FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RustPython/scripts/fix_test.py at main · github-roushan/RustPython · GitHub
github-roushan
RustPython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
RustPython
/
scripts
/
fix_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
161 lines (137 loc) · 5.63 KB
Breadcrumbs
RustPython
/
scripts
/
fix_test.py
Copy path
File metadata and controls
161 lines (137 loc) · 5.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
An automated script to mark failures in python test suite.
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:
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. Run python ./scripts/fix_test.py --test test_venv --path ./Lib/test/test_venv.py or equivalent for the test from the project root.
4. Ensure that there are no unexpected successes in the test.
5. Actually fix the test.
"""
import
argparse
import
ast
import
itertools
import
platform
from
pathlib
import
Path
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"Fix test."
)
parser
.
add_argument
(
"--path"
,
type
=
Path
,
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
class
Test
:
name
:
str
=
""
path
:
str
=
""
result
:
str
=
""
def
__str__
(
self
):
return
f"Test(name=
{
self
.
name
}
, path=
{
self
.
path
}
, result=
{
self
.
result
}
)"
class
TestResult
:
tests_result
:
str
=
""
tests
=
[]
stdout
=
""
def
__str__
(
self
):
return
f"TestResult(tests_result=
{
self
.
tests_result
}
,tests=
{
len
(
self
.
tests
)
}
)"
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"
:
in_test_results
=
True
elif
line
.
startswith
(
"-----------"
):
in_test_results
=
False
if
(
in_test_results
and
not
line
.
startswith
(
"tests"
)
and
not
line
.
startswith
(
"["
)
):
line
=
line
.
split
(
" "
)
if
line
!=
[]
and
len
(
line
)
>
3
:
test
=
Test
()
test
.
name
=
line
[
0
]
test
.
path
=
line
[
1
].
strip
(
"("
).
strip
(
")"
)
test
.
result
=
" "
.
join
(
line
[
3
:]).
lower
()
test_results
.
tests
.
append
(
test
)
else
:
if
"== Tests result: "
in
line
:
res
=
line
.
split
(
"== Tests result: "
)[
1
]
res
=
res
.
split
(
" "
)[
0
]
test_results
.
tests_result
=
res
return
test_results
def
path_to_test
(
path
)
->
list
[
str
]:
return
path
.
split
(
"."
)[
2
:]
def
modify_test
(
file
:
str
,
test
:
list
[
str
],
for_platform
:
bool
=
False
)
->
str
:
a
=
ast
.
parse
(
file
)
lines
=
file
.
splitlines
()
fixture
=
"@unittest.expectedFailure"
for
node
in
ast
.
walk
(
a
):
if
isinstance
(
node
,
ast
.
FunctionDef
):
if
node
.
name
==
test
[
-
1
]:
assert
not
for_platform
indent
=
" "
*
node
.
col_offset
lines
.
insert
(
node
.
lineno
-
1
,
indent
+
fixture
)
lines
.
insert
(
node
.
lineno
-
1
,
indent
+
"# TODO: RUSTPYTHON"
)
break
return
"
\n
"
.
join
(
lines
)
def
modify_test_v2
(
file
:
str
,
test
:
list
[
str
],
for_platform
:
bool
=
False
)
->
str
:
a
=
ast
.
parse
(
file
)
lines
=
file
.
splitlines
()
fixture
=
"@unittest.expectedFailure"
for
key
,
node
in
ast
.
iter_fields
(
a
):
if
key
==
"body"
:
for
i
,
n
in
enumerate
(
node
):
match
n
:
case
ast
.
ClassDef
():
if
len
(
test
)
==
2
and
test
[
0
]
==
n
.
name
:
# look through body for function def
for
i
,
fn
in
enumerate
(
n
.
body
):
match
fn
:
case
ast
.
FunctionDef
():
if
fn
.
name
==
test
[
-
1
]:
assert
not
for_platform
indent
=
" "
*
fn
.
col_offset
lines
.
insert
(
fn
.
lineno
-
1
,
indent
+
fixture
)
lines
.
insert
(
fn
.
lineno
-
1
,
indent
+
"# TODO: RUSTPYTHON"
,
)
break
case
ast
.
FunctionDef
():
if
n
.
name
==
test
[
0
]
and
len
(
test
)
==
1
:
assert
not
for_platform
indent
=
" "
*
n
.
col_offset
lines
.
insert
(
n
.
lineno
-
1
,
indent
+
fixture
)
lines
.
insert
(
n
.
lineno
-
1
,
indent
+
"# TODO: RUSTPYTHON"
)
break
if
i
>
500
:
exit
()
return
"
\n
"
.
join
(
lines
)
def
run_test
(
test_name
):
print
(
f"Running test:
{
test_name
}
"
)
rustpython_location
=
"./target/release/rustpython"
import
subprocess
result
=
subprocess
.
run
(
[
rustpython_location
,
"-m"
,
"test"
,
"-v"
,
test_name
],
capture_output
=
True
,
text
=
True
,
)
return
parse_results
(
result
)
if
__name__
==
"__main__"
:
args
=
parse_args
()
test_name
=
args
.
path
.
stem
tests
=
run_test
(
test_name
)
f
=
open
(
args
.
path
).
read
()
for
test
in
tests
.
tests
:
if
test
.
result
==
"fail"
or
test
.
result
==
"error"
:
print
(
"Modifying test:"
,
test
.
name
)
f
=
modify_test_v2
(
f
,
path_to_test
(
test
.
path
),
args
.
platform
)
with
open
(
args
.
path
,
"w"
)
as
file
:
# TODO: Find validation method, and make --force override it
file
.
write
(
f
)
Back
|
FazBrowse Home
|
New Git URL