1
1
import argparse
2
+ import platform
2
3
3
4
def parse_args ():
4
5
parser = argparse .ArgumentParser (description = "Fix test." )
5
6
parser .add_argument ("--test" , type = str , help = "Name of test" )
6
7
parser .add_argument ("--path" , type = str , help = "Path to test file" )
7
8
parser .add_argument ("--force" , action = "store_true" , help = "Force modification" )
9
+ parser .add_argument ("--platform" , action = "store_true" , help = "Platform specific failure" )
8
10
9
11
args = parser .parse_args ()
10
12
return args
@@ -20,6 +22,7 @@ def __str__(self):
20
22
class TestResult :
21
23
tests_result : str = ""
22
24
tests = []
25
+ stdout = ""
23
26
24
27
def __str__ (self ):
25
28
return f"TestResult(tests_result={ self .tests_result } ,tests={ len (self .tests )} )"
@@ -28,6 +31,7 @@ def __str__(self):
28
31
def parse_results (result ):
29
32
lines = result .stdout .splitlines ()
30
33
test_results = TestResult ()
34
+ test_results .stdout = result .stdout
31
35
in_test_results = False
32
36
for line in lines :
33
37
if line == "Run tests sequentially" :
@@ -52,14 +56,20 @@ def parse_results(result):
52
56
def path_to_test (path ) -> list [str ]:
53
57
return path .split ("." )[2 :]
54
58
55
- def modify_test (file : str , test : list [str ]) -> str :
59
+ def modify_test (file : str , test : list [str ], for_platform : bool = False ) -> str :
56
60
lines = file .splitlines ()
57
61
result = []
62
+ failure_fixture = "expectedFailure"
63
+ if for_platform :
64
+ if platform .system () == "Windows" :
65
+ failure_fixture = "expectedFailureIfWindows(\" TODO: RUSTPYTHON: Generated by fix_test script\" )"
66
+ else :
67
+ raise Exception ("Platform not supported" )
58
68
for line in lines :
59
69
if line .lstrip (" " ).startswith ("def " + test [- 1 ]):
60
70
whitespace = line [:line .index ("def " )]
61
71
result .append (whitespace + "# TODO: RUSTPYTHON" )
62
- result .append (whitespace + "@unittest.expectedFailure " )
72
+ result .append (whitespace + f "@unittest.{ failure_fixture } " )
63
73
result .append (line )
64
74
return "\n " .join (result )
65
75
@@ -77,11 +87,9 @@ def run_test(test_name):
77
87
tests = run_test (test_name )
78
88
f = open (args .path ).read ()
79
89
for test in tests .tests :
80
- if test .result == "fail" :
90
+ if test .result == "fail" or test . result == "error" :
81
91
print ("Modifying test:" , test .name )
82
- f = modify_test (f , path_to_test (test .path ))
92
+ f = modify_test (f , path_to_test (test .path ), args . platform )
83
93
with open (args .path , "w" ) as file :
84
- if args .force or run_test ().tests_result == "ok" :
85
- file .write (f )
86
- else :
87
- raise Exception ("Test failed after modification" )
94
+ # TODO: Find validation method, and make --force override it
95
+ file .write (f )
0 commit comments