Ejemplo n.º 1
0
def get_categories_check_set(old_path: str, new_path: str,
                             categories_path: str) -> check.CompareCheckSet:
    """
    Returns a categories check set, that checks a difference in a number of
    objects of categories(from categories.txt) between old mwms and new mwms.
    """
    cs = check.CompareCheckSet("Categories check")

    def make_do(indexes):
        def do(path):
            all_types = count_all_types(path)
            return sum(all_types[i] for i in indexes)

        return do

    for category, types in parse_groups(categories_path).items():
        cs.add_check(
            check.build_check_set_for_files(
                f"Category {category} check",
                old_path,
                new_path,
                ext=".mwm",
                do=make_do(types),
            ))
    return cs
Ejemplo n.º 2
0
def get_log_levels_check_set(old_path: str, new_path: str) -> check.CompareCheckSet:
    """
    Returns a log levels check set, that checks a difference in a number of
    message levels from warning and higher for each stage between old mwms
    and new mwms.
    """
    cs = check.CompareCheckSet("Log levels check")

    def make_do(level, stage_name, cache={}):
        def do(path):
            for s in _get_log_stages(path):
                if s.name == stage_name:
                    k = f"{path}:{stage_name}"
                    if k not in cache:
                        cache[k] = logs_reader.count_levels(s)

                    return cache[k][level]
            return None

        return do

    for stage_name in (
        stages.get_visible_stages_names() + stages.get_invisible_stages_names()
    ):
        for level in (logging.CRITICAL, logging.ERROR, logging.WARNING):
            cs.add_check(
                check.build_check_set_for_files(
                    f"Stage {stage_name} - {logging.getLevelName(level)} check",
                    old_path,
                    new_path,
                    ext=".log",
                    do=make_do(level, stage_name),
                )
            )
    return cs
Ejemplo n.º 3
0
def get_sections_size_check_set(old_path: str,
                                new_path: str) -> check.CompareCheckSet:
    """
    Returns a sections size check set, that checks a difference in a size
    of each sections of mwm between old mwms and new mwms.
    """
    sections_set = _get_sections_set(old_path)
    sections_set.update(_get_sections_set(new_path))

    cs = check.CompareCheckSet("Sections size check")

    def make_do(section):
        def do(path):
            sections = read_sections(path)
            if section not in sections:
                return None

            return sections[section].size

        return do

    for section in sections_set:
        cs.add_check(
            check.build_check_set_for_files(
                f"Size of {section} check",
                old_path,
                new_path,
                ext=".mwm",
                do=make_do(section),
            ))
    return cs
Ejemplo n.º 4
0
def get_appeared_sections_check_set(old_path: str,
                                    new_path: str) -> check.CompareCheckSet:
    return check.build_check_set_for_files(
        f"Appeared sections check",
        old_path,
        new_path,
        ext=".mwm",
        do=lambda path: SectionNames(read_sections(path)),
        diff_format=lambda s: ", ".join(f"{k}:{v.size}"
                                        for k, v in s.sections.items()),
        format=lambda s: f"number of sections: {len(s.sections)}",
    )
Ejemplo n.º 5
0
def get_size_check_set(old_path: str, new_path: str) -> check.CompareCheckSet:
    """
    Returns a size check set, that checks a difference in a size of mwm between
    old mwms and new mwms.
    """
    return check.build_check_set_for_files(
        "Size check",
        old_path,
        new_path,
        ext=".mwm",
        do=lambda path: os.path.getsize(path),
    )
Ejemplo n.º 6
0
def get_mwm_type_check_set(old_path: str, new_path: str,
                           type_: Union[str, int]) -> check.CompareCheckSet:
    """
    Returns a  mwm type check set, that checks a difference in a number of
    type [type_] between old mwms and new mwms.
    """
    if isinstance(type_, str):
        type_ = type_index(type_)
    assert type_ >= 0, type_

    return check.build_check_set_for_files(
        f"Types check [{readable_type(type_)}]",
        old_path,
        new_path,
        ext=".mwm",
        do=lambda path: count_all_types(path)[type_],
    )
Ejemplo n.º 7
0
def get_addresses_check_set(old_path: str, new_path: str) -> check.CompareCheckSet:
    """
    Returns an addresses check set, that checks a difference in 'matched_percent'
    addresses of BuildAddressTable between old logs and new logs.
    """
    def do(path: str):
        log = logs_reader.Log(path)
        if not log.is_mwm_log:
            return None

        found = logs_reader.find_and_parse(log.lines, ADDR_PATTERN)
        if not found:
            return None

        d = found[0][0]
        return float(d["matched_percent"])

    return check.build_check_set_for_files(
        "Addresses check", old_path, new_path, ext=".log", do=do
    )
Ejemplo n.º 8
0
def get_mwm_types_check_set(old_path: str,
                            new_path: str) -> check.CompareCheckSet:
    """
    Returns a mwm types check set, that checks a difference in a number of
    each type between old mwms and new mwms.
    """
    cs = check.CompareCheckSet("Mwm types check")

    def make_do(index):
        return lambda path: count_all_types(path)[index]

    for t_name, t_index in NAME_TO_INDEX_TYPE_MAPPING.items():
        cs.add_check(
            check.build_check_set_for_files(
                f"Type {t_name} check",
                old_path,
                new_path,
                ext=".mwm",
                do=make_do(t_index),
            ))
    return cs