Merge lp://staging/~freyes/charm-helpers/fix-test-ipv6 into lp://staging/charm-helpers
Status: | Merged |
---|---|
Merged at revision: | 755 |
Proposed branch: | lp://staging/~freyes/charm-helpers/fix-test-ipv6 |
Merge into: | lp://staging/charm-helpers |
Diff against target: |
31 lines (+4/-4) 2 files modified
charmhelpers/contrib/network/ip.py (+3/-3) tests/contrib/network/test_ip.py (+1/-1) |
To merge this branch: | bzr merge lp://staging/~freyes/charm-helpers/fix-test-ipv6 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jorge Niedbalski (community) | Approve | ||
Alex Kavanagh (community) | Approve | ||
Review via email: mp+325779@code.staging.launchpad.net |
Description of the change
Fix test_is_
When calling subprocess.
universal_
The test that fails is:
=======
ERROR: test_is_
-------
Traceback (most recent call last):
File "/home/
return func(*args, **keywargs)
File "/home/
self.
File "/home/
result = result.
AttributeError: 'str' object has no attribute 'decode'
universal_ newlines= True is to normalise newlines between mac, windows and *nix; we're only dealing with *nix machines here, and it indirectly papers over the cracks between Py2 and Py using a IOTextWrapper with default settings.
The 'problem' is that check_output() returns a bytestring in Py3 vs a str on Py2 which is what the decode is for, and the bug is in the test.
I'd prefer to change the test to pass a bytestring if it's Py3 as the code currently works OR (perhaps even better) just make Py2 a bit looser by instead doing:
return b"net.ipv6. conf.all. disable_ ipv6 = 1" in result
as Python2 will paper over the cracks by doing an implicit conversion: e.g. in ipython (py2):
In [4]: s = "hello there\n\n123 and som"
In [5]: b"123" in s
Out[5]: True
Obviously, the test would also need to pass a b"""...""" and b"" (the two mock outputs), and the .decode('UTF-8') would be removed in the original function.
This would work for both py2 and py3. Thoughts?