示例#1
0
    def test_require(self):

        s = Scalar(3)
        assert s.require(Q > 1) is s

        with pytest.raises(NullValueError):
            s.require(Q > 4)
示例#2
0
    def test_require(self):

        s = Scalar(3)
        assert s.require(Q > 1) is s

        with pytest.raises(NullValueError):
            s.require(Q > 4)
示例#3
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
示例#4
0
    def test_repr_unicode(self):

        s = Scalar('∂ƒ')
        print(s)
        print(repr(s))
        print(text_type(s))
        assert repr(s)[0] != "'"

        s = Scalar('∂ƒ'.encode('utf-8'))
        print(s)
        print(repr(s))
        print(text_type(s))

        s = Scalar(b'\xc2')
        print(s)
        print(repr(s))
        print(text_type(s))
示例#5
0
    def test_arithmetic_with_null(self):
        l, r = Scalar(1), Null()

        assert isinstance(l + r, Null)
        assert isinstance(l - r, Null)
        assert isinstance(l * r, Null)
        assert isinstance(l / r, Null)
        assert isinstance(l // r, Null)
        assert isinstance(l**r, Null)
        assert isinstance(l % r, Null)
        if not PY3:
            assert isinstance(operator.div(l, r), Null)
示例#6
0
    def test_arithmetic(self):

        c = Scalar(1)
        assert (c + 1).val() == 2
        assert (c - 1).val() == 0
        assert (c * 2).val() == 2
        assert (c / 1).val() == 1
        assert operator.truediv(c, 2).val() == 0.5

        if not PY3:
            assert operator.div(c, 2).val() == 0.5

        assert (c // 1).val() == 1
        assert (c**2).val() == 1
        assert (c % 2).val() == 1

        assert (c + c).val() == 2
示例#7
0
    def test_bool(self):

        assert Collection([Scalar(1)])
        assert not Collection([])
示例#8
0
 def test_get_single_on_iterator(self):
     c = Collection((Scalar(i) for i in range(5)))
     assert c[2].val() == 2
示例#9
0
 def test_slice_on_iterator(self):
     c = Collection((Scalar(i) for i in range(5)))
     assert c[::2].val() == [0, 2, 4]
示例#10
0
 def test_apply(self):
     assert Scalar(3).apply(lambda x: x.val() * 2).val() == 6
     assert isinstance(Null().apply(lambda x: x), Null)
示例#11
0
 def test_wrap(self):
     v = Scalar(3)
     assert isinstance(Wrapper.wrap(3), Scalar)
     assert Wrapper.wrap(v) is v
     assert isinstance(Wrapper.wrap(BeautifulSoup('a')), Node)
示例#12
0
 def test_hash(self):
     """
     wrappers are hashed by their content
     """
     assert hash(Scalar(2)) == hash(Scalar(2))
     assert hash(Some(2)) == hash(Some(2))
示例#13
0
 def test_len(self):
     assert len(Scalar([1, 2, 3])) == 3
示例#14
0
 def test_lt(self):
     assert (Scalar(3) < 4).val()
示例#15
0
 def test_ne(self):
     assert (Scalar('test') != 'foo').val()
示例#16
0
 def test_gt(self):
     assert (Scalar(3) > 2).val()
示例#17
0
 def test_isnull(self):
     assert not Scalar(1).isnull()
示例#18
0
 def test_getkey(self):
     assert Scalar({'a': 1})['a'].val() == 1
示例#19
0
 def test_slice(self):
     assert Scalar('test')[1:-1].val() == 'es'
示例#20
0
    def test_count(self):

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

        s = Scalar({'a': 1})
        s['b'] = 2
        assert s.val() == {'a': 1, 'b': 2}
示例#22
0
 def test_ge(self):
     assert (Scalar(3) >= 2).val()
示例#23
0
 def test_le(self):
     assert (Scalar(3) <= 3).val()
示例#24
0
    def test_setitem(self):

        s = Scalar({'a': 1})
        s['b'] = 2
        assert s.val() == {'a': 1, 'b': 2}
示例#25
0
 def test_eq(self):
     assert (Scalar('test') == 'test').val()