def test_method_add_link(normalized_topology_example, capsys): """Проверка работы метода add_link""" norm_top = task_22_1d.Topology(normalized_topology_example) add_link_result = norm_top.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) assert add_link_result == None, "Метод add_link не должен ничего возвращать" assert ( "R1", "Eth0/4", ) in norm_top.topology, "После добавления соединения через метод add_link, оно должно существовать в топологии" assert ( len(norm_top.topology) == 7 ), "После добавления соединения количество соединений должно быть равно 7" # проверка добавления существующего линка norm_top.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) out, err = capsys.readouterr() link_msg = "Такое соединение существует" assert ( link_msg in out ), "При добавлении существующего соединения, не было выведено сообщение 'Такое соединение существует'" # проверка добавления линка с существующим портом norm_top.add_link(("R1", "Eth0/4"), ("R7", "Eth0/5")) out, err = capsys.readouterr() port_msg = "Cоединение с одним из портов существует" assert ( port_msg in out ), "При добавлении соединения с существующим портом, не было выведено сообщение 'Cоединение с одним из портов существует'"
def test_method_add_link(normalized_topology_example, capsys): return_value = task_22_1d.Topology(normalized_topology_example) add_link_result = return_value.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) assert None == add_link_result, "add_link method must return None" assert ( "R1", "Eth0/4", ) in return_value.topology, "After adding a connection via the add_link method, it must exist in the topology" assert 7 == len( return_value.topology ), "After adding a connection, the number of connections should be 7" return_value.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) stdout, err = capsys.readouterr() assert ( "Such a connection already exists" in stdout ), "When adding an existing connection, the message 'Such a connection already exists' was not printed" return_value.add_link(("R1", "Eth0/4"), ("R7", "Eth0/5")) stdout, err = capsys.readouterr() assert ( "A link to one of the ports exists" in stdout ), "When adding a connection to an existing port, the 'A link to one of the ports exists' message was not printed"
def test_method_add_link(normalized_topology_example, capsys): """Проверка работы метода add_link""" return_value = task_22_1d.Topology(normalized_topology_example) add_link_result = return_value.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) assert None == add_link_result, "Метод add_link не должен ничего возвращать" assert ( ("R1", "Eth0/4") in return_value.topology ), "После добавления соединения через метод add_link, оно должно существовать в топологии" assert ( 7 == len(return_value.topology) ), "После добавления соединения количество соединений должно быть равно 7" # проверка добавления существующего линка return_value.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) out, err = capsys.readouterr() assert ( "Такое соединение существует" in out ), "При добавлении существующего соединения, не было выведено сообщение 'Такое соединение существует'" # проверка добавления линка с существующим портом return_value.add_link(("R1", "Eth0/4"), ("R7", "Eth0/5")) out, err = capsys.readouterr() assert ( "Cоединение с одним из портов существует" in out ), "При добавлении соединения с существующим портом, не было выведено сообщение 'Cоединение с одним из портов существует'"
def test_method_add_link(normalized_topology_example, capsys): norm_top = task_22_1d.Topology(normalized_topology_example) add_link_result = norm_top.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) assert add_link_result == None, "add_link method must return None" assert ( "R1", "Eth0/4", ) in norm_top.topology, "After adding a connection via the add_link method, it must exist in the topology" assert ( len(norm_top.topology) == 7 ), "After adding a connection, the number of connections should be 7" norm_top.add_link(("R1", "Eth0/4"), ("R7", "Eth0/0")) out, err = capsys.readouterr() link_msg = "Such a connection already exists" assert ( link_msg in out ), "When adding an existing connection, the message 'Such a connection already exists' was not printed" norm_top.add_link(("R1", "Eth0/4"), ("R7", "Eth0/5")) out, err = capsys.readouterr() port_msg = "A link to one of the ports exists" assert ( port_msg in out ), "When adding a connection to an existing port, the 'A link to one of the ports exists' message was not printed"
def test_topology_normalization(topology_with_dupl_links, normalized_topology_example): """Проверка удаления дублей в топологии""" top_with_data = task_22_1d.Topology(topology_with_dupl_links) assert ( type(top_with_data.topology) == dict ), f"По заданию в переменной topology должен быть словарь, а не {type(top_with_data.topology).__name__}" assert len(top_with_data.topology) == len( normalized_topology_example ), "После создания экземпляра, в переменной topology должна находиться топология без дублей"
def test_topology_normalization(topology_with_dupl_links, normalized_topology_example): """Checking the removal of duplicates in a topology""" top_with_data = task_22_1d.Topology(topology_with_dupl_links) assert ( type(top_with_data.topology) == dict ), f"topology attribute should be a dictionary, not a {type(top_with_data.topology).__name__}" assert len(top_with_data.topology) == len( normalized_topology_example ), "After creating an instance, the topology attribute should contain a topology without duplicates"
def test_method_add_link_created(normalized_topology_example): """Проверяем, что в объекте Topology есть метод add_link""" norm_top = task_22_1d.Topology(normalized_topology_example) check_attr_or_method(norm_top, method="add_link")
def test_attr_topology(topology_with_dupl_links): """Проверяем, что в объекте Topology есть атрибут topology""" top_with_data = task_22_1d.Topology(topology_with_dupl_links) check_attr_or_method(top_with_data, attr="topology")
def test_method_add_link_created(normalized_topology_example): norm_top = task_22_1d.Topology(normalized_topology_example) check_attr_or_method(norm_top, method="add_link")
def test_attr_topology(topology_with_dupl_links): """Checking that the Topology object has a topology attribute""" top_with_data = task_22_1d.Topology(topology_with_dupl_links) check_attr_or_method(top_with_data, attr="topology")
def test_method_add_link_created(normalized_topology_example): return_value = task_22_1d.Topology(normalized_topology_example) check_attr_or_method(return_value, method="add_link")
def test_attr_topology(topology_with_dupl_links): """Checking that the Topology object has a topology attribute""" return_value = task_22_1d.Topology(topology_with_dupl_links) check_attr_or_method(return_value, attr="topology")