예제 #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()