示例#1
0
    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
示例#2
0
    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])
示例#3
0
    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
示例#4
0
 def test_typecheck(self):
     """ Collections must contain wrappers """
     with pytest.raises(TypeError):
         Collection([1])
示例#5
0
    def test_list(self):

        items = list(map(Scalar, [1, 2]))
        assert list(Collection(items)) == items
示例#6
0
    def test_repr_unicode(self):

        s = Collection([Soupy('<html>∂ƒ</html>')])
        print(s)
        print(repr(s))
        print(text_type(s))
示例#7
0
    def test_count(self):

        assert Collection([]).count().val() == 0
        assert Collection([Scalar(1)]).count().val() == 1
        assert NullCollection().count().val() == 0
示例#8
0
    def test_bool(self):

        assert Collection([Scalar(1)])
        assert not Collection([])
示例#9
0
 def test_index_oob(self):
     assert isinstance(Collection([])[5], NullNode)
示例#10
0
 def test_get_single_on_iterator(self):
     c = Collection((Scalar(i) for i in range(5)))
     assert c[2].val() == 2
示例#11
0
 def test_slice_on_iterator(self):
     c = Collection((Scalar(i) for i in range(5)))
     assert c[::2].val() == [0, 2, 4]