10
10
this suite would slow down the main suite too much.
11
11
"""
12
12
13
- from contextlib import contextmanager
14
- import errno
15
13
import os
16
14
import os .path
17
15
import re
25
23
from mypy .test .data import DataDrivenTestCase , parse_test_cases , DataSuite
26
24
from mypy .test .helpers import assert_string_arrays_equal
27
25
from mypy .util import try_find_python2_interpreter
26
+ from mypy import api
28
27
29
28
# Files which contain test case descriptions.
30
29
python_eval_files = ['pythoneval.test' ,
@@ -61,11 +60,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
61
60
version.
62
61
"""
63
62
assert testcase .old_cwd is not None , "test was not properly set up"
64
- mypy_cmdline = [
65
- python3_path ,
66
- os .path .join (testcase .old_cwd , 'scripts' , 'mypy' ),
67
- '--show-traceback' ,
68
- ]
63
+ mypy_cmdline = ['--show-traceback' ]
69
64
py2 = testcase .name .lower ().endswith ('python2' )
70
65
if py2 :
71
66
mypy_cmdline .append ('--py2' )
@@ -80,21 +75,27 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
80
75
81
76
# Write the program to a file.
82
77
program = '_' + testcase .name + '.py'
83
- mypy_cmdline .append (program )
84
78
program_path = os .path .join (test_temp_dir , program )
79
+ mypy_cmdline .append (program_path )
85
80
with open (program_path , 'w' ) as file :
86
81
for s in testcase .input :
87
82
file .write ('{}\n ' .format (s ))
83
+ output = []
88
84
# Type check the program.
89
- # This uses the same PYTHONPATH as the current process.
90
- returncode , out = run (mypy_cmdline )
85
+ out , err , returncode = api .run (mypy_cmdline )
86
+ # split lines, remove newlines, and remove directory of test case
87
+ for line in (out + err ).splitlines ():
88
+ if line .startswith (test_temp_dir + os .sep ):
89
+ output .append (line [len (test_temp_dir + os .sep ):].rstrip ("\r \n " ))
90
+ else :
91
+ output .append (line .rstrip ("\r \n " ))
91
92
if returncode == 0 :
92
93
# Execute the program.
93
94
returncode , interp_out = run ([interpreter , program ])
94
- out += interp_out
95
+ output . extend ( interp_out )
95
96
# Remove temp file.
96
97
os .remove (program_path )
97
- assert_string_arrays_equal (adapt_output (testcase ), out ,
98
+ assert_string_arrays_equal (adapt_output (testcase ), output ,
98
99
'Invalid output ({}, line {})' .format (
99
100
testcase .file , testcase .line ))
100
101
@@ -115,7 +116,7 @@ def adapt_output(testcase: DataDrivenTestCase) -> List[str]:
115
116
116
117
117
118
def run (
118
- cmdline : List [str ], * , env : Optional [Dict [str , str ]] = None , timeout : int = 30
119
+ cmdline : List [str ], * , env : Optional [Dict [str , str ]] = None , timeout : int = 300
119
120
) -> Tuple [int , List [str ]]:
120
121
"""A poor man's subprocess.run() for 3.3 and 3.4 compatibility."""
121
122
process = subprocess .Popen (
0 commit comments