File size: 3,245 Bytes
c18772f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# SPDX-FileCopyrightText: © 2026 Tenstorrent AI ULC
# SPDX-License-Identifier: Apache-2.0

"""tests/scripts/check_tt_transformers_junit.py finds the one report for a run and passes
only when a test in it passed.

Host-only: runs the script on hand-written JUnit reports.
"""

import subprocess
import sys
from pathlib import Path

import pytest

REPOSITORY_ROOT = Path(__file__).resolve().parents[3]
CHECK_SCRIPT = REPOSITORY_ROOT / "tests/scripts/check_tt_transformers_junit.py"

PASSED = '<testcase classname="t" name="passed" time="1.0"/>'
SKIPPED = '<testcase classname="t" name="skipped" time="0.0"><skipped message="skip"/></testcase>'
FAILED = '<testcase classname="t" name="failed" time="1.0"><failure message="fail"/></testcase>'
ERROR = '<testcase classname="t" name="error" time="1.0"><error message="error"/></testcase>'


def _write_report(path, *cases):
    path.write_text(
        '<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest">'
        + "".join(cases)
        + "</testsuite></testsuites>",
        encoding="utf-8",
    )


def _check(prefix):
    return subprocess.run([sys.executable, str(CHECK_SCRIPT), str(prefix)], capture_output=True, text=True)


@pytest.mark.parametrize(
    "report_suffix, cases",
    [
        ("_20261008_201748.xml", (PASSED,)),  # renamed by tt-transformers' conftest under CI=true
        (".xml", (PASSED,)),
        ("_20261008_201748.xml", (SKIPPED, PASSED, FAILED)),
    ],
)
def test_report_with_a_passed_test_passes(tmp_path, report_suffix, cases):
    prefix = tmp_path / "tt_transformers_20261008_201741_837538071"
    _write_report(Path(f"{prefix}{report_suffix}"), *cases)

    result = _check(prefix)

    assert result.returncode == 0, result.stderr


@pytest.mark.parametrize(
    "cases",
    [(SKIPPED, SKIPPED), (FAILED,), (ERROR, SKIPPED), ()],
    ids=["all-skipped", "failure-only", "error-and-skipped", "empty"],
)
def test_report_without_a_passed_test_fails(tmp_path, cases):
    prefix = tmp_path / "tt_transformers_20261008_201741_837538071"
    _write_report(Path(f"{prefix}_20261008_201748.xml"), *cases)

    result = _check(prefix)

    assert result.returncode != 0
    assert "No tt-transformers test passed" in result.stderr


def test_missing_report_fails(tmp_path):
    result = _check(tmp_path / "tt_transformers_20261008_201741_837538071")

    assert result.returncode != 0
    assert "found 0" in result.stderr


def test_two_matching_reports_fail(tmp_path):
    prefix = tmp_path / "tt_transformers_20261008_201741_837538071"
    _write_report(Path(f"{prefix}.xml"), PASSED)
    _write_report(Path(f"{prefix}_20261008_201748.xml"), PASSED)

    result = _check(prefix)

    assert result.returncode != 0
    assert "found 2" in result.stderr


def test_reports_of_other_runs_are_ignored(tmp_path):
    prefix = tmp_path / "tt_transformers_20261008_201741_837538071"
    _write_report(Path(f"{prefix}_20261008_201748.xml"), SKIPPED)
    _write_report(Path(f"{prefix}_2_20261008_201748.xml"), PASSED)
    _write_report(tmp_path / "tt_transformers_20261008_201741_837538072_20261008_201748.xml", PASSED)

    result = _check(prefix)

    assert result.returncode != 0
    assert "No tt-transformers test passed" in result.stderr