From: Zhongyue Luo Date: Fri, 6 Sep 2013 04:10:28 +0000 (+0800) Subject: Fixes misuse of assertTrue in test scripts X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=b2e0f75ddaea0c12e154432da7a860725af8e344;p=openstack-build%2Fcinder-build.git Fixes misuse of assertTrue in test scripts Misuse of assertTrue in places where assertEqual should be used. If assertTrue is used instead of assertEquals, the test will always pass if the first argument's boolean cast is True. The second argument passed to assertTrue() will be regarded as the error message when the assertion fails. Using assertEqual will actually check if two arguments are same value. Fixes bug #1221517 Change-Id: I68f614164803729ea26e65f8868b0031e724d324 --- diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index 291896906..64dd29823 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -57,24 +57,19 @@ class ConnectorTestCase(test.TestCase): def test_factory(self): obj = connector.InitiatorConnector.factory('iscsi', None) - self.assertTrue(obj.__class__.__name__, - "ISCSIConnector") + self.assertEqual(obj.__class__.__name__, "ISCSIConnector") obj = connector.InitiatorConnector.factory('fibre_channel', None) - self.assertTrue(obj.__class__.__name__, - "FibreChannelConnector") + self.assertEqual(obj.__class__.__name__, "FibreChannelConnector") obj = connector.InitiatorConnector.factory('aoe', None) - self.assertTrue(obj.__class__.__name__, - "AoEConnector") + self.assertEqual(obj.__class__.__name__, "AoEConnector") obj = connector.InitiatorConnector.factory('nfs', None) - self.assertTrue(obj.__class__.__name__, - "RemoteFsConnector") + self.assertEqual(obj.__class__.__name__, "RemoteFsConnector") obj = connector.InitiatorConnector.factory('glusterfs', None) - self.assertTrue(obj.__class__.__name__, - "RemoteFsConnector") + self.assertEqual(obj.__class__.__name__, "RemoteFsConnector") self.assertRaises(ValueError, connector.InitiatorConnector.factory, diff --git a/cinder/tests/brick/test_brick_linuxscsi.py b/cinder/tests/brick/test_brick_linuxscsi.py index 9b7b0db68..55b1dd42a 100644 --- a/cinder/tests/brick/test_brick_linuxscsi.py +++ b/cinder/tests/brick/test_brick_linuxscsi.py @@ -47,7 +47,7 @@ class LinuxSCSITestCase(test.TestCase): disk_path = ("/dev/disk/by-path/ip-10.10.220.253:3260-" "iscsi-iqn.2000-05.com.3pardata:21810002ac00383d-lun-0") name = self.linuxscsi.get_name_from_path(disk_path) - self.assertTrue(name, device_name) + self.assertEqual(name, device_name) self.stubs.Set(os.path, 'realpath', lambda x: "bogus") name = self.linuxscsi.get_name_from_path(disk_path) self.assertIsNone(name)