Dan Kenigsberg has uploaded a new change for review.

Change subject: tests: use assertIn when applicable
......................................................................

tests: use assertIn when applicable

On failure, assertIn(x, y) provides more tangible information than the
plain assertTrue(x in y).

Change-Id: Idf30dae017ba9e028b0adf00e1edab04c3b27c0d
Signed-off-by: Dan Kenigsberg <[email protected]>
---
M tests/apiTests.py
M tests/functional/networkTests.py
M tests/functional/virtTests.py
M tests/fuserTests.py
M tests/md_utils_tests.py
M tests/mkimageTests.py
M tests/tcTests.py
M tests/utilsTests.py
8 files changed, 18 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/23038/1

diff --git a/tests/apiTests.py b/tests/apiTests.py
index 157aa7f..44c197c 100644
--- a/tests/apiTests.py
+++ b/tests/apiTests.py
@@ -212,7 +212,7 @@
                                  'method': 'Host.ping',
                                  'params': {}})
         reply = self.sendMessage(msg)
-        self.assertFalse('error' in reply)
+        self.assertNotIn('error', reply)
         self.assertEquals(None, reply['result'])
 
     def testPingError(self):
@@ -223,7 +223,7 @@
                                  'params': {}})
         reply = self.sendMessage(msg)
         self.assertEquals(1, reply['error']['code'])
