-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathverify.py
More file actions
58 lines (49 loc) · 1.68 KB
/
Copy pathverify.py
File metadata and controls
58 lines (49 loc) · 1.68 KB
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
#!/usr/bin/env python3
"""Run the structured-pipeline contract against starter or solution."""
from __future__ import annotations
import argparse
import os
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("implementation", choices=("starter", "solution"))
parser.add_argument("--expect-failure", action="store_true")
args = parser.parse_args()
command = [
sys.executable,
"-m",
"unittest",
"discover",
"-s",
str(ROOT / "tests"),
]
environment = os.environ.copy()
environment["PYTHONPATH"] = str(ROOT / args.implementation)
result = subprocess.run(
command,
env=environment,
check=False,
capture_output=args.expect_failure,
text=args.expect_failure,
)
if args.expect_failure:
if result.returncode == 0:
print("Expected the starter to fail, but it passed.", file=sys.stderr)
return 1
output = (result.stdout or "") + (result.stderr or "")
expected_failures = (
"test_invalid_batch_size_raises",
"test_isolates_and_records_malformed_records",
)
if not any(failure in output for failure in expected_failures):
print("Starter failed for an unexpected reason:", file=sys.stderr)
print(output, file=sys.stderr)
return 1
print("Expected batch pipeline regression reproduced: unhandled malformed items and invalid batch size fail.")
return 0
return result.returncode
if __name__ == "__main__":
raise SystemExit(main())