Skip to content

Commit f2d5594

Browse files
committed
fix_test --quick-import
1 parent 2a1faf4 commit f2d5594

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

scripts/fix_test.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
It adds @unittest.expectedFailure to the test functions that are failing in RustPython, but not in CPython.
44
As well as marking the test with a TODO comment.
55
6-
How to use:
6+
Quick Import (recommended):
7+
python ./scripts/fix_test.py --quick-import cpython/Lib/test/test_foo.py
8+
9+
This will:
10+
1. Copy cpython/Lib/test/test_foo.py to Lib/test/test_foo.py (if not exists)
11+
2. Run the test with RustPython
12+
3. Mark failing tests with @unittest.expectedFailure
13+
14+
Manual workflow:
715
1. Copy a specific test from the CPython repository to the RustPython repository.
816
2. Remove all unexpected failures from the test and skip the tests that hang.
917
3. Build RustPython: cargo build --release
@@ -15,6 +23,7 @@
1523
"""
1624

1725
import argparse
26+
import shutil
1827
import sys
1928
from pathlib import Path
2029

@@ -23,7 +32,14 @@
2332

2433
def parse_args():
2534
parser = argparse.ArgumentParser(description="Fix test.")
26-
parser.add_argument("--path", type=Path, help="Path to test file")
35+
group = parser.add_mutually_exclusive_group(required=True)
36+
group.add_argument("--path", type=Path, help="Path to test file")
37+
group.add_argument(
38+
"--quick-import",
39+
type=Path,
40+
metavar="PATH",
41+
help="Import from path containing /Lib/ (e.g., cpython/Lib/test/foo.py)",
42+
)
2743
parser.add_argument("--force", action="store_true", help="Force modification")
2844
parser.add_argument(
2945
"--platform", action="store_true", help="Platform specific failure"
@@ -122,7 +138,7 @@ def run_test(test_name):
122138
import subprocess
123139

124140
result = subprocess.run(
125-
[rustpython_location, "-m", "test", "-v", test_name],
141+
[rustpython_location, "-m", "test", "-v", "-u", "all", "--slowest", test_name],
126142
capture_output=True,
127143
text=True,
128144
)
@@ -131,6 +147,33 @@ def run_test(test_name):
131147

132148
if __name__ == "__main__":
133149
args = parse_args()
150+
151+
# Handle --quick-import: extract Lib/... path and copy if needed
152+
if args.quick_import is not None:
153+
src_str = str(args.quick_import)
154+
lib_marker = "/Lib/"
155+
156+
if lib_marker not in src_str:
157+
print(f"Error: --quick-import path must contain '/Lib/' (got: {src_str})")
158+
sys.exit(1)
159+
160+
idx = src_str.index(lib_marker)
161+
lib_path = Path(src_str[idx + 1 :]) # Lib/test/foo.py
162+
src_path = args.quick_import
163+
164+
if not src_path.exists():
165+
print(f"Error: Source file not found: {src_path}")
166+
sys.exit(1)
167+
168+
if not lib_path.exists():
169+
print(f"Copying: {src_path} -> {lib_path}")
170+
lib_path.parent.mkdir(parents=True, exist_ok=True)
171+
shutil.copy(src_path, lib_path)
172+
else:
173+
print(f"File already exists: {lib_path}")
174+
175+
args.path = lib_path
176+
134177
test_path = args.path.resolve()
135178
if not test_path.exists():
136179
print(f"Error: File not found: {test_path}")

0 commit comments

Comments
 (0)