File: check-build-log

package info (click to toggle)
python-qtpy 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 924 kB
  • sloc: python: 4,767; sh: 28; makefile: 19
file content (207 lines) | stat: -rwxr-xr-x 6,163 bytes parent folder | download
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/python3
# Copyright (c) 2024- Stuart Prescott <stuart@debian.org>
# Released under the same terms as QtPy
"""
Check the build or autopkgtest log to find tests that were skipped that
should not be skipped.

Usage:
    ./debian/test-log-check ../python-qtpy_*.build
"""

from __future__ import annotations

from collections import defaultdict
from dataclasses import dataclass, field
from enum import Enum
import re
import shutil
import sys
from typing import Generator

# pylint: disable=invalid-name,missing-function-docstring


@dataclass
class Ignorables:
    """Class to track ignorable regexes in the test log"""

    ignores: list[str | re.Pattern[str]] = field(default_factory=list)

    def patterns(self) -> Generator[re.Pattern[str], None, None]:
        for pattern in self.ignores:
            if isinstance(pattern, str):
                yield re.compile(pattern)
            else:
                yield pattern


@dataclass
class PyTestMessage:
    """Class to record test errors/skips"""

    interpreter: str
    qt: str
    line: int
    entry: str


class LogState(Enum):
    """State of the log parser"""

    waiting_for_session_start = 0
    waiting_for_interpreter = 1
    waiting_for_session_info = 2
    waiting_for_session_summary = 3
    waiting_for_session_end = 4

    def __next__(self) -> LogState:
        return LogState((self.value + 1) % len(LogState))


session_start_re = re.compile(r"=+ test session starts =+")
session_interpreter_re = re.compile(r"platform linux -- Python ([\d.]+),")
session_info_re = re.compile(r"((pyside|pyqt)\d) ", re.I)
session_summary_re = re.compile(r"=+ short test summary info =+")
error_line_re = re.compile(r"(SKIPPED|ERROR|FAIL)")
session_end_re = re.compile(
    r"=+ (.*\d+ failed.*, )?.* passed.*, .*\d+ skipped.* in .* =+"
)


ignorables = defaultdict(Ignorables)

ignorables["PyQt5"] = Ignorables(
    [
        # Tests not for this QT_API
        "Requires PySide2",
        "Requires PyQt6",
        "Requires PySide6",
        "It is not currently implemented in PyQt5",
        "Doesn't seem to be present on PyQt5",
        "Only available by default in PySide",
        "PySide.*specific test",
        "Not available in PySide2/PyQt5",
        "Only available in Qt6 bindings",
        # Tests not for this platform
        "qtmacextras.py",
        "pip on Windows",
        # Tests needing unavailable components
        "It must be installed separately",
        "No module named 'PyQt5.QtQuick3D'",  # seems to be missing in Debian?
    ]
)

ignorables["PyQt6"] = Ignorables(
    [
        # Tests not for this QT_API
        "Requires PyQt5",
        "Requires PySide6",
        "Requires PySide2",
        "Targeted to PyQt5",
        "Not complete in PyQt6",
        "It is not currently implemented in PyQt6",
        "Doesn't seem to be present on .*PyQt6",
        "Only available by default in PySide",
        "PySide.*specific test",
        "does not exist in Qt6",
        "Only available in Qt5 bindings",
        "not available with qt 6.0",
        # Tests needing unavailable components
        "It must be installed separately",
    ]
)


ignorables["PySide6"] = Ignorables(
    [
        # Tests not for this QT_API
        "Requires PyQt5",
        "Requires PyQt6",
        "Requires PySide2",
        "Targeted to PyQt5",
        "Not complete in PySide6",
        "It is not currently implemented in PySide6",
        "not available under PySide 2/6",
        "does not exist in Qt6",
        "Only available in Qt5 bindings",
        "not available with qt 6.0",
        # Tests needing unavailable components
        "It must be installed separately",
        "No module named 'PySide6.QtAxContainer'",  # seems to be missing in Debian?
    ]
)


def process_log(filename: str) -> list[PyTestMessage]:
    """Process the log file to find the test output"""

    with open(filename, encoding="UTF-8") as logfh:
        status = LogState.waiting_for_session_start
        interpreter = ""
        qt = ""
        messages = []

        for lineno, line in enumerate(logfh.readlines()):
            if status is LogState.waiting_for_session_start:
                if session_start_re.search(line):
                    status = next(status)
                continue
            if status is LogState.waiting_for_interpreter:
                if m := session_interpreter_re.search(line):
                    interpreter = m.group(1)
                    status = next(status)
                continue
            if status is LogState.waiting_for_session_info:
                if m := session_info_re.search(line):
                    qt = m.group(1)
                    status = next(status)
                continue
            if status is LogState.waiting_for_session_summary:
                if m := session_summary_re.search(line):
                    status = next(status)
                continue
            if status is LogState.waiting_for_session_end:
                if m := error_line_re.search(line):
                    messages.append(
                        PyTestMessage(interpreter, qt, lineno, line)
                    )
                if session_end_re.search(line):
                    status = next(status)
                continue

    return messages


def print_report(messages: list[PyTestMessage]) -> None:
    """Report the log lines that were identified"""

    interpreter = ""
    qt = ""
    width, _ = shutil.get_terminal_size(fallback=(50, 1))

    for rep in messages:
        if interpreter != rep.interpreter or qt != rep.qt:
            interpreter = rep.interpreter
            qt = rep.qt
            header = f" {interpreter} {qt} "
            print(f"\n\n{header:=^{width}}")

        skip = False
        for p in ignorables[rep.qt].patterns():
            if p.search(rep.entry):
                skip = True
                break
        if not skip:
            print(rep.entry, end="")


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: test-log-check foo.build")
        sys.exit(1)

    logfile = sys.argv[1]

    reports = process_log(logfile)
    print_report(reports)