Tests: use self.assertNotIn(). 87/18087/2
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Wed, 6 Mar 2019 23:11:28 +0000 (15:11 -0800)
committerOle Trøan <otroan@employees.org>
Mon, 11 Mar 2019 08:09:23 +0000 (08:09 +0000)
Many tests use self.assertEqual(error.find("failed"), -1)
Use self.assertNotIn("failed", error) to provide more meaningful errors such as
AssertionError: 'Failed' not found in '' instead of 0 != -1.

Change-Id: I670acdc977b788b2cedf94cfeafc12097781463f
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
13 files changed:
test/test_bier.py
test/test_bihash.py
test/test_bond.py
test/test_fib.py
test/test_ip_mcast.py
test/test_nat.py
test/test_p2p_ethernet.py
test/test_sctp.py
test/test_session.py
test/test_string.py
test/test_tcp.py
test/test_udp.py
test/test_vhost.py

index 5a2c51c..9a9db3b 100644 (file)
@@ -29,7 +29,7 @@ class TestBFIB(VppTestCase):
 
         if error:
             self.logger.critical(error)
-        self.assertEqual(error.find("Failed"), -1)
+        self.assertNotIn("Failed", error)
 
 
 class TestBier(VppTestCase):
index ff2a898..6ccf6c2 100644 (file)
@@ -25,7 +25,7 @@ class TestBihash(VppTestCase):
 
         if error:
             self.logger.critical(error)
-        self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn('failed', error)
 
     def test_bihash_thread(self):
         """ Bihash Thread Test """
@@ -34,7 +34,7 @@ class TestBihash(VppTestCase):
 
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn('failed', error)
 
 if __name__ == '__main__':
     unittest.main(testRunner=VppTestRunner)
index c1dcb92..533038e 100644 (file)
@@ -228,8 +228,8 @@ class TestBondInterface(VppTestCase):
 
         # verify both interfaces in the show
         ifs = self.vapi.cli("show interface")
-        self.assertNotEqual(ifs.find('BondEthernet0'), -1)
-        self.assertNotEqual(ifs.find('BondEthernet1'), -1)
+        self.assertIn('BondEthernet0', ifs)
+        self.assertIn('BondEthernet1', ifs)
 
         # verify they are in the dump also
         if_dump = self.vapi.sw_interface_bond_dump()
@@ -244,10 +244,10 @@ class TestBondInterface(VppTestCase):
 
         ifs = self.vapi.cli("show interface")
         # verify BondEthernet0 still in the show
-        self.assertNotEqual(ifs.find('BondEthernet0'), -1)
+        self.assertIn('BondEthernet0', ifs)
 
         # verify BondEthernet1 not in the show
-        self.assertEqual(ifs.find('BondEthernet1'), -1)
+        self.assertNotIn('BondEthernet1', ifs)
 
         # verify BondEthernet1 is not in the dump
         if_dump = self.vapi.sw_interface_bond_dump()
@@ -264,7 +264,7 @@ class TestBondInterface(VppTestCase):
 
         # verify BondEthernet0 not in the show
         ifs = self.vapi.cli("show interface")
-        self.assertEqual(ifs.find('BondEthernet0'), -1)
+        self.assertNotIn('BondEthernet0', ifs)
 
         # verify BondEthernet0 is not in the dump
         if_dump = self.vapi.sw_interface_bond_dump()
index 6b59746..2f4d726 100644 (file)
@@ -14,7 +14,7 @@ class TestFIB(VppTestCase):
 
         if error:
             self.logger.critical(error)
-        self.assertEqual(error.find("Failed"), -1)
+        self.assertNotIn("Failed", error)
 
 if __name__ == '__main__':
     unittest.main(testRunner=VppTestRunner)
index cca4f80..41c6f3b 100644 (file)
@@ -34,7 +34,7 @@ class TestMFIB(VppTestCase):
 
         if error:
             self.logger.critical(error)
-        self.assertEqual(error.find("Failed"), -1)
+        self.assertNotIn("Failed", error)
 
 
 class TestIPMcast(VppTestCase):
index e368fe0..0ef3026 100644 (file)
@@ -7285,9 +7285,9 @@ class TestNAT64(MethodHolder):
         self.assertTrue(pg1_found)
 
         features = self.vapi.cli("show interface features pg0")
-        self.assertNotEqual(features.find('nat64-in2out'), -1)
+        self.assertIn('nat64-in2out', features)
         features = self.vapi.cli("show interface features pg1")
-        self.assertNotEqual(features.find('nat64-out2in'), -1)
+        self.assertIn('nat64-out2in', features)
 
         self.vapi.nat64_add_del_interface(self.pg0.sw_if_index, is_add=0)
         self.vapi.nat64_add_del_interface(self.pg1.sw_if_index, is_add=0)
index b0d546e..5200e48 100644 (file)
@@ -48,22 +48,22 @@ class P2PEthernetAPI(VppTestCase):
         self.create_p2p_ethernet(self.pg0, 2, "de:ad:00:00:00:02")
         intfs = self.vapi.cli("show interface")
 
-        self.assertNotEqual(intfs.find('pg0.1'), -1)
-        self.assertNotEqual(intfs.find('pg0.2'), -1)
-        self.assertEqual(intfs.find('pg0.5'), -1)
+        self.assertIn('pg0.1', intfs)
+        self.assertIn('pg0.2', intfs)
+        self.assertNotIn('pg0.5', intfs)
 
         # create pg2.5 subif
         self.create_p2p_ethernet(self.pg0, 5, "de:ad:00:00:00:ff")
         intfs = self.vapi.cli("show interface")
