1
1
import argparse
2
2
import ast
3
+ import itertools
3
4
import platform
4
5
from pathlib import Path
5
6
@@ -71,6 +72,37 @@ def modify_test(file: str, test: list[str], for_platform: bool = False) -> str:
71
72
break
72
73
return "\n " .join (lines )
73
74
75
+ def modify_test_v2 (file : str , test : list [str ], for_platform : bool = False ) -> str :
76
+ a = ast .parse (file )
77
+ lines = file .splitlines ()
78
+ fixture = "@unittest.expectedFailure"
79
+ for key , node in ast .iter_fields (a ):
80
+ if key == "body" :
81
+ for i , n in enumerate (node ):
82
+ match n :
83
+ case ast .ClassDef ():
84
+ if len (test ) == 2 and test [0 ] == n .name :
85
+ # look through body for function def
86
+ for i , fn in enumerate (n .body ):
87
+ match fn :
88
+ case ast .FunctionDef ():
89
+ if fn .name == test [- 1 ]:
90
+ assert not for_platform
91
+ indent = " " * fn .col_offset
92
+ lines .insert (fn .lineno - 1 , indent + fixture )
93
+ lines .insert (fn .lineno - 1 , indent + "# TODO: RUSTPYTHON" )
94
+ break
95
+ case ast .FunctionDef ():
96
+ if n .name == test [0 ] and len (test ) == 1 :
97
+ assert not for_platform
98
+ indent = " " * n .col_offset
99
+ lines .insert (n .lineno - 1 , indent + fixture )
100
+ lines .insert (n .lineno - 1 , indent + "# TODO: RUSTPYTHON" )
101
+ break
102
+ if i > 500 :
103
+ exit ()
104
+ return "\n " .join (lines )
105
+
74
106
def run_test (test_name ):
75
107
print (f"Running test: { test_name } " )
76
108
rustpython_location = "./target/release/rustpython"
@@ -87,7 +119,7 @@ def run_test(test_name):
87
119
for test in tests .tests :
88
120
if test .result == "fail" or test .result == "error" :
89
121
print ("Modifying test:" , test .name )
90
- f = modify_test (f , path_to_test (test .path ), args .platform )
122
+ f = modify_test_v2 (f , path_to_test (test .path ), args .platform )
91
123
with open (args .path , "w" ) as file :
92
124
# TODO: Find validation method, and make --force override it
93
125
file .write (f )
0 commit comments