Ejemplo n.º 1
0
def test_list_view_not_equals(list_proto):
    view_1 = ListView(list_proto)
    lv = ListValue()
    l = [0, 1, 'heya', {'key': 'value'}, [0, 1, 2]]
    lv.extend(l)
    view_2 = ListView(lv)
    assert view_2 != view_1
Ejemplo n.º 2
0
def test_list_view_append_empty():
    lv = ListValue()
    view = ListView(lv)
    assert len(view) == 0
    view.append(10)
    assert len(view) == 1
    assert view[0] == 10
Ejemplo n.º 3
0
def test_list_reverse():
    list = ListValue()
    l = [0, 2, 1]
    list.extend(l)
    view = ListView(list)
    view.reverse()
    assert view[0] == 1
    assert view[1] == 2
    assert view[2] == 0
Ejemplo n.º 4
0
def test_list_view_iterate(list_proto):
    view = ListView(list_proto)
    for i, element in enumerate(view):
        assert view[0] == 0
        assert view[1] == 1
        assert view[2] == 'hey'
        assert view[3] == {'key': 'value'}
        assert len(view[4]) == 3
        assert view[4][0] == 0
        assert view[4][1] == 1
        assert view[4][2] == 2
        if i == 0:
            assert element == 0
        elif i == 1:
            assert element == 1
        elif i == 2:
            assert element == 'hey'
        elif i == 3:
            assert element == {'key': 'value'}
        elif i == 4:
            assert len(element) == 3
            for j, e in enumerate(element):
                if j == 0:
                    assert e == 0
                elif j == 1:
                    assert e == 1
                elif j == 2:
                    assert e == 2
Ejemplo n.º 5
0
def test_list_contains(list_proto):
    view = ListView(list_proto)
    assert 'hey' in view
    assert 'heya' not in view
    assert {'key': 'value'} in view
    assert {'key': 'value-aaa'} not in view
    assert [0, 1, 2] in view
Ejemplo n.º 6
0
def test_list_view_delete(list_proto):
    view = ListView(list_proto)
    del view[1]
    assert len(view) == 4
    assert view[0] == 0
    assert view[1] == 'hey'
    assert view[2] == {'key': 'value'}
    assert len(view[3]) == 3
    assert view[3][0] == 0
    assert view[3][1] == 1
    assert view[3][2] == 2
Ejemplo n.º 7
0
def test_list_view_insert():
    lv = ListValue()
    view = ListView(lv)
    assert len(view) == 0
    view.insert(0, 10)
    assert len(view) == 1
    assert view[0] == 10
    view.insert(20, 20)
    assert len(view) == 2
    assert view[1] == 20
    view.insert(0, 30)
    assert len(view) == 2
    assert view[0] == 30
Ejemplo n.º 8
0
def test_list_view(list_proto):
    view = ListView(list_proto)
    assert len(view) == 5
    assert view[-4] == 1
    assert view[0] == 0
    assert view[1] == 1
    assert view[2] == 'hey'
    assert view[3] == {'key': 'value'}
    assert len(view[4]) == 3
    assert view[4][0] == 0
    assert view[4][1] == 1
    assert view[4][2] == 2
Ejemplo n.º 9
0
def test_list_view_set_items(list_proto):
    view = ListView(list_proto)
    view[0] = 20
    view[1] = 'now string'
    view[2] = {'key': 'value'}
    view[3]['key'] = 50
    view[4][0] = {'new_key': 'new_value'}
    assert view[0] == 20
    assert view[1] == 'now string'
    assert view[2] == {'key': 'value'}
    assert view[3] == {'key': 50}
    assert view[4][0] == {'new_key': 'new_value'}
    assert view[4][1] == 1
    assert view[4][2] == 2
    view[4][0]['new_key'] = None
    assert view[4][0] == {'new_key': None}
Ejemplo n.º 10
0
def test_empty_struct_view():
    l = ListValue()
    view = ListView(l)
    assert len(view) == 0
Ejemplo n.º 11
0
def test_list_view_clear(list_proto):
    view = ListView(list_proto)
    assert len(view) == 5
    view.clear()
    assert len(view) == 0
Ejemplo n.º 12
0
def test_list_view_access_out_of_bounds(list_proto):
    view = ListView(list_proto)
    with pytest.raises(IndexError):
        _ = view[100]
Ejemplo n.º 13
0
def test_list_view_dict():
    list = ListValue()
    l = [0, 1, 'hey', {'key': 'value'}, [0, 1, 2]]
    list.extend(l)
    view = ListView(list)
    assert view.dict() == l