Exemplo n.º 1
0
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_4_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')
Exemplo n.º 2
0
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_4_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__')
Exemplo n.º 3
0
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_4_3a.Topology(example)
    # test __len__
    assert len(top.topology) == 3
Exemplo n.º 4
0
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_4_3a.Topology(example)

    # test __setitem__
    top[('SW1', 'Eth0/1')] = ('R1', 'Eth0/0')
    assert top[('R1', 'Eth0/0')] == ('SW1', 'Eth0/1')
Exemplo n.º 5
0
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_4_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
Exemplo n.º 6
0
def test_methods():
    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_4_3a.Topology(example)
    # test __len__
    assert len(top.topology) == 3

    # test __getitem__
    assert top[('R1', 'Eth0/0')] == ('SW1', 'Eth0/1')
    assert top[('SW1', 'Eth0/1')] == ('R1', 'Eth0/0')

    # test __detitem__
    del top[('R1', 'Eth0/0')]
    assert len(top.topology) == 2
Exemplo n.º 7
0
def test_attr_topology(topology_with_dupl_links):
    '''Проверяем, что в объекте Topology есть атрибут topology'''
    top_with_data = task_4_3a.Topology(topology_with_dupl_links)
    check_attr_or_method(top_with_data, attr='topology')