def test_method_len(): example = { ("R1", "Eth0/0"): ("SW1", "Eth0/1"), ("R2", "Eth0/0"): ("SW1", "Eth0/2"), ("R3", "Eth0/0"): ("SW1", "Eth0/3"), ("SW1", "Eth0/1"): ("R1", "Eth0/0"), ("SW1", "Eth0/2"): ("R2", "Eth0/0"), ("SW1", "Eth0/3"): ("R3", "Eth0/0"), } top = task_12_3a.Topology(example) # test __len__ assert len(top.topology) == 3
def test_sequence_special_methods_created(): example = { ("R1", "Eth0/0"): ("SW1", "Eth0/1"), ("R2", "Eth0/0"): ("SW1", "Eth0/2"), ("R3", "Eth0/0"): ("SW1", "Eth0/3"), } top = task_12_3a.Topology(example) check_attr_or_method(top, method="__getitem__") check_attr_or_method(top, method="__setitem__") check_attr_or_method(top, method="__delitem__") check_attr_or_method(top, method="__len__") check_attr_or_method(top, method="__iter__")
def test_sequence_mixin_methods_created(): example = { ("R1", "Eth0/0"): ("SW1", "Eth0/1"), ("R2", "Eth0/0"): ("SW1", "Eth0/2"), ("R3", "Eth0/0"): ("SW1", "Eth0/3"), } top = task_12_3a.Topology(example) check_attr_or_method(top, method="keys") check_attr_or_method(top, method="get") check_attr_or_method(top, method="pop") check_attr_or_method(top, method="clear") check_attr_or_method(top, method="update")
def test_method_len(): example = { ('R1', 'Eth0/0'): ('SW1', 'Eth0/1'), ('R2', 'Eth0/0'): ('SW1', 'Eth0/2'), ('R3', 'Eth0/0'): ('SW1', 'Eth0/3'), ('SW1', 'Eth0/1'): ('R1', 'Eth0/0'), ('SW1', 'Eth0/2'): ('R2', 'Eth0/0'), ('SW1', 'Eth0/3'): ('R3', 'Eth0/0') } top = task_12_3a.Topology(example) # test __len__ assert len(top.topology) == 3
def test_sequence_mixin_methods_created(): example = { ('R1', 'Eth0/0'): ('SW1', 'Eth0/1'), ('R2', 'Eth0/0'): ('SW1', 'Eth0/2'), ('R3', 'Eth0/0'): ('SW1', 'Eth0/3') } top = task_12_3a.Topology(example) check_attr_or_method(top, method='keys') check_attr_or_method(top, method='get') check_attr_or_method(top, method='pop') check_attr_or_method(top, method='clear') check_attr_or_method(top, method='update')
def test_sequence_special_methods_created(): example = { ('R1', 'Eth0/0'): ('SW1', 'Eth0/1'), ('R2', 'Eth0/0'): ('SW1', 'Eth0/2'), ('R3', 'Eth0/0'): ('SW1', 'Eth0/3') } top = task_12_3a.Topology(example) check_attr_or_method(top, method='__getitem__') check_attr_or_method(top, method='__setitem__') check_attr_or_method(top, method='__delitem__') check_attr_or_method(top, method='__len__') check_attr_or_method(top, method='__iter__')
def test_method_setitem(): example = { ("R1", "Eth0/0"): ("SW1", "Eth0/1"), ("R2", "Eth0/0"): ("SW1", "Eth0/2"), ("R3", "Eth0/0"): ("SW1", "Eth0/3"), ("SW1", "Eth0/1"): ("R1", "Eth0/0"), ("SW1", "Eth0/2"): ("R2", "Eth0/0"), ("SW1", "Eth0/3"): ("R3", "Eth0/0"), } top = task_12_3a.Topology(example) # test __setitem__ top[("SW1", "Eth0/1")] = ("R1", "Eth0/0") assert top[("R1", "Eth0/0")] == ("SW1", "Eth0/1")
def test_method_setitem(): example = { ('R1', 'Eth0/0'): ('SW1', 'Eth0/1'), ('R2', 'Eth0/0'): ('SW1', 'Eth0/2'), ('R3', 'Eth0/0'): ('SW1', 'Eth0/3'), ('SW1', 'Eth0/1'): ('R1', 'Eth0/0'), ('SW1', 'Eth0/2'): ('R2', 'Eth0/0'), ('SW1', 'Eth0/3'): ('R3', 'Eth0/0') } top = task_12_3a.Topology(example) # test __setitem__ top[('SW1', 'Eth0/1')] = ('R1', 'Eth0/0') assert top[('R1', 'Eth0/0')] == ('SW1', 'Eth0/1')
def test_method_delitem(): example = { ("R1", "Eth0/0"): ("SW1", "Eth0/1"), ("R2", "Eth0/0"): ("SW1", "Eth0/2"), ("R3", "Eth0/0"): ("SW1", "Eth0/3"), ("SW1", "Eth0/1"): ("R1", "Eth0/0"), ("SW1", "Eth0/2"): ("R2", "Eth0/0"), ("SW1", "Eth0/3"): ("R3", "Eth0/0"), } top = task_12_3a.Topology(example) # test __detitem__ del top[("R1", "Eth0/0")] assert len(top.topology) == 2 # test mirror __detitem__ del top[("SW1", "Eth0/2")] assert len(top.topology) == 1
def test_method_delitem(): example = { ('R1', 'Eth0/0'): ('SW1', 'Eth0/1'), ('R2', 'Eth0/0'): ('SW1', 'Eth0/2'), ('R3', 'Eth0/0'): ('SW1', 'Eth0/3'), ('SW1', 'Eth0/1'): ('R1', 'Eth0/0'), ('SW1', 'Eth0/2'): ('R2', 'Eth0/0'), ('SW1', 'Eth0/3'): ('R3', 'Eth0/0') } top = task_12_3a.Topology(example) # test __detitem__ del top[('R1', 'Eth0/0')] assert len(top.topology) == 2 # test mirror __detitem__ del top[('SW1', 'Eth0/2')] assert len(top.topology) == 1
def test_attr_topology(topology_with_dupl_links): """Проверяем, что в объекте Topology есть атрибут topology""" top_with_data = task_12_3a.Topology(topology_with_dupl_links) check_attr_or_method(top_with_data, attr="topology")