diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-06-15 23:28:51 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-06-15 23:28:51 -0400 |
commit | a066f95c67bb5fa15350cdff319f60d589274c3a (patch) | |
tree | 790d277e08dd39da82dd956c89709e17538a1a82 /tests | |
parent | a454a6408b3c7ecc816073049d060632191099bb (diff) | |
parent | d598ceeb838b4ccaf667ded84bb02bf096ab7b12 (diff) | |
download | vyos-cloud-init-a066f95c67bb5fa15350cdff319f60d589274c3a.tar.gz vyos-cloud-init-a066f95c67bb5fa15350cdff319f60d589274c3a.zip |
merge with trunk
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_cli.py | 43 | ||||
-rw-r--r-- | tests/unittests/test_datasource/test_gce.py | 2 |
2 files changed, 15 insertions, 30 deletions
diff --git a/tests/unittests/test_cli.py b/tests/unittests/test_cli.py index 163ce64c..5fa252f7 100644 --- a/tests/unittests/test_cli.py +++ b/tests/unittests/test_cli.py @@ -1,12 +1,10 @@ -import imp -import os import six -import sys from . import helpers as test_helpers -mock = test_helpers.mock -BIN_CLOUDINIT = "bin/cloud-init" +from cloudinit.cmd import main as cli + +mock = test_helpers.mock class TestCLI(test_helpers.FilesystemMockingTestCase): @@ -15,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) diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py index 1f7eb99e..6e62a4d2 100644 --- a/tests/unittests/test_datasource/test_gce.py +++ b/tests/unittests/test_datasource/test_gce.py @@ -52,7 +52,7 @@ GCE_META_ENCODING = { HEADERS = {'X-Google-Metadata-Request': 'True'} MD_URL_RE = re.compile( - r'http://metadata.google.internal./computeMetadata/v1/.*') + r'http://metadata.google.internal/computeMetadata/v1/.*') def _set_mock_metadata(gce_meta=None): |