summaryrefslogtreecommitdiffstats
path: root/test/lib/ansible_test/_internal/commands/coverage/erase.py
blob: 70b685c535222a8de594fa3597197a54cb3e8444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Erase code coverage files."""
from __future__ import annotations

import os

from ...util_common import (
    ResultType,
)

from ...executor import (
    Delegate,
)

from ...provisioning import (
    prepare_profiles,
)

from . import (
    CoverageConfig,
)


def command_coverage_erase(args: CoverageEraseConfig) -> None:
    """Erase code coverage data files collected during test runs."""
    host_state = prepare_profiles(args)  # coverage erase

    if args.delegate:
        raise Delegate(host_state=host_state)

    coverage_dir = ResultType.COVERAGE.path

    for name in os.listdir(coverage_dir):
        if not name.startswith('coverage') and '=coverage.' not in name:
            continue

        path = os.path.join(coverage_dir, name)

        if not args.explain:
            os.remove(path)


class CoverageEraseConfig(CoverageConfig):
    """Configuration for the coverage erase command."""