Пример #1
0
def test_from_iter_custom_class():
    class C(object):
        def __init__(self, attr):
            self.attr = attr

        def __eq__(self, other):
            return self.attr == other.attr

        def _lens_from_iter(self, iterable):
            return C(next(iter(iterable)))

    assert s.from_iter(C(1), [2]) == C(2)
Пример #2
0
def test_from_iter_custom_class():
    class C(object):

        def __init__(self, attr):
            self.attr = attr

        def __eq__(self, other):
            return self.attr == other.attr

        def _lens_from_iter(self, iterable):
            return C(next(iter(iterable)))

    assert s.from_iter(C(1), [2]) == C(2)
Пример #3
0
def test_from_iter_set():
    assert s.from_iter(set(), [1, 2, 3]) == {1, 2, 3}
Пример #4
0
def test_from_iter_list():
    assert s.from_iter([], (1, 2, 3)) == [1, 2, 3]
Пример #5
0
def test_from_iter_bytes():
    assert s.from_iter(b'', s.to_iter(b'123')) == b'123'
Пример #6
0
def test_from_iter_dict():
    data = {"jane": 5, "jim": 6, "joanne": 8}
    new_keys = [(k.capitalize(), v) for k, v in s.to_iter(data)]
    assert s.from_iter(data, new_keys) == {"Jane": 5, "Jim": 6, "Joanne": 8}
Пример #7
0
def test_from_iter_tuple():
    assert s.from_iter((), [1, 2, 3]) == (1, 2, 3)
Пример #8
0
def test_from_iter_dict():
    data = {'jane': 5, 'jim': 6, 'joanne': 8}
    new_keys = [(k.capitalize(), v) for k, v in s.to_iter(data)]
    assert s.from_iter(data, new_keys) == {'Jane': 5, 'Jim': 6, 'Joanne': 8}
Пример #9
0
def test_from_iter_bytes():
    assert s.from_iter(b"", s.to_iter(b"123")) == b"123"
Пример #10
0
def test_from_iter_set():
    assert s.from_iter(set(), [1, 2, 3]) == {1, 2, 3}
Пример #11
0
def test_from_iter_list():
    assert s.from_iter([], (1, 2, 3)) == [1, 2, 3]
Пример #12
0
def test_from_iter_bytes():
    assert s.from_iter(b'', [49, 50, 51]) == b'123'
Пример #13
0
def test_from_iter_unknown():
    with pytest.raises(NotImplementedError):
        s.from_iter(object(), [1, 2, 3])
Пример #14
0
def test_from_iter_dict():
    data = {'jane': 5, 'jim': 6, 'joanne': 8}
    new_keys = [(k.capitalize(), v) for k, v in s.to_iter(data)]
    assert s.from_iter(data, new_keys) == {'Jane': 5, 'Jim': 6, 'Joanne': 8}
Пример #15
0
def test_from_iter_str():
    assert s.from_iter(u'', ['1', '2', '3']) == u'123'
Пример #16
0
def test_from_iter_str():
    assert s.from_iter(u"", ["1", "2", "3"]) == u"123"
Пример #17
0
def test_from_iter_tuple():
    assert s.from_iter((), [1, 2, 3]) == (1, 2, 3)
Пример #18
0
def test_from_iter_namedtuple():
    Tup = collections.namedtuple("Tup", "attr1 attr2 attr3")
    iterTup = s.from_iter(Tup(1, 2, 3), [4, 5, 6])
    assert iterTup == Tup(4, 5, 6)
    assert type(iterTup) is Tup
Пример #19
0
def test_from_iter_unknown():
    with pytest.raises(NotImplementedError):
        s.from_iter(object(), [1, 2, 3])
Пример #20
0
def test_from_iter_str():
    assert s.from_iter(u'', ['1', '2', '3']) == u'123'