Merge lp:~gnuoy/charm-helpers/1595418 into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 592
Proposed branch: lp:~gnuoy/charm-helpers/1595418
Merge into: lp:charm-helpers
Diff against target: 26 lines (+4/-3)
2 files modified
charmhelpers/core/hookenv.py (+1/-1)
tests/core/test_hookenv.py (+3/-2)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/1595418
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+298200@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

I always prefer to add the universal_newlines=True argument to the subprocess calls, so they return proper strings. This seems preferable than faffing about with manual decoding and making the assumption that the system encoding is UTF-8. And fewer bytestrings infecting your tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/hookenv.py'
2--- charmhelpers/core/hookenv.py 2016-03-30 21:04:15 +0000
3+++ charmhelpers/core/hookenv.py 2016-06-23 07:14:09 +0000
4@@ -1006,4 +1006,4 @@
5 :raise: NotImplementedError if run on Juju < 2.0
6 '''
7 cmd = ['network-get', '--primary-address', binding]
8- return subprocess.check_output(cmd).strip()
9+ return subprocess.check_output(cmd).decode('UTF-8').strip()
10
11=== modified file 'tests/core/test_hookenv.py'
12--- tests/core/test_hookenv.py 2016-03-09 20:30:51 +0000
13+++ tests/core/test_hookenv.py 2016-06-23 07:14:09 +0000
14@@ -1621,9 +1621,10 @@
15 @patch('subprocess.check_output')
16 def test_network_get_primary(self, check_output):
17 '''Ensure that network-get is called correctly and output is returned'''
18- check_output.return_value = '192.168.22.1'
19+ check_output.return_value = b'192.168.22.1'
20 ip = hookenv.network_get_primary_address('mybinding')
21- check_output.assert_called_with(['network-get', '--primary-address', 'mybinding'])
22+ check_output.assert_called_with(
23+ ['network-get', '--primary-address', 'mybinding'])
24 self.assertEqual(ip, '192.168.22.1')
25
26 @patch('subprocess.check_output')

Subscribers

People subscribed via source and target branches