Esempio n. 1
0
    def test_special_case_op(self):
        query = q.Query(self.toc)
        query.clear()
        query.pushDict({'foo': [q.In([27, 42]), q.Empty()]})
        mongo = query.mongo()

        # xxx Empty overrides In
        assert mongo == {'_bases': {'$in': [self.toc._fullname]},
                         'foo': {'$in': [None, [], {}]}}
Esempio n. 2
0
def test_OperatorTypeEnforcement():
    "Test that attributes verify operator types"

    class myToc(TO):
        class myAttr(Bool()):
            pass

    y = q.Query(myToc, myAttr=q.Empty())

    def spam():
        y = q.Query(myToc, myAttr=q.Greater(23))

    py.test.raises(TypeError, spam)
Esempio n. 3
0
    def test_Empty(self):
        from blm import fundamental, testblm
        toi = blm.testblm.Test()
        self.commit()

        assert blm.testblm.Test._query(attr1=q.Empty()).run()
        assert blm.testblm.Test._query(attr3=q.Empty()).run()
        assert blm.testblm.Test._query(attr4=q.Empty()).run()
        assert blm.testblm.Test._query(attr5=q.Empty()).run()

        toi, = blm.testblm.Test._query().run()
        toi(attr1=['foo'], attr3={'foo': 'bar'}, attr4=[toi], attr5={'foo': toi})
        self.commit()

        assert not blm.testblm.Test._query(attr1=q.Empty()).run()
        assert not blm.testblm.Test._query(attr3=q.Empty()).run()
        assert not blm.testblm.Test._query(attr4=q.Empty()).run()
        assert not blm.testblm.Test._query(attr5=q.Empty()).run()

        toi, = blm.testblm.Test._query().run()
        toi(attr1=[], attr3={}, attr4=[], attr5={})
        self.commit()

        assert blm.testblm.Test._query(attr1=q.Empty()).run()
        assert blm.testblm.Test._query(attr3=q.Empty()).run()
        assert blm.testblm.Test._query(attr4=q.Empty()).run()
        assert blm.testblm.Test._query(attr5=q.Empty()).run()
Esempio n. 4
0
 def test_Empty(self):
     op = q.Empty()
     mongo = op.mongo()
     assert mongo == {'$empty': True}
Esempio n. 5
0
def test_Empty():
    "Test Empty operator"
    
    assert q.Empty().matches([])
    assert not q.Empty().matches([1, 2])