Exemplo n.º 1
0
def test_set_missing(test, test_directory, test_json_file):
    """
    try to recover from missing values

    :param test test class

    :param test_directory directory with test

    :param test_json_file json file
    """
    real_out = ""
    if test.output is not None:
        output = test_directory + test.output
        output_path = Path(output)
        if not output_path.is_file():
            error_handler.call_error(Errors.MISSING_FILE,
                                     bcolors.bold(output) + " is missing")
        with open(output) as input_file:
            real_out = input_file.read()
    input_data = None
    if test.input is not None:
        input = test_directory + test.input
        input_path = Path(input)
        if not input_path.is_file():
            error_handler.call_error(Errors.MISSING_FILE,
                                     bcolors.bold(input) + " is missing")
        with open(input) as input_file:
            input_data = bytes(input_file.read(), "UTF-8")
    if test.is_not_set():
        error_handler.call_warning(
            bcolors.bold(test_directory) + " is not valid test directory. " +
            bcolors.bold("Skipping test!"))
        score['SKIP'].append(test_directory)
        return None, None, False
    if test.code is None:
        test.code = 0
        error_handler.warning("key " + bcolors.bold("returnCode") + " in " +
                              test_json_file +
                              " is missing. Using default value: " +
                              bcolors.bold(str(test.code)))
    error_handler.call_warning()
    return input_data, real_out, True
Exemplo n.º 2
0
def read_test_file(test, test_file, data):
    """
    read test.json

    :param test test class

    :param test_file json file

    :param data file data
    """

    for key in data.keys():
        if key == 'input':
            if isinstance(data[key], str):
                test.input = data[key]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('input') + " in " + bcolors.bold(test_file) +
                    " has to be string")
        elif key == 'output':
            if isinstance(data[key], str):
                test.output = data[key]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('output') + " in " + bcolors.bold(test_file) +
                    " has to be string")
        elif key == 'comment':
            if isinstance(data[key], str):
                test.comment = data[key]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('comment') + " in " +
                    bcolors.bold(test_file) + " has to be string")
        elif key == 'returnCode':
            if isinstance(data[key], int):
                test.code = data[key]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('returnCode') + " in " +
                    bcolors.bold(test_file) + " has to be int")
        elif key == 'timeout':
            if isinstance(data[key], int) and data[key] > 0:
                test.timeout = data[key]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('timeout') + " in " +
                    bcolors.bold(test_file) + " has to be int bigger than 0")
        elif key == 'args':
            if isinstance(data[key], list):
                test.args = data[key]
            elif isinstance(data[key], str):
                test.args = [data[key]]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('args') + " in " + bcolors.bold(test_file) +
                    " has to be array, string")
        elif key == 'expectedFiles':
            if isinstance(data[key], list):
                test.expected_files = data[key]
            elif isinstance(data[key], str):
                test.expected_files = [data[key]]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('expectedFiles') + " in " +
                    bcolors.bold(test_file) + " has to be array or string")
        elif key == 'outputFiles':
            if isinstance(data[key], list):
                test.output_files = data[key]
            elif isinstance(data[key], str):
                test.output_files = [data[key]]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    bcolors.bold('output_files') + " in " +
                    bcolors.bold(test_file) + " has to be array or string")
        else:
            error_handler.warning("Unknown key \'" + bcolors.note(key) +
                                  "\' in " + test_file)
    if len(test.output_files) != len(test.expected_files):
        error_handler.call_error(
            Errors.FATAL_ERROR,
            "Count of files in " + bcolors.bold('outputFiles') + " and " +
            bcolors.bold('expectedFiles') + " is different")
Exemplo n.º 3
0
def parse_config(ar, config_file, data):
    for key in data.keys():
        if key == 'onlyFailed':
            if isinstance(data[key], bool):
                ar.onlyFailed = data[key]
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "OnlyFailed has to be bool")
        elif key == 'noWarnings':
            if isinstance(data[key], bool):
                ar.no_warnings = data[key]
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "noWarnings has to be bool")
        elif key == 'noDiff':
            if isinstance(data[key], bool):
                ar.no_diff = data[key]
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "noDiff has to be bool")
        elif key == "testsDir":
            if isinstance(data[key], str):
                ar.tests_dir = data[key]
                if ar.tests_dir[-1] != '/':
                    ar.tests_dir += '/'
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "testsDirectory has to be string")
        elif key == "resultDir":
            if isinstance(data[key], str):
                ar.result_dir = data[key]
                if ar.result_dir[-1] != '/':
                    ar.result_dir += '/'
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "resultDirectory has to be string")
        elif key == "timeout":
            if isinstance(data[key], int) and data[key] > 0:
                ar.timeout = data[key]
            else:
                error_handler.call_error(
                    Errors.INVALID_JSON,
                    "timeout has to be int and greater than 0")
        elif key == "exclude":
            if isinstance(data[key], str):
                if data[key] != "":
                    ar.exclude = [data[key]]
            elif isinstance(data[key], list):
                ar.exclude = data[key]
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "exclude has to be string or array")
        elif key == "executable":
            if isinstance(data[key], str):
                ar.executable = data[key]
            else:
                error_handler.call_error(Errors.INVALID_JSON,
                                         "executable has to be string path")
        else:
            error_handler.warning("Unknown key \'" + bcolors.note(key) +
                                  "\' in " + config_file)
Exemplo n.º 4
0
import argstest
import my_test
import json
from bColors import bcolors
from errors import error_handler
from errors import Errors
from shutil import rmtree
from pathlib import Path
from importlib import util
from os import makedirs

spam_spec = util.find_spec("yaml")
found = spam_spec is not None
yaml_support = True
if not found:
    error_handler.warning("yaml module does not exists. Please install " +
                          bcolors.note(bcolors.bold("pyyaml")) + " package for using yaml module")
    yaml_support = False
else:
    import yaml

version = "2.3.0.2"


def lets_test(arguments):
    arguments = argstest.parse_args_test(arguments)
    if not arguments.valid:
        error_handler.call_error(Errors.WRONG_PARAM)
    if arguments.hlp:
        argstest.print_help()
        exit(0)
    elif arguments.version: