本文整理汇总了Python中netdiff.diff函数的典型用法代码示例。如果您正苦于以下问题:Python diff函数的具体用法?Python diff怎么用?Python diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了diff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_changes
def test_no_changes(self):
old = NetJsonParser(links2)
new = NetJsonParser(links2)
result = diff(old, new)
self.assertIsInstance(result, dict)
self.assertIsNone(result['added'])
self.assertIsNone(result['removed'])
示例2: test_no_changes
def test_no_changes(self):
old = CnmlParser(cnml1)
new = CnmlParser(cnml1)
result = diff(old, new)
self.assertIsInstance(result, dict)
self.assertIsNone(result['added'])
self.assertIsNone(result['removed'])
示例3: test_simple_diff
def test_simple_diff(self):
old = OlsrParser(links3)
new = OlsrParser(links5)
result = diff(old, new)
self.assertIsNone(result['changed'])
# ensure there are differences
self.assertEqual(len(result['added']['links']), 3)
self.assertEqual(len(result['removed']['links']), 1)
self.assertEqual(len(result['added']['nodes']), 2)
self.assertEqual(len(result['removed']['nodes']), 1)
# ensure 3 links added
self._test_expected_links(
graph=result['added'],
expected_links=[
('10.150.0.3', '10.150.0.7'),
('10.150.0.3', '10.150.0.6'),
('10.150.0.7', '10.150.0.6'),
]
)
self._test_expected_links(
graph=result['removed'],
expected_links=[('10.150.0.5', '10.150.0.4')]
)
added_nodes = [node['id'] for node in result['added']['nodes']]
self.assertIn('10.150.0.6', added_nodes)
self.assertIn('10.150.0.7', added_nodes)
self.assertIn('10.150.0.5', result['removed']['nodes'][0].values())
示例4: test_no_changes
def test_no_changes(self):
old = BatmanParser(iulinet)
new = BatmanParser(iulinet)
result = diff(old, new)
self.assertIsInstance(result, dict)
self.assertIsNone(result['added'])
self.assertIsNone(result['removed'])
示例5: test_no_changes
def test_no_changes(self):
old = Bmx6Parser(topo)
new = Bmx6Parser(topo)
result = diff(old, new)
self.assertIsInstance(result, dict)
self.assertIsNone(result['added'])
self.assertIsNone(result['removed'])
示例6: test_added_1_link
def test_added_1_link(self):
old = CnmlParser(cnml1)
new = CnmlParser(cnml2)
result = diff(old, new)
self.assertIsNone(result['removed'])
# ensure there are differences
self.assertEqual(len(result['added']['links']), 1)
# ensure 1 link added
self.assertIn('10.228.172.97', result['added']['links'][0].values())
self.assertIn('10.228.172.101', result['added']['links'][0].values())
示例7: diff
def diff(self, data=None):
""" shortcut to netdiff.diff """
# if we get an instance of ``self.parser_class`` it means
# ``self.get_topology_data`` has already been executed by ``receive``
if isinstance(data, self.parser_class):
latest = data
else:
latest = self.get_topology_data(data)
current = NetJsonParser(self.json(dict=True, omit_down=True))
return diff(current, latest)
示例8: test_no_changes
def test_no_changes(self):
old = OlsrParser(links2)
new = OlsrParser(links2)
result = diff(old, new)
self.assertTrue(type(result) is dict)
self.assertTrue(type(result['added']) is list)
self.assertTrue(type(result['removed']) is list)
# ensure there are no differences
self.assertEqual(len(result['added']), 0)
self.assertEqual(len(result['removed']), 0)
示例9: test_added_1_link
def test_added_1_link(self):
old = OlsrParser(links2)
new = OlsrParser(links3)
result = diff(old, new)
# ensure there are differences
self.assertEqual(len(result['added']), 1)
self.assertEqual(len(result['removed']), 0)
# ensure 1 link added
self.assertIn('10.150.0.5', result['added'][0])
self.assertIn('10.150.0.4', result['added'][0])
示例10: test_removed_1_link
def test_removed_1_link(self):
old = CnmlParser(cnml2)
new = CnmlParser(cnml1)
result = diff(old, new)
self.assertIsInstance(result, dict)
self.assertIsNone(result['added'])
self.assertTrue(type(result['removed']['links']) is list)
# ensure there are differences
self.assertEqual(len(result['removed']['links']), 1)
# ensure 1 link removed
self.assertIn('10.228.172.97', result['removed']['links'][0].values())
self.assertIn('10.228.172.101', result['removed']['links'][0].values())
示例11: test_added_1_link
def test_added_1_link(self):
old = NetJsonParser(links2)
new = NetJsonParser(links3)
result = diff(old, new)
self.assertIsNone(result['removed'])
# ensure there are no differences
self.assertEqual(len(result['added']['links']), 1)
self.assertEqual(len(result['added']['nodes']), 1)
# ensure correct link added
self.assertIn('10.150.0.5', result['added']['links'][0].values())
self.assertIn('10.150.0.4', result['added']['links'][0].values())
# ensure correct node added
self.assertIn('10.150.0.5', result['added']['nodes'][0].values())
示例12: test_removed_1_link
def test_removed_1_link(self):
old = OlsrParser(links3)
new = OlsrParser(links2)
result = diff(old, new)
self.assertTrue(type(result) is dict)
self.assertTrue(type(result['added']) is list)
self.assertTrue(type(result['removed']) is list)
# ensure there are differences
self.assertEqual(len(result['added']), 0)
self.assertEqual(len(result['removed']), 1)
# ensure 1 link removed
self.assertIn('10.150.0.5', result['removed'][0])
self.assertIn('10.150.0.4', result['removed'][0])
示例13: test_cost_changes_1
def test_cost_changes_1(self):
old = OlsrParser(links2)
new = OlsrParser(links2_cost)
result = diff(old, new)
self.assertIsNone(result['added'])
self.assertIsNone(result['removed'])
self.assertIsInstance(result['changed'], dict)
self.assertEqual(len(result['changed']['nodes']), 0)
links = result['changed']['links']
self.assertTrue(type(links) is list)
self.assertEqual(len(links), 2)
# ensure results are correct
self.assertTrue(1.302 in (links[0]['cost'], links[1]['cost']))
self.assertTrue(1.023 in (links[0]['cost'], links[1]['cost']))
示例14: test_label_diff_added
def test_label_diff_added(self):
old = OpenvpnParser({})
new = OpenvpnParser(links5_tap)
result = diff(old, new)
labels = []
for node in result['added']['nodes']:
if 'label' in node:
labels.append(node['label'])
self.assertEqual(len(labels), 5)
self.assertIn('nodeA', labels)
self.assertIn('nodeB', labels)
self.assertIn('nodeC', labels)
self.assertIn('nodeD', labels)
self.assertIn('nodeE', labels)
示例15: test_cost_changes_2
def test_cost_changes_2(self):
old = OlsrParser(links5)
new = OlsrParser(links5_cost)
result = diff(old, new)
self.assertIsNone(result['added'])
self.assertIsNone(result['removed'])
self.assertIsInstance(result['changed'], dict)
self.assertEqual(len(result['changed']['nodes']), 0)
links = result['changed']['links']
self.assertEqual(len(links), 4)
weights = [link['weight'] for link in links]
self.assertIn(1.0, weights)
self.assertIn(2.0, weights)
self.assertIn(1.50390625, weights)
self.assertIn(3.515625, weights)