Tests: use self.assertNotIn().
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>
diff --git a/test/test_bier.py b/test/test_bier.py
index 5a2c51c..9a9db3b 100644
--- a/test/test_bier.py
+++ b/test/test_bier.py
@@ -29,7 +29,7 @@
if error:
self.logger.critical(error)
- self.assertEqual(error.find("Failed"), -1)
+ self.assertNotIn("Failed", error)
class TestBier(VppTestCase):
diff --git a/test/test_bihash.py b/test/test_bihash.py
index ff2a898..6ccf6c2 100644
--- a/test/test_bihash.py
+++ b/test/test_bihash.py
@@ -25,7 +25,7 @@
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 @@
if error:
self.logger.critical(error)
- self.assertEqual(error.find("failed"), -1)
+ self.assertNotIn('failed', error)
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/test_bond.py b/test/test_bond.py
index c1dcb92..533038e 100644
--- a/test/test_bond.py
+++ b/test/test_bond.py
@@ -228,8 +228,8 @@
# 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 @@
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 @@
# 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()
diff --git a/test/test_fib.py b/test/test_fib.py
index 6b59746..2f4d726 100644
--- a/test/test_fib.py
+++ b/test/test_fib.py
@@ -14,7 +14,7 @@
if error:
self.logger.critical(error)
- self.assertEqual(error.find("Failed"), -1)
+ self.assertNotIn("Failed", error)
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/test_ip_mcast.py b/test/test_ip_mcast.py
index cca4f80..41c6f3b 100644
--- a/test/test_ip_mcast.py
+++ b/test/test_ip_mcast.py
@@ -34,7 +34,7 @@
if error:
self.logger.critical(error)
- self.assertEqual(error.find("Failed"), -1)
+ self.assertNotIn("Failed", error)
class TestIPMcast(VppTestCase):
diff --git a/test/test_nat.py b/test/test_nat.py
index e368fe0..0ef3026 100644
--- a/test/test_nat.py
+++ b/test/test_nat.py
@@ -7285,9 +7285,9 @@
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)
diff --git a/test/test_p2p_ethernet.py b/test/test_p2p_ethernet.py
index b0d546e..5200e48 100644
--- a/test/test_p2p_ethernet.py
+++ b/test/test_p2p_ethernet.py
@@ -48,22 +48,22 @@
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")
diff --git a/test/test_sctp.py b/test/test_sctp.py
index d7efc8c..70201eb 100644
--- a/test/test_sctp.py
+++ b/test/test_sctp.py
@@ -66,7 +66,7 @@
"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 @@
" 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()
diff --git a/test/test_session.py b/test/test_session.py
index 5f4f3f5..afea5f6 100644
--- a/test/test_session.py
+++ b/test/test_session.py
@@ -68,14 +68,14 @@
"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 @@
if error:
self.logger.critical(error)
- self.assertEqual(error.find("failed"), -1)
+ self.assertNotIn("failed", error)
def tearDown(self):
super(TestSessionUnitTests, self).tearDown()
diff --git a/test/test_string.py b/test/test_string.py
index b44489e..cfdec1f 100644
--- a/test/test_string.py
+++ b/test/test_string.py
@@ -35,7 +35,7 @@
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)
diff --git a/test/test_tcp.py b/test/test_tcp.py
index 5f2bce5..b7ce596 100644
--- a/test/test_tcp.py
+++ b/test/test_tcp.py
@@ -66,14 +66,14 @@
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 @@
if error:
self.logger.critical(error)
- self.assertEqual(error.find("failed"), -1)
+ self.assertNotIn("failed", error)
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/test_udp.py b/test/test_udp.py
index a52ba27..d0ad23f 100644
--- a/test/test_udp.py
+++ b/test/test_udp.py
@@ -293,14 +293,14 @@
"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()
diff --git a/test/test_vhost.py b/test/test_vhost.py
index 469fada..9a93821 100644
--- a/test/test_vhost.py
+++ b/test/test_vhost.py
@@ -35,8 +35,8 @@
# 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 @@
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 @@
# 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()