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)
def test_fromiter_str(): assert s.fromiter('', ['1', '2', '3']) == '123'
def test_fromiter_set(): assert s.fromiter(set(), [1, 2, 3]) == {1, 2, 3}
def test_fromiter_list(): assert s.fromiter([], (1, 2, 3)) == [1, 2, 3]
def test_fromiter_bytes(): assert s.fromiter(b'', [49, 50, 51]) == b'123'
def test_fromiter_unknown(): with pytest.raises(NotImplementedError): s.fromiter(object(), [1, 2, 3])
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}
def test_fromiter_tuple(): assert s.fromiter((), [1, 2, 3]) == (1, 2, 3)