summaryrefslogtreecommitdiff
path: root/tests/unittests/test_util.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-03-15 11:40:13 -0600
committerChad Smith <chad.smith@canonical.com>2018-03-15 11:40:13 -0600
commit97012fbb5207ddf1d2dcbb1c5eae710c47ab8ec0 (patch)
treecbd8b3377e12763bf0c43657a7d3021fdda9fa89 /tests/unittests/test_util.py
parent837021fd3ded8262ff7131efe6cfd4c7ce489e2b (diff)
downloadvyos-cloud-init-97012fbb5207ddf1d2dcbb1c5eae710c47ab8ec0.tar.gz
vyos-cloud-init-97012fbb5207ddf1d2dcbb1c5eae710c47ab8ec0.zip
util: Fix subp regression. Allow specifying subp command as a string.
The command provided to subp can either be a string or a list. This patch fixes a regression which raised CalledProcessError whenever providing a string to subp. LP: #1755965
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r--tests/unittests/test_util.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 89ae40f5..499e7c9f 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -632,6 +632,24 @@ class TestSubp(helpers.CiTestCase):
# but by using bash, we remove dependency on another program.
return([BASH, '-c', 'printf "$@"', 'printf'] + list(args))
+ def test_subp_handles_bytestrings(self):
+ """subp can run a bytestring command if shell is True."""
+ tmp_file = self.tmp_path('test.out')
+ cmd = 'echo HI MOM >> {tmp_file}'.format(tmp_file=tmp_file)
+ (out, _err) = util.subp(cmd.encode('utf-8'), shell=True)
+ self.assertEqual(u'', out)
+ self.assertEqual(u'', _err)
+ self.assertEqual('HI MOM\n', util.load_file(tmp_file))
+
+ def test_subp_handles_strings(self):
+ """subp can run a string command if shell is True."""
+ tmp_file = self.tmp_path('test.out')
+ cmd = 'echo HI MOM >> {tmp_file}'.format(tmp_file=tmp_file)
+ (out, _err) = util.subp(cmd, shell=True)
+ self.assertEqual(u'', out)
+ self.assertEqual(u'', _err)
+ self.assertEqual('HI MOM\n', util.load_file(tmp_file))
+
def test_subp_handles_utf8(self):
# The given bytes contain utf-8 accented characters as seen in e.g.
# the "deja dup" package in Ubuntu.