def test_dictzip(self): c = Collection([Scalar(1), Scalar(2)]) result = c.dictzip(['a', 'b']) expected = {'a': 1, 'b': 2} assert result.val() == expected lbls = Collection([Scalar('a'), Scalar('b')]) assert c.dictzip(lbls).val() == expected
def test_zip(self): c1 = Collection(map(Scalar, [1, 2, 3])) c2 = c1.each(Q * 2) c3 = c1.zip(c2) assert c3.val() == [(1, 2), (2, 4), (3, 6)] with pytest.raises(ValueError): c1.zip([1, 2])
def test_all(self): c = Collection(map(Scalar, [True, False])) assert c.any().val() assert not c.all().val() assert not c.none().val() c = Collection(map(Scalar, [True, True])) assert c.any().val() assert c.all().val() assert not c.none().val() c = Collection(map(Scalar, [False, False])) assert not c.any().val() assert not c.all().val() assert c.none().val() c = Collection([]) assert not c.any().val() assert c.none().val() assert c.all().val() # this is python's behavior for empty lists
def test_typecheck(self): """ Collections must contain wrappers """ with pytest.raises(TypeError): Collection([1])
def test_list(self): items = list(map(Scalar, [1, 2])) assert list(Collection(items)) == items
def test_repr_unicode(self): s = Collection([Soupy('<html>∂ƒ</html>')]) print(s) print(repr(s)) print(text_type(s))
def test_count(self): assert Collection([]).count().val() == 0 assert Collection([Scalar(1)]).count().val() == 1 assert NullCollection().count().val() == 0
def test_bool(self): assert Collection([Scalar(1)]) assert not Collection([])
def test_index_oob(self): assert isinstance(Collection([])[5], NullNode)
def test_get_single_on_iterator(self): c = Collection((Scalar(i) for i in range(5))) assert c[2].val() == 2
def test_slice_on_iterator(self): c = Collection((Scalar(i) for i in range(5))) assert c[::2].val() == [0, 2, 4]