def test_topology_normalization(topology_with_dupl_links, normalized_topology_example): """Проверка удаления дублей в топологии""" top_with_data = task_22_1c.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_1c.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" correct_topology = unify_topology_dict(normalized_topology_example) return_value = task_22_1c.Topology(topology_with_dupl_links) return_topology = unify_topology_dict(return_value.topology) assert ( type(return_value.topology) == dict ), f"topology attribute should be a dictionary, not a {type(top_with_data.topology).__name__}" assert len(correct_topology) == len( return_value.topology ), "After creating an instance, the topology attribute should contain a topology without duplicates"
def test_method_delete_node(normalized_topology_example, capsys): return_value = task_22_1c.Topology(normalized_topology_example) node = "SW1" delete_node_result = return_value.delete_node(node) assert None == delete_node_result, "The delete_node method should return None" ports_with_node = [ src for src, dst in return_value.topology.items() if node in src or node in dst ] assert 0 == len(ports_with_node), "Links to host SW1 have not been deleted" assert 3 == len(return_value.topology ), "Only three connections should remain in the topology" return_value.delete_node(node) stdout, err = capsys.readouterr() assert ( "There is no such device" in stdout ), "When deleting a non-existent device, the message 'There is no such device' was not displayed"
def test_method_delete_node(normalized_topology_example, capsys): norm_top = task_22_1c.Topology(normalized_topology_example) node = "SW1" delete_node_result = norm_top.delete_node(node) assert delete_node_result == None, "The delete_node method should return None" ports_with_node = [ src for src, dst in norm_top.topology.items() if node in src or node in dst ] assert len(ports_with_node) == 0, "Links to host SW1 have not been deleted" assert (len(norm_top.topology) == 3 ), "Only three connections should remain in the topology" norm_top.delete_node(node) out, err = capsys.readouterr() node_msg = "There is no such device" assert ( node_msg in out ), "When deleting a non-existent device, the message 'There is no such device' was not displayed"
def test_method_delete_node(normalized_topology_example, capsys): """Проверка работы метода delete_node""" return_value = task_22_1c.Topology(normalized_topology_example) node = "SW1" delete_node_result = return_value.delete_node(node) assert None == delete_node_result, "Метод delete_node не должен ничего возвращать" ports_with_node = [ src for src, dst in return_value.topology.items() if node in src or node in dst ] assert 0 == len(ports_with_node), "Соединения с хостом SW1 не были удалены" assert 3 == len( return_value.topology ), "В топологии должны остаться только три соединения" # проверка удаления несуществующего устройства return_value.delete_node(node) out, err = capsys.readouterr() assert ( "Такого устройства нет" in out ), "При удалении несуществующего устройства, не было выведено сообщение 'Такого устройства нет'"
def test_method_delete_node_created( topology_with_dupl_links, normalized_topology_example ): """Проверяем, что в объекте Topology есть метод delete_node""" return_value = task_22_1c.Topology(normalized_topology_example) check_attr_or_method(return_value, method="delete_node")
def test_attr_topology(topology_with_dupl_links): """Проверяем, что в объекте Topology есть атрибут topology""" top_with_data = task_22_1c.Topology(topology_with_dupl_links) check_attr_or_method(top_with_data, attr="topology")
def test_method_delete_node_created(topology_with_dupl_links, normalized_topology_example): return_value = task_22_1c.Topology(normalized_topology_example) check_attr_or_method(return_value, method="delete_node")
def test_attr_topology(topology_with_dupl_links): """Checking that the Topology object has a topology attribute""" top_with_data = task_22_1c.Topology(topology_with_dupl_links) check_attr_or_method(top_with_data, attr="topology")