Ejemplo n.º 1
0
 def test_invalid_ast(self):
     p = Predicate("server matches '(unbal'")
     assert not p.is_valid()
     errs = p.errors()
     assert 'Compilation failed for' in errs["errors"][0]
     assert 'unbalanced parenthesis' == errs["regex"]["(unbal"] or\
            errs["regex"]["(unbal"].startswith("missing ), unterminated subpattern")
Ejemplo n.º 2
0
 def test_invalid_ast(self):
     p = Predicate("server matches '(unbal'")
     assert not p.is_valid()
     errs = p.errors()
     assert 'Compilation failed for' in errs["errors"][0]
     assert 'unbalanced parenthesis' == errs["regex"]["(unbal"] or\
            errs["regex"]["(unbal"].startswith("missing ), unterminated subpattern")
Ejemplo n.º 3
0
 def test_error(self):
     p = Predicate("foo is\nbar !! fun")
     assert not p.is_valid()
     assert p.errors()['errors'] == [
         'Failed to parse characters !! at line 2, col 5',
         'Syntax error with fun at line 2, col 8',
     ]
Ejemplo n.º 4
0
 def test_error(self):
     p = Predicate("foo is\nbar !! fun")
     assert not p.is_valid()
     assert p.errors()['errors'] == [
         'Failed to parse characters !! at line 2, col 5',
         'Syntax error with fun at line 2, col 8',
     ]
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def main():
    import sys
    if len(sys.argv) == 2:
        p = Predicate(sys.argv[1])
        if not p.is_valid():
            for error in p.errors()['errors']:
                print(error)
            return
    else:
        p = None
    rows = []
    for id, size, date, sender, msg, dest in mailq():

        colsObject = {
            "cols": [{
                "value": id
            }, {
                "value": size
            }, {
                "value": date
            }, {
                "value": sender
            }, {
                "value": dest
            }]
        }
        rows.append(colsObject)

    #doc = list(id, size, date, sender, msg, dest)

    if p == None or p.evaluate(doc):
        rowsObject = {"rows": rows}
        hrowsColsObject = {
            "cols": [{
                "value": "ID"
            }, {
                "value": "Size"
            }, {
                "value": "Date"
            }, {
                "value": "Sender"
            }, {
                "value": "Recipient"
            }]
        }

        hrowsColsArray = []
        hrowsColsArray.append(hrowsColsObject)

        hrowsObject = {"hrows": hrowsColsArray}

        returnString = json.dumps(hrowsObject)[1:-1] + ", " + json.dumps(
            rowsObject)[1:-1]

        print(returnString)
Ejemplo n.º 8
0
 def test_invalid_parse(self):
     p = Predicate("true true")
     assert not p.is_valid()
     assert 'Syntax error with true' in p.errors()["errors"][0]
Ejemplo n.º 9
0
 def test_invalid_token(self):
     p = Predicate("name is !! and true")
     assert not p.is_valid()
     assert 'Failed to parse characters !!' in p.errors()["errors"][0]
Ejemplo n.º 10
0
 def test_invalid_end(self):
     p = Predicate("name is 'Jack' and ")
     assert not p.is_valid()
     assert 'Unexpected end of predicate!' in p.errors()["errors"]
Ejemplo n.º 11
0
 def test_invalid_ast(self):
     p = Predicate("server matches '(unbal'")
     assert not p.is_valid()
     errs = p.errors()
     assert "Compilation failed for" in errs["errors"][0]
     assert "unbalanced parenthesis" == errs["regex"]["(unbal"]
Ejemplo n.º 12
0
 def test_invalid_parse(self):
     p = Predicate("true true")
     assert not p.is_valid()
     assert "Syntax error with true" in p.errors()["errors"][0]
Ejemplo n.º 13
0
 def test_invalid_token(self):
     p = Predicate("name is !! and true")
     assert not p.is_valid()
     assert "Failed to parse characters !!" in p.errors()["errors"][0]
Ejemplo n.º 14
0
 def test_invalid_end(self):
     p = Predicate("name is 'Jack' and ")
     assert not p.is_valid()
     assert "Unexpected end of predicate!" in p.errors()["errors"]
Ejemplo n.º 15
0
 def test_invalid_ast(self):
     p = Predicate("server matches '(unbal'")
     assert not p.is_valid()
     errs = p.errors()
     assert 'Compilation failed for' in errs["errors"][0]
     assert 'unbalanced parenthesis' == errs["regex"]["(unbal"]