From c8fd01e292f855acb8e1c69ce8262f12b00f9937 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 28 Jul 2015 16:07:37 -0400 Subject: [PATCH] tests: use cloudinit.tests.TestCase everywhere It seems sane to have consistent use of a 'TestCase' class wherever possible. I stumbled on need for this in porting some code (the reporter) back to cloud-init 0.7. Change-Id: Ia10546484dfe73154a68e817129ac2f950d5fe85 --- cloudinit/tests/osys/test_base.py | 5 ++--- cloudinit/tests/osys/windows/test_general.py | 6 ++++-- cloudinit/tests/test_reporting.py | 8 +++----- cloudinit/tests/test_safeyaml.py | 4 ++-- cloudinit/tests/test_templating.py | 4 ++-- cloudinit/tests/test_url_helper.py | 6 +++--- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cloudinit/tests/osys/test_base.py b/cloudinit/tests/osys/test_base.py index c5a46dac..7129571f 100644 --- a/cloudinit/tests/osys/test_base.py +++ b/cloudinit/tests/osys/test_base.py @@ -13,13 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -import unittest - from cloudinit.osys import base +from cloudinit.tests import TestCase from cloudinit.tests.util import mock -class TestOSUtils(unittest.TestCase): +class TestOSUtils(TestCase): @mock.patch('importlib.import_module') @mock.patch('platform.linux_distribution') diff --git a/cloudinit/tests/osys/windows/test_general.py b/cloudinit/tests/osys/windows/test_general.py index 951a22fc..1b2e4556 100644 --- a/cloudinit/tests/osys/windows/test_general.py +++ b/cloudinit/tests/osys/windows/test_general.py @@ -4,15 +4,16 @@ # vi: ts=4 expandtab import importlib -import unittest from cloudinit import exceptions +from cloudinit.tests import TestCase from cloudinit.tests.util import mock -class TestWindowsGeneral(unittest.TestCase): +class TestWindowsGeneral(TestCase): def setUp(self): + super(TestWindowsGeneral, self).setUp() self._ctypes_mock = mock.Mock() self._util_mock = mock.MagicMock() self._module_patcher = mock.patch.dict( @@ -27,6 +28,7 @@ class TestWindowsGeneral(unittest.TestCase): self._general = self._general_module.General() def tearDown(self): + super(TestWindowsGeneral, self).tearDown() self._module_patcher.stop() def _test_check_os_version(self, ret_value, error_value=None): diff --git a/cloudinit/tests/test_reporting.py b/cloudinit/tests/test_reporting.py index e70b9bd0..24e1b96b 100644 --- a/cloudinit/tests/test_reporting.py +++ b/cloudinit/tests/test_reporting.py @@ -3,8 +3,6 @@ # # vi: ts=4 expandtab -import unittest - from cloudinit import reporting from cloudinit.tests import TestCase from cloudinit.tests.util import mock @@ -15,7 +13,7 @@ def _fake_registry(): 'b': mock.MagicMock()}) -class TestReportStartEvent(unittest.TestCase): +class TestReportStartEvent(TestCase): @mock.patch('cloudinit.reporting.instantiated_handler_registry', new_callable=_fake_registry) @@ -32,7 +30,7 @@ class TestReportStartEvent(unittest.TestCase): self.assertEqual(expected_string_representation, event.as_string()) -class TestReportFinishEvent(unittest.TestCase): +class TestReportFinishEvent(TestCase): def _report_finish_event(self, successful=None): event_name, event_description = 'my_test_event', 'my description' @@ -83,7 +81,7 @@ class TestReportFinishEvent(unittest.TestCase): expected_string_representation) -class TestReportingEvent(unittest.TestCase): +class TestReportingEvent(TestCase): def test_as_string(self): event_type, name, description = 'test_type', 'test_name', 'test_desc' diff --git a/cloudinit/tests/test_safeyaml.py b/cloudinit/tests/test_safeyaml.py index dceef7af..da90d53f 100644 --- a/cloudinit/tests/test_safeyaml.py +++ b/cloudinit/tests/test_safeyaml.py @@ -4,12 +4,12 @@ # vi: ts=4 expandtab from cloudinit import safeyaml as yaml -from cloudinit import tests +from cloudinit.tests import TestCase import tempfile -class TestSafeYaml(tests.TestCase): +class TestSafeYaml(TestCase): def test_simple(self): blob = '\nk1: one\nk2: two' expected = {'k1': "one", 'k2': "two"} diff --git a/cloudinit/tests/test_templating.py b/cloudinit/tests/test_templating.py index e76cabbd..e4c8ce76 100644 --- a/cloudinit/tests/test_templating.py +++ b/cloudinit/tests/test_templating.py @@ -9,10 +9,10 @@ import os import textwrap from cloudinit import templater -from cloudinit import tests +from cloudinit.tests import TestCase -class TestTemplates(tests.TestCase): +class TestTemplates(TestCase): jinja_tmpl = '\n'.join(( "## template:jinja", "{{a}},{{b}}", diff --git a/cloudinit/tests/test_url_helper.py b/cloudinit/tests/test_url_helper.py index bcc88ef2..bd1b9236 100644 --- a/cloudinit/tests/test_url_helper.py +++ b/cloudinit/tests/test_url_helper.py @@ -5,7 +5,7 @@ import httpretty -from cloudinit import tests +from cloudinit.tests import TestCase from cloudinit.tests.util import mock from cloudinit import url_helper @@ -24,7 +24,7 @@ class TimeJumpSideEffect(object): return next(self.time) -class UrlHelperWaitForUrlsTest(tests.TestCase): +class UrlHelperWaitForUrlsTest(TestCase): @httpretty.activate def test_url_wait_for(self): @@ -68,7 +68,7 @@ class UrlHelperWaitForUrlsTest(tests.TestCase): self.assertIsNone(url_helper.wait_any_url(urls, max_wait=1)) -class UrlHelperFetchTest(tests.TestCase): +class UrlHelperFetchTest(TestCase): @httpretty.activate def test_url_fetch(self):