Пример #1
0
def test_function_return_value():
    """
    Проверка работы функции
    """
    correct_return_value = unify_topology_dict({
        ("R1", "Eth 0/0"): ("SW1", "Eth 0/1"),
        ("R2", "Eth 0/0"): ("SW1", "Eth 0/2"),
        ("R2", "Eth 0/1"): ("R5", "Eth 0/0"),
        ("R2", "Eth 0/2"): ("R6", "Eth 0/1"),
        ("R3", "Eth 0/0"): ("SW1", "Eth 0/3"),
        ("R4", "Eth 0/0"): ("SW1", "Eth 0/4"),
        ("R4", "Eth 0/1"): ("R5", "Eth 0/1"),
    })

    assert os.path.exists("topology.yaml"), "Файл topology.yaml не существует"
    return_value = task_17_3b.transform_topology("topology.yaml")
    assert return_value != None, "Функция ничего не возвращает"
    assert (
        type(return_value) == dict
    ), f"По заданию функция должна возвращать словарь, а возвращает {type(return_value).__name__}"
    assert len(correct_return_value) == len(
        return_value
    ), "В словаре, который описывает топологию есть дублирующиеся линки"
    assert correct_return_value == unify_topology_dict(
        return_value), "Функция возвращает неправильное значение"
Пример #2
0
def test_function_return_value():
    """
    Function check
    """
    correct_return_value = unify_topology_dict(
        {
            ("R1", "Eth 0/0"): ("SW1", "Eth 0/1"),
            ("R2", "Eth 0/0"): ("SW1", "Eth 0/2"),
            ("R2", "Eth 0/1"): ("R5", "Eth 0/0"),
            ("R2", "Eth 0/2"): ("R6", "Eth 0/1"),
            ("R3", "Eth 0/0"): ("SW1", "Eth 0/3"),
            ("R4", "Eth 0/0"): ("SW1", "Eth 0/4"),
            ("R4", "Eth 0/1"): ("R5", "Eth 0/1"),
        }
    )

    assert os.path.exists("topology.yaml"), "topology.yaml file does not exist"
    return_value = task_17_3b.transform_topology("topology.yaml")
    assert return_value != None, "The function returns None"
    assert (
        type(return_value) == dict
    ), f"The function should return a dict, instead it returns a {type(return_value).__name__}"
    assert len(correct_return_value) == len(
        return_value
    ), "There are duplicate links in the dictionary that describes the topology"
    assert correct_return_value == unify_topology_dict(
        return_value
    ), "Function returns wrong value"
def test_topology_normalization():
    """Проверка удаления дублей в топологии"""
    topology_with_dupl_links = {
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
        ("SW1", "Eth0/1"): ("R1", "Eth0/0"),
        ("SW1", "Eth0/2"): ("R2", "Eth0/0"),
        ("SW1", "Eth0/3"): ("R3", "Eth0/0"),
    }
    correct_topology = unify_topology_dict({
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
    })

    return_value = task_22_1.Topology(topology_with_dupl_links)
    return_topology = unify_topology_dict(return_value.topology)
    assert (
        type(return_value.topology) == dict
    ), f"По заданию в переменной topology должен быть словарь, а не {type(return_value.topology).__name__}"
    assert len(correct_topology) == len(
        return_value.topology
    ), "После создания экземпляра, в переменной topology должна находиться топология без дублей"
    assert (
        correct_topology == return_topology
    ), "После создания экземпляра, в переменной topology должна находиться топология без дублей"
Пример #4
0
def test_topology_normalization():
    """Checking the removal of duplicates in a topology"""
    topology_with_dupl_links = {
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
        ("SW1", "Eth0/1"): ("R1", "Eth0/0"),
        ("SW1", "Eth0/2"): ("R2", "Eth0/0"),
        ("SW1", "Eth0/3"): ("R3", "Eth0/0"),
    }
    correct_topology = unify_topology_dict({
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
    })

    return_value = task_22_1.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"
    assert (
        correct_topology == return_topology
    ), "After creating an instance, the topology attribute should contain a topology without duplicates"
def test_topology_normalization(topology_with_dupl_links, normalized_topology_example):
    """Проверка удаления дублей в топологии"""
    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 должен быть словарь, а не {type(top_with_data.topology).__name__}"
    assert len(correct_topology) == len(
        return_value.topology
    ), "После создания экземпляра, в переменной topology должна находиться топология без дублей"
