From 6b20f1762429c482257b9c372ee77cb54523d7c5 Mon Sep 17 00:00:00 2001 From: Van Hung Pham Date: Thu, 8 Jun 2017 02:10:06 +0700 Subject: [PATCH] Replace assertTrue(isinstance()) with assertIsInstance() Some of tests use different method of assertTrue(isinstance(A, B)) or assertEqual(type(A), B). The correct way is to use assertIsInstance(A, B) provided by testtools. Change-Id: Ieb99417a4522f803e15547a9c7f6d781b6142678 --- tests/unit/test_os_utils.py | 2 +- tests/unit/test_plugin_kvm.py | 2 +- tests/unit/test_utils.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_os_utils.py b/tests/unit/test_os_utils.py index 586cd20..4a5507a 100644 --- a/tests/unit/test_os_utils.py +++ b/tests/unit/test_os_utils.py @@ -175,7 +175,7 @@ class TestOsUtils(unittest.TestCase): """Test retrieving consumer usage.""" with mock.patch('openstack.connection.Connection') as MockClass: MockClass.return_value = MockedOpenStackConn() - self.assertTrue(isinstance(self.osu.get_consumer_usage(), list)) + self.assertIsInstance(self.osu.get_consumer_usage(), list) def test_get_consumer_usage_with_servers(self): """Test retrieving consumer usage with servers list.""" diff --git a/tests/unit/test_plugin_kvm.py b/tests/unit/test_plugin_kvm.py index 277e1df..b4d8305 100644 --- a/tests/unit/test_plugin_kvm.py +++ b/tests/unit/test_plugin_kvm.py @@ -107,7 +107,7 @@ class TestKvm(unittest.TestCase): """Ensure the run() method works.""" sys.modules.pop('libvirt', None) result = tests.runner('kvm') - self.assertTrue(isinstance(result.exception, SystemExit)) + self.assertIsInstance(result.exception, SystemExit) def test_run_failure(self): """Ensure the run() method works.""" diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index c1a2648..73f5ff5 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -49,13 +49,13 @@ class TestUtils(unittest.TestCase): os.remove(cache_db) def test_is_int_is_int(self): # noqa - self.assertTrue(isinstance(utils.is_int(value=1), int)) + self.assertIsInstance(utils.is_int(value=1), int) def test_is_int_is_int_str(self): # noqa - self.assertTrue(isinstance(utils.is_int(value='1'), int)) + self.assertIsInstance(utils.is_int(value='1'), int) def test_is_int_is_not_int(self): # noqa - self.assertTrue(isinstance(utils.is_int(value='a'), str)) + self.assertIsInstance(utils.is_int(value='a'), str) def test_read_config_not_found(self): # noqa self.assertRaises( @@ -65,7 +65,7 @@ class TestUtils(unittest.TestCase): ) def test_read_config_found_dict_return(self): # noqa - self.assertTrue(isinstance(self.config, dict)) + self.assertIsInstance(self.config, dict) def test_read_config_found_defaults_in_sections(self): """Read config defaults from each section."""