コード例 #1
0
def run_tests():
    global FILE_ERRORS
    total_errors = 0

    for test_file in find_all_test_scripts():
        module = importlib.import_module(test_file, "mobaas.tests")

        names_funcs = inspect.getmembers(module, inspect.isfunction)

        if "ORDER" in dict(inspect.getmembers(module)):
            order = module.ORDER
            names_funcs_dict = dict(names_funcs)

            for func_name in order:
                if func_name in names_funcs_dict:
                    run_test(func_name, names_funcs_dict[func_name])
                    del names_funcs_dict[func_name]

            names_funcs = names_funcs_dict.items()

        for name_func, func in names_funcs:
            if name_func.startswith("test_"):
                run_test(name_func, func)

        end_file_message(test_file, FILE_ERRORS)
        total_errors += FILE_ERRORS
        FILE_ERRORS = 0

    err.log_error_test(
        err.INFO, "[Test][Total] Ended testing with in total " +
        str(total_errors) + " errors")
コード例 #2
0
def run_tests():
    global FILE_ERRORS
    total_errors = 0

    for test_file in find_all_test_scripts():
        module = importlib.import_module(test_file, "mobaas.tests")

        names_funcs = inspect.getmembers(module, inspect.isfunction)

        if "ORDER" in dict(inspect.getmembers(module)):
            order = module.ORDER
            names_funcs_dict = dict(names_funcs)

            for func_name in order:
                if func_name in names_funcs_dict:
                    run_test(func_name, names_funcs_dict[func_name])
                    del names_funcs_dict[func_name]

            names_funcs = names_funcs_dict.items()

        for name_func, func in names_funcs:
            if name_func.startswith("test_"):
                run_test(name_func, func)

        end_file_message(test_file, FILE_ERRORS)
        total_errors += FILE_ERRORS
        FILE_ERRORS = 0

    err.log_error_test(err.INFO, "[Test][Total] Ended testing with in total " + str(total_errors) + " errors")
コード例 #3
0
def compare_answer(result, should_be, test_str):

    r = True
    if not result == should_be:
        err.log_error_test(err.CRITICAL, "[Test][Fault] {" + test_str + "} Expected: " + str(should_be) + " but found: " + str(result) + " in test " + config.CURRENT_TEST)
        r = False
        config.TEST_ERRORS += 1

    return r
コード例 #4
0
def compare_answer(result, should_be, test_str):

    r = True
    if not result == should_be:
        err.log_error_test(
            err.CRITICAL,
            "[Test][Fault] {" + test_str + "} Expected: " + str(should_be) +
            " but found: " + str(result) + " in test " + config.CURRENT_TEST)
        r = False
        config.TEST_ERRORS += 1

    return r
コード例 #5
0
def run_test(name_func, func):
    global FILE_ERRORS
    config.CURRENT_TEST = name_func
    try:
        func()
    except Exception as e:
        err.log_error_test(err.CRITICAL, "[Test][Fault] {" + config.CURRENT_TEST + "} caused an exception: " + e.message)
        config.TEST_ERRORS += 1
        print traceback.format_exc()

    err.log_error_test(err.INFO, "[Test] {" + config.CURRENT_TEST + "} has completed with " + str(config.TEST_ERRORS) + " errors")
    FILE_ERRORS += config.TEST_ERRORS
    config.TEST_ERRORS = 0
コード例 #6
0
def run_test(name_func, func):
    global FILE_ERRORS
    config.CURRENT_TEST = name_func
    try:
        func()
    except Exception as e:
        err.log_error_test(
            err.CRITICAL, "[Test][Fault] {" + config.CURRENT_TEST +
            "} caused an exception: " + e.message)
        config.TEST_ERRORS += 1
        print traceback.format_exc()

    err.log_error_test(
        err.INFO, "[Test] {" + config.CURRENT_TEST + "} has completed with " +
        str(config.TEST_ERRORS) + " errors")
    FILE_ERRORS += config.TEST_ERRORS
    config.TEST_ERRORS = 0
コード例 #7
0
def end_file_message(current_file, file_errors):
    err.log_error_test(
        err.INFO, "[Test][File] Ended tests in file " + current_file +
        " with " + str(file_errors) + " errors")
コード例 #8
0
def end_file_message(current_file, file_errors):
    err.log_error_test(err.INFO, "[Test][File] Ended tests in file " + current_file + " with " + str(file_errors) + " errors")