Пример #6
0
def test_topology_normalization(topology_with_dupl_links,
                                normalized_topology_example):
    """Checking the removal of duplicates in a topology"""
    correct_topology = unify_topology_dict(normalized_topology_example)
    return_value = task_22_1b.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_function_return_value_different_args():
    """
    Проверка работы функции на другом выводе
    """
    input_value = {
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
        ("R4", "Eth0/0"): ("R3", "Eth0/1"),
        ("R5", "Eth0/0"): ("R3", "Eth0/2"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
    }
    correct_return_value = {
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
    }

    return_value = task_11_2a.unique_network_map(input_value)
    assert return_value is not None, "Функция ничего не возвращает"
    assert (
        type(return_value) == dict
    ), f"По заданию функция должна возвращать словарь, а возвращает {type(return_value).__name__}"
    assert len(correct_return_value) == len(
        return_value
    ), "В словаре, который описывает топологию есть дублирующиеся линки"
    unified_return_value = unify_topology_dict(return_value)
    assert (
        correct_return_value == unified_return_value
    ), "Функция возвращает неправильное значение"
Пример #8
0
def test_function_return_value():
    """
    Проверка работы функции
    """
    sh_cdp_topology_tuples = {
        ("R1", "Eth 0/0"): ("SW1", "Eth 0/1"),
        ("R2", "Eth 0/0"): ("SW1", "Eth 0/2"),
        ("R2", "Eth 0/1"): ("R5", "Eth 0/0"),
        ("R2", "Eth 0/2"): ("R6", "Eth 0/1"),
        ("R3", "Eth 0/0"): ("SW1", "Eth 0/3"),
        ("R4", "Eth 0/0"): ("SW1", "Eth 0/4"),
        ("R4", "Eth 0/1"): ("R5", "Eth 0/1"),
    }
    correct_return_value = unify_topology_dict(sh_cdp_topology_tuples)

    assert os.path.exists("topology.yaml"), "Файл topology.yaml не существует"
    return_value = task_17_3b.transform_topology("topology.yaml")
    assert return_value != None, "Функция ничего не возвращает"
    assert (
        type(return_value) == dict
    ), f"По заданию функция должна возвращать словарь, а возвращает {type(return_value).__name__}"
    assert (unify_topology_dict(return_value) == correct_return_value
            ), "Функция возвращает неправильное значение"
Пример #9
0
def test_function_return_value():
    """
    Function check
    """
    sh_cdp_topology_tuples = {
        ("R1", "Eth 0/0"): ("SW1", "Eth 0/1"),
        ("R2", "Eth 0/0"): ("SW1", "Eth 0/2"),
        ("R2", "Eth 0/1"): ("R5", "Eth 0/0"),
        ("R2", "Eth 0/2"): ("R6", "Eth 0/1"),
        ("R3", "Eth 0/0"): ("SW1", "Eth 0/3"),
        ("R4", "Eth 0/0"): ("SW1", "Eth 0/4"),
        ("R4", "Eth 0/1"): ("R5", "Eth 0/1"),
    }
    correct_return_value = unify_topology_dict(sh_cdp_topology_tuples)

    assert os.path.exists("topology.yaml"), "topology.yaml file does not exist"
    return_value = task_17_3b.transform_topology("topology.yaml")
    assert return_value != None, "The function returns None"
    assert (
        type(return_value) == dict
    ), f"The function should return a dict, instead it returns a {type(return_value).__name__}"
    assert (unify_topology_dict(return_value) == correct_return_value
            ), "Function returns wrong value"
Пример #10
0
def test_function_return_value():
    """
    Проверка работы функции
    """
    sh_cdp_n_sw1 = (
        "SW1>show cdp neighbors\n\n"
        "Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge\n"
        "                  S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone\n\n"
        "Device ID    Local Intrfce   Holdtme     Capability       Platform    Port ID\n"
        "R1           Eth 0/1         122           R S I           2811       Eth 0/0\n"
        "R2           Eth 0/2         143           R S I           2811       Eth 0/0\n"
        "R3           Eth 0/3         151           R S I           2811       Eth 0/0\n"
        "R6           Eth 0/5         121           R S I           2811       Eth 0/1"
    )
    correct_return_value = {
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
        ("R6", "Eth0/1"): ("SW1", "Eth0/5"),
    }

    return_value = task_11_2.create_network_map([
        'sh_cdp_n_r2.txt', 'sh_cdp_n_r1.txt', 'sh_cdp_n_sw1.txt',
        'sh_cdp_n_r3.txt'
    ])
    assert return_value != None, "Функция ничего не возвращает"
    assert (
        type(return_value) == dict
    ), f"По заданию функция должна возвращать словарь, а возвращает {type(return_value).__name__}"
    assert len(return_value) == len(
        correct_return_value
    ), "В словаре, который описывает топологию есть дублирующиеся линки"
    unified_return_value = unify_topology_dict(return_value)
    assert (unified_return_value == correct_return_value
            ), "Функция возвращает неправильное значение"
Пример #11
0
def test_function_return_value():
    """
    Function check
    """
    input_value = {
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
        ("SW1", "Eth0/1"): ("R1", "Eth0/0"),
        ("SW1", "Eth0/2"): ("R2", "Eth0/0"),
        ("SW1", "Eth0/3"): ("R3", "Eth0/0"),
        ("SW1", "Eth0/5"): ("R6", "Eth0/1"),
    }
    correct_return_value = {
        ("R1", "Eth0/0"): ("SW1", "Eth0/1"),
        ("R2", "Eth0/0"): ("SW1", "Eth0/2"),
        ("R2", "Eth0/1"): ("SW2", "Eth0/11"),
        ("R3", "Eth0/0"): ("SW1", "Eth0/3"),
        ("R3", "Eth0/1"): ("R4", "Eth0/0"),
        ("R3", "Eth0/2"): ("R5", "Eth0/0"),
        ("R6", "Eth0/1"): ("SW1", "Eth0/5"),
    }

    return_value = task_11_2a.unique_network_map(input_value)
    assert return_value != None, "The function returns None"
    assert (
        type(return_value) == dict
    ), f"The function should return a dict, instead it returns a {type(return_value).__name__}"
    assert len(return_value) == len(
        correct_return_value
    ), "There are duplicate links in the dictionary that describes the topology"
    unified_return_value = unify_topology_dict(return_value)
    assert (unified_return_value == correct_return_value
            ), "Function returns wrong value"