diff options
author | Carl Baldwin <carl@ecbaldwin.net> | 2018-10-29 20:01:39 +0000 |
---|---|---|
committer | Carl Baldwin <carl@ecbaldwin.net> | 2018-10-29 20:10:19 +0000 |
commit | 8bccb4278a1c6cb291a9635a4b2252372f074b7e (patch) | |
tree | d1f9d1061a1db670fea7af527e10add4a2b09e59 /test/scenario_test/bgp_router_test.py | |
parent | c8694bc8a7dccd663689f8d134b89fe3a1f37d70 (diff) |
Use assertEqual in python tests
In trying to run the local tests, I found that changing these
assertTrue calls to assertEqual helped me out. With this, a failure
shows the actual and expected values rather than just saying "True is
not False" which is less helpful.
Diffstat (limited to 'test/scenario_test/bgp_router_test.py')
-rw-r--r-- | test/scenario_test/bgp_router_test.py | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/test/scenario_test/bgp_router_test.py b/test/scenario_test/bgp_router_test.py index a69aa3f7..e7ac9ec1 100644 --- a/test/scenario_test/bgp_router_test.py +++ b/test/scenario_test/bgp_router_test.py @@ -128,7 +128,7 @@ class GoBGPTestBase(unittest.TestCase): time.sleep(interval) continue - self.assertTrue(len(global_rib) == len(self.quaggas)) + self.assertEqual(len(global_rib), len(self.quaggas)) for c in self.quaggas.itervalues(): for r in c.routes: @@ -222,21 +222,21 @@ class GoBGPTestBase(unittest.TestCase): def test_10_originate_path(self): self.gobgp.add_route('10.10.0.0/24') dst = self.gobgp.get_global_rib('10.10.0.0/24') - self.assertTrue(len(dst) == 1) - self.assertTrue(len(dst[0]['paths']) == 1) + self.assertEqual(len(dst), 1) + self.assertEqual(len(dst[0]['paths']), 1) path = dst[0]['paths'][0] - self.assertTrue(path['nexthop'] == '0.0.0.0') - self.assertTrue(len(path['aspath']) == 0) + self.assertEqual(path['nexthop'], '0.0.0.0') + self.assertEqual(len(path['aspath']), 0) def test_11_check_adj_rib_out(self): for q in self.quaggas.itervalues(): paths = self.gobgp.get_adj_rib_out(q, '10.10.0.0/24') - self.assertTrue(len(paths) == 1) + self.assertEqual(len(paths), 1) path = paths[0] peer_info = self.gobgp.peers[q] local_addr = peer_info['local_addr'].split('/')[0] - self.assertTrue(path['nexthop'] == local_addr) - self.assertTrue(path['aspath'] == [self.gobgp.asn]) + self.assertEqual(path['nexthop'], local_addr) + self.assertEqual(path['aspath'], [self.gobgp.asn]) def test_12_disable_peer(self): q1 = self.quaggas['q1'] @@ -247,13 +247,13 @@ class GoBGPTestBase(unittest.TestCase): for route in q1.routes.iterkeys(): dst = self.gobgp.get_global_rib(route) - self.assertTrue(len(dst) == 0) + self.assertEqual(len(dst), 0) for q in self.quaggas.itervalues(): if q is q1: continue paths = self.gobgp.get_adj_rib_out(q, route) - self.assertTrue(len(paths) == 0) + self.assertEqual(len(paths), 0) def test_13_enable_peer(self): q1 = self.quaggas['q1'] @@ -280,24 +280,24 @@ class GoBGPTestBase(unittest.TestCase): # iBGP peer g2 = self.quaggas['g2'] paths = g2.get_global_rib('10.20.0.0/24') - self.assertTrue(len(paths) == 1) - self.assertTrue(len(paths[0]['paths']) == 1) + self.assertEqual(len(paths), 1) + self.assertEqual(len(paths[0]['paths']), 1) path = paths[0]['paths'][0] local_pref = extract_path_attribute(path, BGP_ATTR_TYPE_LOCAL_PREF) - self.assertTrue(local_pref['value'] == 1000) + self.assertEqual(local_pref['value'], 1000) med = extract_path_attribute(path, BGP_ATTR_TYPE_MULTI_EXIT_DISC) - self.assertTrue(med['metric'] == 2000) + self.assertEqual(med['metric'], 2000) # eBGP peer q1 = self.quaggas['q1'] paths = q1.get_global_rib('10.20.0.0/24') - self.assertTrue(len(paths) == 1) + self.assertEqual(len(paths), 1) path = paths[0] local_pref = extract_path_attribute(path, BGP_ATTR_TYPE_LOCAL_PREF) # local_pref's default value is 100 - self.assertTrue(local_pref['value'] == 100) + self.assertEqual(local_pref['value'], 100) med = extract_path_attribute(path, BGP_ATTR_TYPE_MULTI_EXIT_DISC) - self.assertTrue(med['metric'] == 2000) + self.assertEqual(med['metric'], 2000) def test_17_check_shutdown(self): g1 = self.gobgp @@ -398,7 +398,7 @@ class GoBGPTestBase(unittest.TestCase): wait_for_completion(lambda: len(g2.get_global_rib(prefix)) == 0) ret = json.loads(r.next()) - self.assertTrue(ret[0]['nlri']['prefix'] == prefix) + self.assertEqual(ret[0]['nlri']['prefix'], prefix) self.assertTrue('withdrawal' in ret[0]) def test_22_check_cli_sorted(self): @@ -425,7 +425,7 @@ class GoBGPTestBase(unittest.TestCase): except StopIteration: break - self.assertTrue(cnt == cnt2) + self.assertEqual(cnt, cnt2) def test_23_check_withdrawal3(self): gobgp_ctn_image_name = parser_option.gobgp_image @@ -456,18 +456,18 @@ class GoBGPTestBase(unittest.TestCase): g4.local('gobgp global rib add 50.0.0.0/24 med 10') paths = g1.get_adj_rib_out(g3, '50.0.0.0/24') - self.assertTrue(len(paths) == 0) + self.assertEqual(len(paths), 0) paths = g1.get_adj_rib_out(g4, '50.0.0.0/24') - self.assertTrue(len(paths) == 1) - self.assertTrue(paths[0]['source-id'] == '192.168.0.8') + self.assertEqual(len(paths), 1) + self.assertEqual(paths[0]['source-id'], '192.168.0.8') g3.local('gobgp global rib del 50.0.0.0/24') paths = g1.get_adj_rib_out(g3, '50.0.0.0/24') - self.assertTrue(len(paths) == 1) - self.assertTrue(paths[0]['source-id'] == '192.168.0.9') + self.assertEqual(len(paths), 1) + self.assertEqual(paths[0]['source-id'], '192.168.0.9') paths = g1.get_adj_rib_out(g4, '50.0.0.0/24') - self.assertTrue(len(paths) == 0) + self.assertEqual(len(paths), 0) if __name__ == '__main__': |