Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_split(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
edge = g_phy.edge("r1", "r2")
new_nodes = ank_utils.split_edge(g_phy, edge)
r1 = g_phy.node('r1')
r2 = g_phy.node('r2')
r1_r2 = g_phy.node('r1_r2')
self.assertListEqual(new_nodes, [r1_r2])
result = [n.neighbors() for n in new_nodes]
self.assertListEqual([[r1, r2]], result)
# For multiple edges and specifying a prepend for the new nodes
anm = autonetkit.topos.house()
g_phy = anm['phy']
edges = g_phy.node("r2").edges()
new_nodes = ank_utils.split_edges(g_phy, edges, id_prepend="split_")
split_r2_r4 = g_phy.node('split_r2_r4')
split_r1_r2 = g_phy.node('split_r1_r2')
split_r2_r3 = g_phy.node('split_r2_r3')
expected_result = [split_r2_r4, split_r1_r2, split_r2_r3]
self.assertListEqual(expected_result, new_nodes)
result = [n.neighbors() for n in new_nodes]
r3 = g_phy.node('r3')
r4 = g_phy.node('r4')
expected_result = [[r4, r2], [r1, r2], [r2, r3]]
self.assertListEqual(expected_result, result)
def test_groupby(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
r1 = g_phy.node('r1')
r2 = g_phy.node('r2')
r3 = g_phy.node('r3')
r4 = g_phy.node('r4')
r5 = g_phy.node('r5')
expected_result = {1: [r1, r2, r3], 2: [r4, r5]}
self.assertDictEqual(expected_result, g_phy.groupby("asn"))
def test_neigh_attr(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
genexp = ank_utils.neigh_attr(g_phy, "r2", "asn")
result = [item for item in genexp]
self.assertListEqual([2,1,1], result)
def test_neigh_average(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
self.assertEqual(ank_utils.neigh_average(g_phy, "r5", "asn"), 1.5)
self.assertEqual(ank_utils.neigh_average(g_phy, "r3", "asn"), 1.3333333333333333)
def test_fqdn(self):
anm = autonetkit.topos.house()
r1 = anm['phy'].node("r1")
self.assertEqual(ank_utils.fqdn(r1), 'r1.1')
r2 = anm['phy'].node("r2")
self.assertEqual(ank_utils.fqdn(r2), 'r2.1')
def test_aggregate_nodes(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
r2 = g_phy.node('r2')
r3 = g_phy.node('r3')
r5 = g_phy.node('r5')
rlist = ['r4', 'r2']
result = ank_utils.aggregate_nodes(g_phy, rlist)
self.assertListEqual(result, [(r2, r5)])
alist = ['r1', 'r2', 'r3', 'r4']
result = ank_utils.aggregate_nodes(g_phy, alist)
self.assertListEqual(result, [(r3, r5)])
def test_shortest_path(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
r1 = g_phy.node('r1')
r2 = g_phy.node('r2')
r3 = g_phy.node('r3')
r4 = g_phy.node('r4')
r5 = g_phy.node('r5')
self.assertListEqual(ank_utils.shortest_path(g_phy,'r1','r2'), [r1, r2])
self.assertListEqual(ank_utils.shortest_path(g_phy,'r1','r4'), [r1, r2, r4])
self.assertListEqual(ank_utils.shortest_path(g_phy,'r1','r5'), [r1, r3, r5])
def test_neigh_equal(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
self.assertFalse(ank_utils.neigh_equal(g_phy, "r2", "asn"))
self.assertTrue(ank_utils.neigh_equal(g_phy, "r1", "asn"))
def test_wrap_edges(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
r1 = g_phy.node('r1')
r2 = g_phy.node('r2')
r3 = g_phy.node('r3')
r4 = g_phy.node('r4')
r5 = g_phy.node('r5')
elist = [("r1", "r2"), ("r2", "r3")]
edges = ank_utils.wrap_edges(g_phy, elist)
# The edges are now NetworkModel edge objects
expected_result = [(r1, r2), (r2, r3)]
self.assertListEqual(expected_result, edges)
def test_connected_subgraphs(self):
anm = autonetkit.topos.house()
g_phy = anm['phy']
r1 = g_phy.node('r1')
r2 = g_phy.node('r2')
r3 = g_phy.node('r3')
r4 = g_phy.node('r4')
r5 = g_phy.node('r5')
result = ank_utils.connected_subgraphs(g_phy)
expected_result = [[r4, r5, r1, r2, r3]]
self.assertListEqual(expected_result, result)
edges = [("r2", "r4"), ("r3", "r5")]
g_phy.remove_edges_from(edges)
result = ank_utils.connected_subgraphs(g_phy)
expected_result = [[r1, r2, r3], [r4, r5]]
self.assertListEqual(expected_result, result)