-        self.assertNotEqual(intfs.find('pg0.5'), -1)
+        self.assertIn('pg0.5', intfs)
         # delete pg2.5 subif
         self.delete_p2p_ethernet(self.pg0, "de:ad:00:00:00:ff")
 
         intfs = self.vapi.cli("show interface")
 
-        self.assertNotEqual(intfs.find('pg0.1'), -1)
-        self.assertNotEqual(intfs.find('pg0.2'), -1)
-        self.assertEqual(intfs.find('pg0.5'), -1)
+        self.assertIn('pg0.1', intfs)
+        self.assertIn('pg0.2', intfs)
+        self.assertNotIn('pg0.5', intfs)
 
         self.logger.info("FFP_TEST_FINISH_0000")
 
index d7efc8c..70201eb 100644 (file)
@@ -66,7 +66,7 @@ class TestSCTP(VppTestCase):
                               "no-echo uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         error = self.vapi.cli("test echo client mbytes 10 no-return " +
                               " appns 1" +
@@ -76,7 +76,7 @@ class TestSCTP(VppTestCase):
                               " uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         # Delete inter-table routes
         ip_t01.remove_vpp_config()
index 5f4f3f5..afea5f6 100644 (file)
@@ -68,14 +68,14 @@ class TestSession(VppTestCase):
                               "private-segment-size 1m uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         error = self.vapi.cli("test echo client nclients 100 appns 1 " +
                               "no-output fifo-size 64 syn-timeout 2 " +
                               "private-segment-size 1m uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         if self.vpp_dead:
             self.assert_equal(0)
@@ -98,7 +98,7 @@ class TestSessionUnitTests(VppTestCase):
 
         if error:
             self.logger.critical(error)
-        self.assertEqual(error.find("failed"), -1)
+        self.assertNotIn("failed", error)
 
     def tearDown(self):
         super(TestSessionUnitTests, self).tearDown()
index b44489e..cfdec1f 100644 (file)
@@ -35,7 +35,7 @@ class TestString(VppTestCase):
             error = self.vapi.cli("test string " + name)
             if error.find("failed") != -1:
                 self.logger.critical("FAILURE in the " + name + " test")
-                self.assertEqual(error.find("failed"), -1)
+                self.assertNotIn("failed", error)
 
 if __name__ == '__main__':
     unittest.main(testRunner=VppTestRunner)
index 5f2bce5..b7ce596 100644 (file)
@@ -66,14 +66,14 @@ class TestTCP(VppTestCase):
                               uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         error = self.vapi.cli("test echo client mbytes 10 appns 1 " +
                               "fifo-size 4 no-output test-bytes " +
                               "syn-timeout 2 uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         # Delete inter-table routes
         ip_t01.remove_vpp_config()
@@ -97,7 +97,7 @@ class TestTCPUnitTests(VppTestCase):
 
         if error:
             self.logger.critical(error)
-        self.assertEqual(error.find("failed"), -1)
+        self.assertNotIn("failed", error)
 
 if __name__ == '__main__':
     unittest.main(testRunner=VppTestRunner)
index a52ba27..d0ad23f 100644 (file)
@@ -293,14 +293,14 @@ class TestUDP(VppTestCase):
                               "uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         error = self.vapi.cli("test echo client mbytes 10 appns 1 " +
                               "fifo-size 4 no-output test-bytes " +
                               "syn-timeout 2 no-return uri " + uri)
         if error:
             self.logger.critical(error)
-            self.assertEqual(error.find("failed"), -1)
+            self.assertNotIn("failed", error)
 
         # Delete inter-table routes
         ip_t01.remove_vpp_config()
index 469fada..9a93821 100644 (file)
@@ -35,8 +35,8 @@ class TesVhostInterface(VppTestCase):
 
         # verify both interfaces in the show
         ifs = self.vapi.cli("show interface")
-        self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1)
-        self.assertNotEqual(ifs.find('VirtualEthernet0/0/1'), -1)
+        self.assertIn('VirtualEthernet0/0/0', ifs)
+        self.assertIn('VirtualEthernet0/0/1', ifs)
 
         # verify they are in the dump also
         if_dump = self.vapi.sw_interface_vhost_user_dump()
@@ -51,10 +51,10 @@ class TesVhostInterface(VppTestCase):
 
         ifs = self.vapi.cli("show interface")
         # verify VirtualEthernet0/0/0 still in the show
-        self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1)
+        self.assertIn('VirtualEthernet0/0/0', ifs)
 
         # verify VirtualEthernet0/0/1 not in the show
-        self.assertEqual(ifs.find('VirtualEthernet0/0/1'), -1)
+        self.assertNotIn('VirtualEthernet0/0/1', ifs)
 
         # verify VirtualEthernet0/0/1 is not in the dump
         if_dump = self.vapi.sw_interface_vhost_user_dump()
@@ -71,7 +71,7 @@ class TesVhostInterface(VppTestCase):
 
         # verify VirtualEthernet0/0/0 not in the show
         ifs = self.vapi.cli("show interface")
-        self.assertEqual(ifs.find('VirtualEthernet0/0/0'), -1)
+        self.assertNotIn('VirtualEthernet0/0/0', ifs)
 
         # verify VirtualEthernet0/0/0 is not in the dump
         if_dump = self.vapi.sw_interface_vhost_user_dump()