Exemplo n.º 1
0
def test_fromiter_custom_class():
    class C:
        def __init__(self, attr):
            self.attr = attr

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

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

    assert s.fromiter(C(1), [2]) == C(2)
Exemplo n.º 2
0
def test_fromiter_str():
    assert s.fromiter('', ['1', '2', '3']) == '123'
Exemplo n.º 3
0
def test_fromiter_set():
    assert s.fromiter(set(), [1, 2, 3]) == {1, 2, 3}
Exemplo n.º 4
0
def test_fromiter_list():
    assert s.fromiter([], (1, 2, 3)) == [1, 2, 3]
Exemplo n.º 5
0
def test_fromiter_bytes():
    assert s.fromiter(b'', [49, 50, 51]) == b'123'
Exemplo n.º 6
0
def test_fromiter_unknown():
    with pytest.raises(NotImplementedError):
        s.fromiter(object(), [1, 2, 3])
Exemplo n.º 7
0
def test_fromiter_dict():
    data = {'jane': 5, 'jim': 6, 'joanne': 8}
    new_keys = [k.capitalize() for k in data]
    assert s.fromiter(data, new_keys) == {'Jane': 5, 'Jim': 6, 'Joanne': 8}
Exemplo n.º 8
0
def test_fromiter_tuple():
    assert s.fromiter((), [1, 2, 3]) == (1, 2, 3)