Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix_test --quick-import
  • Loading branch information
youknowone committed Jan 11, 2026
commit f2d559428823b32134c798553993cfb06d28f617
49 changes: 46 additions & 3 deletions scripts/fix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
It adds @unittest.expectedFailure to the test functions that are failing in RustPython, but not in CPython.
As well as marking the test with a TODO comment.

How to use:
Quick Import (recommended):
python ./scripts/fix_test.py --quick-import cpython/Lib/test/test_foo.py

This will:
1. Copy cpython/Lib/test/test_foo.py to Lib/test/test_foo.py (if not exists)
2. Run the test with RustPython
3. Mark failing tests with @unittest.expectedFailure

Manual workflow:
1. Copy a specific test from the CPython repository to the RustPython repository.
2. Remove all unexpected failures from the test and skip the tests that hang.
3. Build RustPython: cargo build --release
Expand All @@ -15,6 +23,7 @@
"""

import argparse
import shutil
import sys
from pathlib import Path

Expand All @@ -23,7 +32,14 @@

def parse_args():
parser = argparse.ArgumentParser(description="Fix test.")
parser.add_argument("--path", type=Path, help="Path to test file")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--path", type=Path, help="Path to test file")
group.add_argument(
"--quick-import",
type=Path,
metavar="PATH",
help="Import from path containing /Lib/ (e.g., cpython/Lib/test/foo.py)",
)
parser.add_argument("--force", action="store_true", help="Force modification")
parser.add_argument(
"--platform", action="store_true", help="Platform specific failure"
Expand Down Expand Up @@ -122,7 +138,7 @@ def run_test(test_name):
import subprocess

result = subprocess.run(
[rustpython_location, "-m", "test", "-v", test_name],
[rustpython_location, "-m", "test", "-v", "-u", "all", "--slowest", test_name],
capture_output=True,
text=True,
)
Expand All @@ -131,6 +147,33 @@ def run_test(test_name):

if __name__ == "__main__":
args = parse_args()

# Handle --quick-import: extract Lib/... path and copy if needed
if args.quick_import is not None:
src_str = str(args.quick_import)
lib_marker = "/Lib/"

if lib_marker not in src_str:
print(f"Error: --quick-import path must contain '/Lib/' (got: {src_str})")
sys.exit(1)

idx = src_str.index(lib_marker)
lib_path = Path(src_str[idx + 1 :]) # Lib/test/foo.py
src_path = args.quick_import

if not src_path.exists():
print(f"Error: Source file not found: {src_path}")
sys.exit(1)

if not lib_path.exists():
print(f"Copying: {src_path} -> {lib_path}")
lib_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(src_path, lib_path)
else:
print(f"File already exists: {lib_path}")

args.path = lib_path

test_path = args.path.resolve()
if not test_path.exists():
print(f"Error: File not found: {test_path}")
Expand Down