Пример #1
0
 def test_jack_and_jill(self):
     p = Predicate("name is 'Jack'\r\nand friend is 'Jill'")
     assert p.is_valid()
     assert p.evaluate({"name": "Jack", "friend": "Jill"})
     res, ctx = p.analyze({"name": "Jack", "friend": "Jill"})
     assert res
     assert p.description() == """AND operator at line: 2, col 1
Пример #2
0
def test_samples():
    p = os.path.dirname(os.path.abspath(__file__))
    fh = open(os.path.join(p, "preds.txt"))
    for line, pred in enumerate(fh):
        pred = pred.strip()
        obj = Predicate(pred)
        if not obj.is_valid():
            print "Invalid Predicate!"
            print "Line: ", line
            print "Predicate: ", pred
            info = obj.errors()
            print "Errors: ", "\n".join(info["errors"])
            for k, v in info["regex"].iteritems():
                print "\t%s : %s" % (k, repr(v))
            assert False

        res, ctx = obj.analyze(DOC)
        if not pred.endswith("true") and not pred.endswith("false"):
            print "Line: ", line
            print "Unknown result!"
            print "Predicate: ", pred
            assert False

        if (pred.endswith("true") and not res) or (pred.endswith("false") and res):
            print "Line: ", line
            print "Predicate: ", pred
            print "Failures: ", "\n".join(ctx.failed)
            print "Literals: "
            for k, v in ctx.literals.iteritems():
                print "\t%s : %s" % (k, repr(v))
            assert False
Пример #3
0
 def test_jack_and_jill(self):
     p = Predicate("name is 'Jack'\r\nand friend is 'Jill'")
     assert p.is_valid()
     assert p.evaluate({"name": "Jack", "friend": "Jill"})
     res, ctx = p.analyze({"name": "Jack", "friend": "Jill"})
     assert res
     assert p.description() == """AND operator at line: 2, col 1
Пример #4
0
def test_samples():
    p = os.path.dirname(os.path.abspath(__file__))
    fh = open(os.path.join(p, "preds.txt"))
    for line, pred in enumerate(fh):
        pred = pred.strip()
        obj = Predicate(pred)
        if not obj.is_valid():
            print "Invalid Predicate!"
            print "Line: ", line
            print "Predicate: ", pred
            info = obj.errors()
            print "Errors: ", "\n".join(info["errors"])
            for k, v in info["regex"].iteritems():
                print "\t%s : %s" % (k, repr(v))
            assert False

        res, info = obj.analyze(DOC)
        if not pred.endswith("true") and not pred.endswith("false"):
            print "Line: ", line
            print "Unknown result!"
            print "Predicate: ", pred
            assert False

        if (pred.endswith("true") and not res) or (pred.endswith("false") and res):
            print "Line: ", line
            print "Predicate: ", pred
            print "Failures: ", "\n".join(info["failed"])
            print "Literals: "
            for k, v in info["literals"].iteritems():
                print "\t%s : %s" % (k, repr(v))
            assert False
Пример #5
0
    def test_jack_and_jill(self):
        p = Predicate("name is 'Jack' and friend is 'Jill'")
        assert p.is_valid()
        assert p.evaluate({"name": "Jack", "friend": "Jill"})
        res, ctx = p.analyze({"name": "Jack", "friend": "Jill"})
        assert res
        assert (
            p.description()
            == """AND operator at line: 1, col 15
	IS comparison at line: 1, col 5
		Literal name at line: 1, col 0
		Literal 'Jack' at line: 1, col 8
	IS comparison at line: 1, col 26
		Literal friend at line: 1, col 19
		Literal 'Jill' at line: 1, col 29
"""
        )