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
Next Next commit
platform support
  • Loading branch information
arihant2math committed Apr 24, 2025
commit 0236917a621ecdbcff8a5d47414c02e6b4673fc5
24 changes: 16 additions & 8 deletions scripts/fix_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import argparse
import platform

def parse_args():
parser = argparse.ArgumentParser(description="Fix test.")
parser.add_argument("--test", type=str, help="Name of test")
parser.add_argument("--path", type=str, help="Path to test file")
parser.add_argument("--force", action="store_true", help="Force modification")
parser.add_argument("--platform", action="store_true", help="Platform specific failure")

args = parser.parse_args()
return args
Expand All @@ -20,6 +22,7 @@ def __str__(self):
class TestResult:
tests_result: str = ""
tests = []
stdout = ""

def __str__(self):
return f"TestResult(tests_result={self.tests_result},tests={len(self.tests)})"
Expand All @@ -28,6 +31,7 @@ def __str__(self):
def parse_results(result):
lines = result.stdout.splitlines()
test_results = TestResult()
test_results.stdout = result.stdout
in_test_results = False
for line in lines:
if line == "Run tests sequentially":
Expand All @@ -52,14 +56,20 @@ def parse_results(result):
def path_to_test(path) -> list[str]:
return path.split(".")[2:]

def modify_test(file: str, test: list[str]) -> str:
def modify_test(file: str, test: list[str], for_platform: bool = False) -> str:
lines = file.splitlines()
result = []
failure_fixture = "expectedFailure"
if for_platform:
if platform.system() == "Windows":
failure_fixture = "expectedFailureIfWindows(\"TODO: RUSTPYTHON: Generated by fix_test script\")"
else:
raise Exception("Platform not supported")
for line in lines:
if line.lstrip(" ").startswith("def " + test[-1]):
whitespace = line[:line.index("def ")]
result.append(whitespace + "# TODO: RUSTPYTHON")
result.append(whitespace + "@unittest.expectedFailure")
result.append(whitespace + f"@unittest.{failure_fixture}")
result.append(line)
return "\n".join(result)

Expand All @@ -77,11 +87,9 @@ def run_test(test_name):
tests = run_test(test_name)
f = open(args.path).read()
for test in tests.tests:
if test.result == "fail":
if test.result == "fail" or test.result == "error":
print("Modifying test:", test.name)
f = modify_test(f, path_to_test(test.path))
f = modify_test(f, path_to_test(test.path), args.platform)
with open(args.path, "w") as file:
if args.force or run_test().tests_result == "ok":
file.write(f)
else:
raise Exception("Test failed after modification")
# TODO: Find validation method, and make --force override it
file.write(f)