summaryrefslogtreecommitdiff
path: root/tests/unittests/test_cli.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-06-20 22:38:26 -0400
committerScott Moser <smoser@ubuntu.com>2016-06-20 22:38:26 -0400
commitb0ea6e5a2c1c26b8faf1dc8303feebb00344e537 (patch)
tree1ec50e5f8c07ab1c7b4e206a5d0c7dca0858b640 /tests/unittests/test_cli.py
parentfe6919dcd37c6c1ecd371e5eb20b605ab20a6420 (diff)
parent776b0cfe847f531d8d5a235f52673c3da1f06064 (diff)
downloadvyos-cloud-init-b0ea6e5a2c1c26b8faf1dc8303feebb00344e537.tar.gz
vyos-cloud-init-b0ea6e5a2c1c26b8faf1dc8303feebb00344e537.zip
merge with trunk.
test runs to the point where it did, think I got most of the changes incorporated.
Diffstat (limited to 'tests/unittests/test_cli.py')
-rw-r--r--tests/unittests/test_cli.py46
1 files changed, 13 insertions, 33 deletions
diff --git a/tests/unittests/test_cli.py b/tests/unittests/test_cli.py
index f537bd83..5fa252f7 100644
--- a/tests/unittests/test_cli.py
+++ b/tests/unittests/test_cli.py
@@ -1,17 +1,10 @@
-import imp
-import os
import six
-import sys
from . import helpers as test_helpers
-try:
- from unittest import mock
-except ImportError:
- import mock
+from cloudinit.cmd import main as cli
-
-BIN_CLOUDINIT = "bin/cloud-init"
+mock = test_helpers.mock
class TestCLI(test_helpers.FilesystemMockingTestCase):
@@ -20,35 +13,22 @@ class TestCLI(test_helpers.FilesystemMockingTestCase):
super(TestCLI, self).setUp()
self.stderr = six.StringIO()
self.patchStdoutAndStderr(stderr=self.stderr)
- self.sys_exit = mock.MagicMock()
- self.patched_funcs.enter_context(
- mock.patch.object(sys, 'exit', self.sys_exit))
-
- def _call_main(self):
- self.patched_funcs.enter_context(
- mock.patch.object(sys, 'argv', ['cloud-init']))
- cli = imp.load_module(
- 'cli', open(BIN_CLOUDINIT), '', ('', 'r', imp.PY_SOURCE))
+
+ def _call_main(self, sysv_args=None):
+ if not sysv_args:
+ sysv_args = ['cloud-init']
try:
- return cli.main()
- except Exception:
- pass
+ return cli.main(sysv_args=sysv_args)
+ except SystemExit as e:
+ return e.code
- @test_helpers.skipIf(not os.path.isfile(BIN_CLOUDINIT), "no bin/cloudinit")
def test_no_arguments_shows_usage(self):
- self._call_main()
- self.assertIn('usage: cloud-init', self.stderr.getvalue())
-
- @test_helpers.skipIf(not os.path.isfile(BIN_CLOUDINIT), "no bin/cloudinit")
- def test_no_arguments_exits_2(self):
exit_code = self._call_main()
- if self.sys_exit.call_count:
- self.assertEqual(mock.call(2), self.sys_exit.call_args)
- else:
- self.assertEqual(2, exit_code)
+ self.assertIn('usage: cloud-init', self.stderr.getvalue())
+ self.assertEqual(2, exit_code)
- @test_helpers.skipIf(not os.path.isfile(BIN_CLOUDINIT), "no bin/cloudinit")
def test_no_arguments_shows_error_message(self):
- self._call_main()
+ exit_code = self._call_main()
self.assertIn('cloud-init: error: too few arguments',
self.stderr.getvalue())
+ self.assertEqual(2, exit_code)