File: testsuite.py

package info (click to toggle)
libtemplates-parser 25.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,404 kB
  • sloc: ada: 12,020; python: 658; makefile: 351; sh: 37
file content (111 lines) | stat: -rwxr-xr-x 2,776 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
"""./testsuite.py [options] [test name]

Run the template-parser testsuite.
"""

from glob import glob
import os
import sys
import time

from e3.env import Env
from e3.os.process import Run
from e3.fs import mkdir, rm
from e3.sys import interpreter

import e3.testsuite
from e3.testsuite import Testsuite
from e3.testsuite.driver.diff import DiffTestDriver
from e3.testsuite.result import Log, TestResult, TestStatus
from e3.testsuite.testcase_finder import ParsedTest, YAMLTestFinder, TestFinder


class BasicTestDriver(DiffTestDriver):
    """Simple test driver that runs a python script inside the TP tests."""

    def run(self):
        """Run the template parser test.

        Executes the test.py command inside the tests and compares the results.
        """
        cmd = [interpreter(), "test.py"]
        start_time = time.time()
        run = self.shell(
            cmd,
            cwd=self.test_env["working_dir"],
            catch_error=False,
            timeout=None,
        )
        self.result.time = time.time() - start_time


class TPTestsuite(Testsuite):
    """Testsuite for Template Parser."""

    test_driver_map = {"basic": BasicTestDriver}
    default_driver = "basic"

    tests_subdir = "tests"

    def __init__(self):
        super().__init__()
        target = os.environ.get("TARGET")
        prj_build = os.environ.get("PRJ_BUILD")

        if target is None:
            target = Run(["gcc", "-dumpmachine"]).out.strip("\n")
        else:
            target = target.lower()

        if prj_build is None:
            prj_build = "debug"
        else:
            prj_build = prj_build.lower()

        def makedir(dir):
            return (
                os.getcwd()
                + "/../.build/"
                + dir
                + "/"
                + target
                + "/"
                + prj_build
                + "/static/"
            )

        env = Env()
        env.add_search_path("PYTHONPATH", os.getcwd())
        env.add_search_path(
            "PATH",
            os.environ.get("PATH")
            + os.pathsep
            + makedir("bin")
            + os.pathsep
            + makedir("rbin"),
        )

    @property
    def test_finders(self):
        return [YAMLTestFinder()]

    def add_options(self, parser):
        parser.add_argument(
            "--diffs",
            dest="view_diffs",
            action="store_true",
            default=False,
            help="Print .diff content",
        )
        parser.add_argument(
            "--old-result-dir",
            dest="old_result_dir",
            type=str,
            default=None,
            help="Old result dir",
        )


if __name__ == "__main__":
    sys.exit(TPTestsuite().testsuite_main())