示例#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')
示例#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__')
示例#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
示例#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')
示例#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
示例#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
示例#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')