-        self.assertFalse('result' in reply)
+        self.assertNotIn('result', reply)
 
     def testNoMethod(self):
         msg = self.buildMessage({'jsonrpc': '2.0',
@@ -256,7 +256,7 @@
             self.clearAPI()
             self.programAPI("testPing")
             ret = self.sendMessage(msg)
-            self.assertFalse('error' in ret)
+            self.assertNotIn('error', ret)
 
         msg = self.buildMessage({'jsonrpc': '2.0',
                                  'id': 1,
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 21d00ff..7394465 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -1442,7 +1442,7 @@
                 self.assertEqual(status, SUCCESS, msg)
                 self.assertNetworkExists(NETWORK_NAME)
                 status, msg, info = self.vdsm_net.getVdsCapabilities()
-                self.assertTrue('BOOTPROTO' in info['nics'][nic]['cfg'])
+                self.assertIn('BOOTPROTO', info['nics'][nic]['cfg'])
                 bootproto = info['nics'][nic]['cfg']['BOOTPROTO']
                 self.assertEqual(bootproto, 'none')
 
@@ -1451,7 +1451,7 @@
                 self.assertEqual(status, SUCCESS, msg)
                 self.assertNetworkExists(vlan_name)
                 status, msg, info = self.vdsm_net.getVdsCapabilities()
-                self.assertTrue('BOOTPROTO' in info['nics'][nic]['cfg'])
+                self.assertIn('BOOTPROTO', info['nics'][nic]['cfg'])
                 bootproto = info['nics'][nic]['cfg']['BOOTPROTO']
                 self.assertEqual(bootproto, 'none')
 
@@ -1460,7 +1460,7 @@
                     {vlan_name: networks[vlan_name]}, {}, {})
                 self.assertEqual(status, SUCCESS, msg)
                 status, msg, info = self.vdsm_net.getVdsCapabilities()
-                self.assertTrue('BOOTPROTO' in info['nics'][nic]['cfg'])
+                self.assertIn('BOOTPROTO', info['nics'][nic]['cfg'])
                 bootproto = info['nics'][nic]['cfg']['BOOTPROTO']
                 self.assertEqual(bootproto, 'none')
 
@@ -1489,7 +1489,7 @@
                 self.assertNetworkExists(NETWORK_NAME)
                 self.assertNetworkExists(vlan_name)
                 status, msg, info = self.vdsm_net.getVdsCapabilities()
-                self.assertTrue('BOOTPROTO' in info['nics'][nic]['cfg'])
+                self.assertIn('BOOTPROTO', info['nics'][nic]['cfg'])
                 bootproto = info['nics'][nic]['cfg']['BOOTPROTO']
                 self.assertEqual(bootproto, 'none')
 
diff --git a/tests/functional/virtTests.py b/tests/functional/virtTests.py
index bd54621..0580af7 100644
--- a/tests/functional/virtTests.py
+++ b/tests/functional/virtTests.py
@@ -159,7 +159,7 @@
 
     def assertVmUp(self, vmid):
         result = self._getVmStatus(vmid)
-        self.assertTrue(result['status'] in self.UPSTATES)
+        self.assertIn(result['status'], self.UPSTATES)
 
     def assertGuestUp(self, vmid, targetUptime=0):
         result = self._getVmStatus(vmid)
diff --git a/tests/fuserTests.py b/tests/fuserTests.py
index 6516758..42a4c26 100644
--- a/tests/fuserTests.py
+++ b/tests/fuserTests.py
@@ -30,4 +30,4 @@
     def testSelfExe(self):
         pid = os.getpid()
         with NamedTemporaryFile() as tempFile:
-            self.assertTrue(pid in fuser.fuser(tempFile.name))
+            self.assertIn(pid, fuser.fuser(tempFile.name))
diff --git a/tests/md_utils_tests.py b/tests/md_utils_tests.py
index 29038cb..bf02743 100644
--- a/tests/md_utils_tests.py
+++ b/tests/md_utils_tests.py
@@ -38,5 +38,5 @@
             elif dev == '/dev/md2':
                 self.assertEquals(uuid, '1234566d:9f136504:efb8e4be:12810206')
             else:
-                self.assertTrue(dev in ['/dev/md1', '/dev/md/1', '/dev/md0',
-                                        '/dev/md/0', '/dev/md2'])
+                self.assertIn(dev, ['/dev/md1', '/dev/md/1', '/dev/md0',
+                                    '/dev/md/0', '/dev/md2'])
diff --git a/tests/mkimageTests.py b/tests/mkimageTests.py
index 606394b..5bd94a8 100644
--- a/tests/mkimageTests.py
+++ b/tests/mkimageTests.py
@@ -113,9 +113,9 @@
         self.assertEqual(len(out_subdir), len(self.expected_results) / 2)
         for filename in self.expected_results:
             if os.path.basename(filename) == filename:
-                self.assertTrue(filename in out_dir)
+                self.assertIn(filename, out_dir)
             else:
-                self.assertTrue(os.path.basename(filename) in out_subdir)
+                self.assertIn(os.path.basename(filename), out_subdir)
             filepath = os.path.join(self.workdir, filename)
             if checkPerms:
                 self._check_permissions(filepath,
diff --git a/tests/tcTests.py b/tests/tcTests.py
index 4ee661f..4777072 100644
--- a/tests/tcTests.py
+++ b/tests/tcTests.py
@@ -170,14 +170,12 @@
 
     def _addIngress(self):
         tc.qdisc_replace_ingress(self._bridge.devName)
-        self.assertTrue("qdisc ingress" in self._showQdisc(),
-                        "Could not add an ingress qdisc to the device.")
+        self.assertIn("qdisc ingress", self._showQdisc())
 
     def testToggleIngress(self):
         self._addIngress()
         tc.qdisc_del(self._bridge.devName, 'ingress')
-        self.assertFalse("qdisc ingress" in self._showQdisc(),
-                         "Could not remove an ingress qdisc from the device.")
+        self.assertNotIn("qdisc ingress", self._showQdisc())
 
     def testQdiscsOfDevice(self):
         self._addIngress()
@@ -187,7 +185,7 @@
     def testReplacePrio(self):
         self._addIngress()
         tc.qdisc_replace_prio(self._bridge.devName)
-        self.assertTrue("root" in self._showQdisc())
+        self.assertIn("root", self._showQdisc())
 
     def testTogglePromisc(self):
         tc.set_promisc(self._bridge.devName, True)
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
index c5b250d..8e98920 100644
--- a/tests/utilsTests.py
+++ b/tests/utilsTests.py
@@ -77,8 +77,7 @@
             utils.CommandPath(NAME, 'utter nonsense').cmd
         except OSError as e:
             self.assertEquals(e.errno, errno.ENOENT)
-            self.assertTrue(NAME in e.strerror,
-                            msg='%s not in %s' % (NAME, e.strerror))
+            self.assertIn(NAME, e.strerror)
 
 
 class GeneralUtilsTests(TestCaseBase):
@@ -97,7 +96,7 @@
                   'Writeback', 'Mapped', 'Slab', 'VmallocTotal',
                   'VmallocUsed', 'VmallocChunk')
         for field in fields:
-            self.assertTrue(field in meminfo)
+            self.assertIn(field, meminfo)
             self.assertTrue(isinstance(meminfo[field], int))
 
     def testParseMemInfo(self):


-- 
To view, visit http://gerrit.ovirt.org/23038
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf30dae017ba9e028b0adf00e1edab04c3b27c0d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to