Example #1
0
def load_parse_patterns(parse_config_filepath):
    """
    Loads the parse patterns from the desired file.
    These parse patterns are later used to load in the results file
    The lines of this file should be formated in either of the following ways:
        name;path;regex;[default value]
        name;path;regex
    """
    parse_patterns = OrderedDict()

    for line in load_config_lines(parse_config_filepath):

        components = line.split(";")

        if len(components) == 3 or len(components) == 4:

            name = components[0]
            filepath = components[1]
            regex_str = components[2]

            default_value = None
            if len(components) == 4:
                default_value = components[3]

            if name not in parse_patterns:
                parse_patterns[name] = ParsePattern(name, filepath, regex_str,
                                                    default_value)
            else:
                raise InspectError(
                    "Duplicate parse pattern name '{}'".format(name),
                    parse_config_filepath,
                )

        else:
            raise InspectError("Invalid parse format line: '{}'".format(line),
                               parse_config_filepath)

    return parse_patterns
Example #2
0
def load_pass_requirements(pass_requirements_filepath):
    """
    Load the pass requirements from particular file
    The lines of the pass requiremtents file should follow one of the following format:
        name;Range(min,max)
        name;RangeAbs(min,max,absolute_value)
        name;Equal()
    """
    parse_patterns = OrderedDict()

    for line in load_config_lines(pass_requirements_filepath):
        components = line.split(";")

        if len(components) != 2:
            raise InspectError(
                "Invalid pass requirement format line: '{}'".format(line),
                pass_requirements_filepath,
            )

        metric = components[0]
        expr = components[1]

        if metric in parse_patterns:
            raise InspectError(
                "Duplicate pass requirement for '{}'".format(metric),
                pass_requirements_filepath,
            )

        func, params_str = expr.split("(")
        params_str = params_str.rstrip(")")
        params = []

        if params_str != "":
            params = params_str.split(",")

        if func == "Range":
            if len(params) != 2:
                raise InspectError(
                    "Range() pass requirement function requires two arguments",
                    pass_requirements_filepath,
                )

            parse_patterns[metric] = RangePassRequirement(
                metric, float(params[0]), float(params[1]))
        elif func == "RangeAbs":
            if len(params) != 3:
                raise InspectError(
                    "RangeAbs() pass requirement function requires two arguments",
                    pass_requirements_filepath,
                )

            parse_patterns[metric] = RangeAbsPassRequirement(
                metric, float(params[0]), float(params[1]), float(params[2]))
        elif func == "Equal":
            if len(params) != 0:
                raise InspectError(
                    "Equal() pass requirement function requires no arguments",
                    pass_requirements_filepath,
                )
            parse_patterns[metric] = EqualPassRequirement(metric)
        else:
            raise InspectError(
                "Unexpected pass requirement function '{}' for metric '{}'".
                format(func, metric),
                pass_requirements_filepath,
            )

    return parse_patterns