Commit 204c4a86 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

format: fix callAndRead for python3

See merge request !399
parents 5ea9b36b 4444e963
...@@ -150,9 +150,12 @@ def getPublicIPv4Address(): ...@@ -150,9 +150,12 @@ def getPublicIPv4Address():
return ipv4 return ipv4
def callAndRead(argument_list, raise_on_error=True): def callAndRead(argument_list, raise_on_error=True):
popen = subprocess.Popen(argument_list, popen = subprocess.Popen(
argument_list,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT,
universal_newlines=True,
)
result = popen.communicate()[0] result = popen.communicate()[0]
if raise_on_error and popen.returncode != 0: if raise_on_error and popen.returncode != 0:
raise ValueError('Issue while invoking %r, result was:\n%s' % ( raise ValueError('Issue while invoking %r, result was:\n%s' % (
......
...@@ -950,5 +950,9 @@ class TestFormatConfig(SlapformatMixin): ...@@ -950,5 +950,9 @@ class TestFormatConfig(SlapformatMixin):
# TODO add more tests with config file # TODO add more tests with config file
if __name__ == '__main__':
unittest.main() class TestCallAndRead(unittest.TestCase):
def test_callAndRead(self):
self.assertEqual(
slapos.format.callAndRead(['echo', 'hello']),
(0, 'hello\n'))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment