run_mediacrawler_quality.py
1.84 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
59
60
61
62
63
64
65
66
67
68
69
70
"""Run isolated MediaCrawler smoke tests from the BettaFish repository root."""
from __future__ import annotations
import argparse
import subprocess
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
VENDOR_ROOT = REPO_ROOT / "vendor" / "mediacrawler"
DEFAULT_TESTS = [
"test/test_utils.py",
"test/test_expiring_local_cache.py",
"tests/test_store_factory.py",
"tests/test_excel_store.py",
]
def parse_args(argv: list[str]) -> tuple[argparse.Namespace, list[str]]:
parser = argparse.ArgumentParser(
description="Run the isolated MediaCrawler smoke-test subset."
)
parser.add_argument(
"--print-only",
action="store_true",
help="Print the resolved pytest command without executing it.",
)
return parser.parse_known_args(argv)
def build_command(extra_args: list[str]) -> list[str]:
return [
sys.executable,
"-m",
"pytest",
"--rootdir",
".",
*DEFAULT_TESTS,
*extra_args,
]
def main(argv: list[str]) -> int:
args, extra_args = parse_args(argv)
if not VENDOR_ROOT.exists():
print(f"MediaCrawler vendor directory not found: {VENDOR_ROOT}", file=sys.stderr)
return 2
if sys.version_info[:2] != (3, 11):
print(
"Warning: vendor/mediacrawler smoke tests are maintained against Python 3.11. "
f"Current interpreter is {sys.version_info.major}.{sys.version_info.minor}.",
file=sys.stderr,
)
command = build_command(extra_args)
print(f"MediaCrawler root: {VENDOR_ROOT}")
print("Pytest command:", " ".join(command))
if args.print_only:
return 0
completed = subprocess.run(command, cwd=VENDOR_ROOT, check=False)
return completed.returncode
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))