예제 #1
0
def run_exec_test(testname):
    '''Runs a python test, which executes code directly rather than queries'''
    print "Running python test: \033[35;1m%s\033[0m" % testname

    glob = rels.copy()
    exp_result = {}

    try:

        expr = readfile('%s%s.exec' % (tests_path, testname))
        exec(expr, glob)  #Evaluating the expression

        expr = readfile('%s%s.exec' % (tests_path, testname))
        exec(expr, glob)  #Evaluating the expression

        expr = readfile('%s%s.result' % (tests_path, testname))
        exp_result = eval(expr, rels)  #Evaluating the expression

        if isinstance(exp_result, dict):
            fields_ok = True

            for i in exp_result:
                fields_ok = fields_ok and glob[i] == exp_result[i]

            if fields_ok:
                print colored('Test passed', 'green')
                return True
    except:
        pass
    print colored('ERROR', 'red')
    print colored('=====================================', 'red')
    print "Expected %s" % exp_result
    #print "Got %s" % result
    print colored('=====================================', 'red')
    return False
예제 #2
0
def run_test(testname):
    '''Runs a specific test executing the file
    testname.query
    and comparing the result with 
    testname.result
    The query will be executed both unoptimized and
    optimized'''
    print "Running test: " + colored(testname, 'magenta')

    query = None
    expr = None
    o_query = None
    o_expr = None
    result_rel = None
    result = None
    o_result = None

    try:
        result_rel = relation.relation('%s%s.result' % (tests_path, testname))

        query = readfile('%s%s.query' % (tests_path, testname)).strip()
        query = unicode(query, 'utf-8')

        expr = parser.parse(query)  #Converting expression to python code

        o_query = optimizer.optimize_all(query, rels)

        result = eval(expr, rels)  #Evaluating the expression

        o_expr = parser.parse(o_query)  #Converting expression to python code
        o_result = eval(o_expr, rels)  #Evaluating the expression

        if (o_result == result_rel) and (result == result_rel):
            print colored('Test passed', 'green')
            return True
    except Exception as inst:
        print inst, "------"
        pass
    print colored('ERROR', 'red')
    print "Query: %s -> %s" % (query, expr)
    print "Optimized query: %s -> %s" % (o_query, o_expr)
    print colored('=====================================', 'red')
    print "\033[33;1mExpected result\033[0m"
    print result_rel
    print "\033[33;1mResult\033[0m"
    print result
    print "\033[33;1mOptimized result\033[0m"
    print o_result
    print "\033[33;1moptimized result match\033[0m", result_rel == o_result
    print "\033[33;1mresult match          \033[0m", result == result_rel
    print colored('=====================================', 'red')
    return False
예제 #3
0
def run_py_test(testname):
    '''Runs a python test, which evaluates expressions directly rather than queries'''
    print "Running expression python test: " + colored(testname, 'magenta')

    try:

        expr = readfile('%s%s.python' % (tests_path, testname))
        result = eval(expr, rels)  #Evaluating the expression

        expr = readfile('%s%s.result' % (tests_path, testname))
        exp_result = eval(expr, rels)  #Evaluating the expression

        if result == exp_result:
            print colored('Test passed', 'green')
            return True
    except:
        pass

    print colored('ERROR', 'red')
    print colored('=====================================', 'red')
    print "Expected %s" % exp_result
    print "Got %s" % result
    print colored('=====================================', 'red')
    return False