Skip to content

Commit f6a74b5

Browse files
emmatypinggvanrossum
authored andcommitted
Move pythoneval to mypy.api and increase timeout (#4047)
1 parent 1f9e139 commit f6a74b5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

mypy/test/testpythoneval.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
this suite would slow down the main suite too much.
1111
"""
1212

13-
from contextlib import contextmanager
14-
import errno
1513
import os
1614
import os.path
1715
import re
@@ -25,6 +23,7 @@
2523
from mypy.test.data import DataDrivenTestCase, parse_test_cases, DataSuite
2624
from mypy.test.helpers import assert_string_arrays_equal
2725
from mypy.util import try_find_python2_interpreter
26+
from mypy import api
2827

2928
# Files which contain test case descriptions.
3029
python_eval_files = ['pythoneval.test',
@@ -61,11 +60,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
6160
version.
6261
"""
6362
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']
6964
py2 = testcase.name.lower().endswith('python2')
7065
if py2:
7166
mypy_cmdline.append('--py2')
@@ -80,21 +75,27 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
8075

8176
# Write the program to a file.
8277
program = '_' + testcase.name + '.py'
83-
mypy_cmdline.append(program)
8478
program_path = os.path.join(test_temp_dir, program)
79+
mypy_cmdline.append(program_path)
8580
with open(program_path, 'w') as file:
8681
for s in testcase.input:
8782
file.write('{}\n'.format(s))
83+
output = []
8884
# 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"))
9192
if returncode == 0:
9293
# Execute the program.
9394
returncode, interp_out = run([interpreter, program])
94-
out += interp_out
95+
output.extend(interp_out)
9596
# Remove temp file.
9697
os.remove(program_path)
97-
assert_string_arrays_equal(adapt_output(testcase), out,
98+
assert_string_arrays_equal(adapt_output(testcase), output,
9899
'Invalid output ({}, line {})'.format(
99100
testcase.file, testcase.line))
100101

@@ -115,7 +116,7 @@ def adapt_output(testcase: DataDrivenTestCase) -> List[str]:
115116

116117

117118
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
119120
) -> Tuple[int, List[str]]:
120121
"""A poor man's subprocess.run() for 3.3 and 3.4 compatibility."""
121122
process = subprocess.Popen(

0 commit comments

Comments
 (0)