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)
def test_from_iter_set(): assert s.from_iter(set(), [1, 2, 3]) == {1, 2, 3}
def test_from_iter_list(): assert s.from_iter([], (1, 2, 3)) == [1, 2, 3]
def test_from_iter_bytes(): assert s.from_iter(b'', s.to_iter(b'123')) == b'123'
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}
def test_from_iter_tuple(): assert s.from_iter((), [1, 2, 3]) == (1, 2, 3)
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}
def test_from_iter_bytes(): assert s.from_iter(b"", s.to_iter(b"123")) == b"123"
def test_from_iter_bytes(): assert s.from_iter(b'', [49, 50, 51]) == b'123'
def test_from_iter_unknown(): with pytest.raises(NotImplementedError): s.from_iter(object(), [1, 2, 3])
def test_from_iter_str(): assert s.from_iter(u'', ['1', '2', '3']) == u'123'
def test_from_iter_str(): assert s.from_iter(u"", ["1", "2", "3"]) == u"123"
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