|
| 1 | +import subprocess |
| 2 | +import tarfile |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +PACK_SCRIPT = Path(__file__).with_name("pack_ya_trace_inputs.sh") |
| 6 | + |
| 7 | + |
| 8 | +def _trace_path(ya_out: Path, suite: str) -> Path: |
| 9 | + return ya_out / suite / "test-results" / "unittest" / "ytest.report.trace" |
| 10 | + |
| 11 | + |
| 12 | +def test_pack_uses_python_selected_paths_without_auxiliary_manifest( |
| 13 | + tmp_path: Path, |
| 14 | +) -> None: |
| 15 | + report_dir = tmp_path / "summary" |
| 16 | + ya_out = tmp_path / "out" |
| 17 | + selected = _trace_path(ya_out, "selected") |
| 18 | + ignored = _trace_path(ya_out, "ignored") |
| 19 | + for path in (selected, ignored): |
| 20 | + path.parent.mkdir(parents=True) |
| 21 | + path.write_text(path.parent.parent.parent.name) |
| 22 | + report_dir.mkdir() |
| 23 | + (report_dir / "trace-inputs.files").write_bytes( |
| 24 | + b"./selected/test-results/unittest/ytest.report.trace\0" |
| 25 | + ) |
| 26 | + evlog = tmp_path / "ya_evlog.jsonl" |
| 27 | + evlog.write_text("{}\n") |
| 28 | + |
| 29 | + subprocess.run(["bash", PACK_SCRIPT, report_dir, ya_out, evlog], check=True) |
| 30 | + |
| 31 | + with tarfile.open(report_dir / "trace-inputs.tar.gz") as archive: |
| 32 | + assert set(archive.getnames()) == { |
| 33 | + "ya_evlog.jsonl", |
| 34 | + "ya-out/selected/test-results/unittest/ytest.report.trace", |
| 35 | + } |
| 36 | + assert not (report_dir / "trace-inputs.files").exists() |
| 37 | + |
| 38 | + |
| 39 | +def test_pack_discovers_inputs_after_renderer_startup_failure(tmp_path: Path) -> None: |
| 40 | + report_dir = tmp_path / "summary" |
| 41 | + ya_out = tmp_path / "out" |
| 42 | + trace = _trace_path(ya_out, "suite") |
| 43 | + trace.parent.mkdir(parents=True) |
| 44 | + trace.write_text("{}\n") |
| 45 | + (ya_out / "not-a-trace").write_text("ignored") |
| 46 | + |
| 47 | + subprocess.run(["bash", PACK_SCRIPT, report_dir, ya_out], check=True) |
| 48 | + |
| 49 | + with tarfile.open(report_dir / "trace-inputs.tar.gz") as archive: |
| 50 | + assert archive.getnames() == [ |
| 51 | + "ya-out/suite/test-results/unittest/ytest.report.trace" |
| 52 | + ] |
| 53 | + |
| 54 | + |
| 55 | +def test_pack_treats_unusual_python_selected_paths_literally(tmp_path: Path) -> None: |
| 56 | + report_dir = tmp_path / "summary" |
| 57 | + ya_out = tmp_path / "out" |
| 58 | + trace = _trace_path(ya_out, "-suite\nwith-newline") |
| 59 | + trace.parent.mkdir(parents=True) |
| 60 | + trace.write_text("{}\n") |
| 61 | + report_dir.mkdir() |
| 62 | + relative = trace.relative_to(ya_out).as_posix() |
| 63 | + (report_dir / "trace-inputs.files").write_bytes(f"./{relative}".encode() + b"\0") |
| 64 | + |
| 65 | + subprocess.run(["bash", PACK_SCRIPT, report_dir, ya_out], check=True) |
| 66 | + |
| 67 | + with tarfile.open(report_dir / "trace-inputs.tar.gz") as archive: |
| 68 | + assert archive.getnames() == [f"ya-out/{relative}"] |
0 commit comments