Beispiel #1
0
def test_list_root():
    l = [-1]
    assert lens()[0](1)(l) == [1]
    assert l == [-1]
Beispiel #2
0
def test_pfun_list_attribute():
    x = VanillaClass(List([0]))
    assert lens().attribute[0](1)(x).attribute == List([1])
    assert x.attribute == List([0])
Beispiel #3
0
def test_pfun_nested_list():
    l = List([List([-1])])
    assert lens()[0][0](1)(l) == List([List([1])])
    assert l == List([List([-1])])
Beispiel #4
0
def test_pfun_dict_root():
    d = Dict({})
    assert lens()['key']('value')(d) == Dict({'key': 'value'})
    assert d == Dict({})
Beispiel #5
0
def test_vanilla_class_root():
    x = VanillaClass('a')
    assert lens().attribute('b')(x).attribute == 'b'
    assert x.attribute == 'a'
Beispiel #6
0
def test_tuple_index_error():
    t = ()
    with pytest.raises(IndexError):
        lens()[0](1)(t)
Beispiel #7
0
def test_dict_root():
    d = {}
    assert lens()['key']('value')(d) == {'key': 'value'}
    assert d == {}
Beispiel #8
0
def test_dict_immutable_attribute():
    x = ImmutableClass({})
    assert lens().attribute['key']('value')(x) == ImmutableClass(
        {'key': 'value'})
    assert x == ImmutableClass({})
Beispiel #9
0
def test_pfun_dict_attribute():
    x = VanillaClass(Dict({}))
    assert lens().attribute['key']('value')(x).attribute == Dict(
        {'key': 'value'})
    assert x.attribute == Dict({})
Beispiel #10
0
def test_tuple_immutable_attribute():
    x = ImmutableClass((0, ))
    assert lens().attribute[0](1)(x).attribute == (1, )
    assert x == ImmutableClass((0, ))
Beispiel #11
0
def test_dict_attribute():
    x = VanillaClass({})
    assert lens().attribute['key']('value')(x).attribute == {'key': 'value'}
    assert x.attribute == {}
Beispiel #12
0
def test_tuple_attribute():
    x = VanillaClass((0, ))
    assert lens().attribute[0](1)(x).attribute == (1, )
    assert x.attribute == (0, )
Beispiel #13
0
def test_list_immutable_attribute():
    x = ImmutableClass([0])
    assert lens().attribute[0](1)(x) == ImmutableClass([1])
    assert x == ImmutableClass([0])
Beispiel #14
0
def test_list_attribute():
    x = VanillaClass([0])
    assert lens().attribute[0](1)(x).attribute == [1]
    assert x.attribute == [0]
Beispiel #15
0
def test_nested_list():
    l = [[0]]
    assert lens()[0][0](1)(l) == [[1]]
    assert l == [[0]]
Beispiel #16
0
def test_nested_vanilla():
    x = VanillaClass(VanillaClass('a'))
    assert lens().attribute.attribute('b')(x).attribute.attribute == 'b'
    assert x.attribute.attribute == 'a'
Beispiel #17
0
def test_tuple_root():
    t = (-1, )
    assert lens()[0](1)(t) == (1, )
    assert t == (-1, )
Beispiel #18
0
def test_nested_immutable():
    x = ImmutableClass(ImmutableClass('a'))
    assert lens().attribute.attribute('b')(x) == ImmutableClass(
        ImmutableClass('b'))
    assert x == ImmutableClass(ImmutableClass('a'))
Beispiel #19
0
def test_nested_tuple():
    t = ((-1, ), )
    assert lens()[0][0](1)(t) == ((1, ), )
    assert t == ((-1, ), )
Beispiel #20
0
def test_nested_named_tuple():
    x = NamedTupleClass(NamedTupleClass('a'))
    assert lens().attribute.attribute('b')(x) == NamedTupleClass(
        NamedTupleClass('b'))
    assert x == NamedTupleClass(NamedTupleClass('a'))
Beispiel #21
0
def test_nested_dict():
    d = {'key': {}}
    assert lens()['key']['key']('value')(d) == {'key': {'key': 'value'}}
    assert d == {'key': {}}
Beispiel #22
0
def test_pfun_list_root():
    l = List([-1])
    assert lens()[0](1)(l) == List([1])
    assert l == List([-1])
Beispiel #23
0
def test_nested_pfun_dict():
    d = Dict({'key': Dict({})})
    assert lens()['key']['key']('value')(d) == Dict(
        {'key': Dict({'key': 'value'})})
    assert d == Dict({'key': Dict({})})
Beispiel #24
0
def test_pfun_list_index_error():
    l = List([])
    with pytest.raises(IndexError):
        lens()[0]('')(l)
Beispiel #25
0
def test_immutable_class_root():
    x = ImmutableClass('a')
    assert lens().attribute('b')(x) == ImmutableClass('b')
    assert x == ImmutableClass('a')
Beispiel #26
0
def test_named_tuple_root():
    x = NamedTupleClass('a')
    assert lens().attribute('b')(x) == NamedTupleClass('b')
    assert x == NamedTupleClass('a')