@@ -19,6 +19,10 @@ def colored(text: str, color: str | None = None, on_color: str | None = None, at
19
19
20
20
21
21
_STRICTER_CONFIG_FILE = "pyrightconfig.stricter.json"
22
+ _TESTCASES_CONFIG_FILE = "pyrightconfig.testcases.json"
23
+ _TESTCASES = "test_cases"
24
+ _NPX_ERROR_PATTERN = r"error (runn|find)ing npx"
25
+ _NPX_ERROR_MESSAGE = colored ("\n Skipping Pyright tests: npx is not installed or can't be run!" , "yellow" )
22
26
_SUCCESS = colored ("Success" , "green" )
23
27
_SKIPPED = colored ("Skipped" , "yellow" )
24
28
_FAILED = colored ("Failed" , "red" )
@@ -89,14 +93,15 @@ def main() -> None:
89
93
print ("\n Running check_new_syntax.py..." )
90
94
check_new_syntax_result = subprocess .run ([sys .executable , "tests/check_new_syntax.py" ])
91
95
92
- print (f"\n Running Pyright on Python { _PYTHON_VERSION } ..." )
96
+ strict_params = _get_strict_params (path )
97
+ print (f"\n Running Pyright ({ 'stricter' if strict_params else 'base' } configs) for Python { _PYTHON_VERSION } ..." )
93
98
pyright_result = subprocess .run (
94
- [sys .executable , "tests/pyright_test.py" , path , "--pythonversion" , _PYTHON_VERSION ] + _get_strict_params ( path ) ,
95
- stderr = subprocess . PIPE ,
99
+ [sys .executable , "tests/pyright_test.py" , path , "--pythonversion" , _PYTHON_VERSION ] + strict_params ,
100
+ capture_output = True ,
96
101
text = True ,
97
102
)
98
- if re .match (r"error (runn|find)ing npx" , pyright_result .stderr ):
99
- print (colored ( " \n Skipping Pyright tests: npx is not installed or can't be run!" , "yellow" ) )
103
+ if re .match (_NPX_ERROR_PATTERN , pyright_result .stderr ):
104
+ print (_NPX_ERROR_MESSAGE )
100
105
pyright_returncode = 0
101
106
pyright_skipped = True
102
107
else :
@@ -133,19 +138,47 @@ def main() -> None:
133
138
print ("\n Running pytype..." )
134
139
pytype_result = subprocess .run ([sys .executable , "tests/pytype_test.py" , path ])
135
140
136
- print (f"\n Running regression tests for Python { _PYTHON_VERSION } ..." )
137
- regr_test_result = subprocess .run (
138
- [sys .executable , "tests/regr_test.py" , "stdlib" if folder == "stdlib" else stub , "--python-version" , _PYTHON_VERSION ],
139
- stderr = subprocess .PIPE ,
140
- text = True ,
141
- )
142
- # No test means they all ran successfully (0 out of 0). Not all 3rd-party stubs have regression tests.
143
- if "No test cases found" in regr_test_result .stderr :
141
+ test_cases_path = Path (path ) / "@tests" / _TESTCASES if folder == "stubs" else Path (_TESTCASES )
142
+ if not test_cases_path .exists ():
143
+ # No test means they all ran successfully (0 out of 0). Not all 3rd-party stubs have regression tests.
144
+ print (colored (f"\n Regression tests: No { _TESTCASES } folder for { stub !r} !" , "green" ))
145
+ pyright_testcases_returncode = 0
146
+ pyright_testcases_skipped = False
144
147
regr_test_returncode = 0
145
- print (colored (f"\n No test cases found for { stub !r} !" , "green" ))
146
148
else :
147
- regr_test_returncode = regr_test_result .returncode
148
- print (regr_test_result .stderr )
149
+ print (f"\n Running Pyright regression tests for Python { _PYTHON_VERSION } ..." )
150
+ command = [
151
+ sys .executable ,
152
+ "tests/pyright_test.py" ,
153
+ str (test_cases_path ),
154
+ "--pythonversion" ,
155
+ _PYTHON_VERSION ,
156
+ "-p" ,
157
+ _TESTCASES_CONFIG_FILE ,
158
+ ]
159
+ pyright_testcases_result = subprocess .run (command , capture_output = True , text = True )
160
+ if re .match (_NPX_ERROR_PATTERN , pyright_testcases_result .stderr ):
161
+ print (_NPX_ERROR_MESSAGE )
162
+ pyright_testcases_returncode = 0
163
+ pyright_testcases_skipped = True
164
+ else :
165
+ print (pyright_result .stderr )
166
+ pyright_testcases_returncode = pyright_testcases_result .returncode
167
+ pyright_testcases_skipped = False
168
+
169
+ print (f"\n Running mypy regression tests for Python { _PYTHON_VERSION } ..." )
170
+ regr_test_result = subprocess .run (
171
+ [sys .executable , "tests/regr_test.py" , "stdlib" if folder == "stdlib" else stub , "--python-version" , _PYTHON_VERSION ],
172
+ capture_output = True ,
173
+ text = True ,
174
+ )
175
+ # No test means they all ran successfully (0 out of 0). Not all 3rd-party stubs have regression tests.
176
+ if "No test cases found" in regr_test_result .stderr :
177
+ regr_test_returncode = 0
178
+ print (colored (f"\n No test cases found for { stub !r} !" , "green" ))
179
+ else :
180
+ regr_test_returncode = regr_test_result .returncode
181
+ print (regr_test_result .stderr )
149
182
150
183
any_failure = any (
151
184
[
@@ -156,6 +189,7 @@ def main() -> None:
156
189
mypy_result .returncode ,
157
190
getattr (stubtest_result , "returncode" , 0 ),
158
191
getattr (pytype_result , "returncode" , 0 ),
192
+ pyright_testcases_returncode ,
159
193
regr_test_returncode ,
160
194
]
161
195
)
@@ -180,7 +214,11 @@ def main() -> None:
180
214
print ("pytype:" , _SKIPPED )
181
215
else :
182
216
print ("pytype:" , _SUCCESS if pytype_result .returncode == 0 else _FAILED )
183
- print ("Regression test:" , _SUCCESS if regr_test_returncode == 0 else _FAILED )
217
+ if pyright_testcases_skipped :
218
+ print ("Pyright regression tests:" , _SKIPPED )
219
+ else :
220
+ print ("Pyright regression tests:" , _SUCCESS if pyright_testcases_returncode == 0 else _FAILED )
221
+ print ("mypy regression test:" , _SUCCESS if regr_test_returncode == 0 else _FAILED )
184
222
185
223
sys .exit (int (any_failure ))
186
224
0 commit comments