test-distribution.py functionality.
(pbs_source_dir: Path, raw_args: list[str])
| 79 | |
| 80 | |
| 81 | def main(pbs_source_dir: Path, raw_args: list[str]) -> int: |
| 82 | """test-distribution.py functionality.""" |
| 83 | |
| 84 | parser = argparse.ArgumentParser() |
| 85 | |
| 86 | parser.add_argument( |
| 87 | "--stdlib", |
| 88 | action="store_true", |
| 89 | help="Run the stdlib test harness", |
| 90 | ) |
| 91 | parser.add_argument( |
| 92 | "dist", |
| 93 | nargs=1, |
| 94 | help="Path to distribution to test", |
| 95 | ) |
| 96 | parser.add_argument( |
| 97 | "harness_args", |
| 98 | nargs=argparse.REMAINDER, |
| 99 | help="Raw arguments to pass to Python's test harness", |
| 100 | ) |
| 101 | |
| 102 | args = parser.parse_args(raw_args) |
| 103 | |
| 104 | dist_path_raw = Path(args.dist[0]) |
| 105 | |
| 106 | td = None |
| 107 | try: |
| 108 | if dist_path_raw.is_file(): |
| 109 | td = tempfile.TemporaryDirectory() |
| 110 | dist_path = extract_python_archive(dist_path_raw, Path(td.name)) |
| 111 | else: |
| 112 | dist_path = dist_path_raw |
| 113 | |
| 114 | python_json = dist_path / "PYTHON.json" |
| 115 | |
| 116 | with python_json.open("r", encoding="utf-8") as fh: |
| 117 | python_info = json.load(fh) |
| 118 | |
| 119 | codes = [] |
| 120 | |
| 121 | codes.append(run_custom_unittests(pbs_source_dir, dist_path, python_info)) |
| 122 | |
| 123 | if args.stdlib: |
| 124 | codes.append(run_stdlib_tests(dist_path, python_info, args.harness_args)) |
| 125 | |
| 126 | if len(codes) == 0: |
| 127 | print("no tests run") |
| 128 | return 1 |
| 129 | |
| 130 | if any(code != 0 for code in codes): |
| 131 | return 1 |
| 132 | |
| 133 | return 0 |
| 134 | |
| 135 | finally: |
| 136 | if td: |
| 137 | td.cleanup() |
no test coverage detected