Skip to content

Move pythoneval to mypy.api and increase timeout #4047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
this suite would slow down the main suite too much.
"""

from contextlib import contextmanager
import errno
import os
import os.path
import re
Expand All @@ -25,6 +23,7 @@
from mypy.test.data import DataDrivenTestCase, parse_test_cases, DataSuite
from mypy.test.helpers import assert_string_arrays_equal
from mypy.util import try_find_python2_interpreter
from mypy import api

# Files which contain test case descriptions.
python_eval_files = ['pythoneval.test',
Expand Down Expand Up @@ -61,11 +60,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:
version.
"""
assert testcase.old_cwd is not None, "test was not properly set up"
mypy_cmdline = [
python3_path,
os.path.join(testcase.old_cwd, 'scripts', 'mypy'),
'--show-traceback',
]
mypy_cmdline = ['--show-traceback']
py2 = testcase.name.lower().endswith('python2')
if py2:
mypy_cmdline.append('--py2')
Expand All @@ -80,21 +75,27 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None:

# Write the program to a file.
program = '_' + testcase.name + '.py'
mypy_cmdline.append(program)
program_path = os.path.join(test_temp_dir, program)
mypy_cmdline.append(program_path)
with open(program_path, 'w') as file:
for s in testcase.input:
file.write('{}\n'.format(s))
output = []
# Type check the program.
# This uses the same PYTHONPATH as the current process.
returncode, out = run(mypy_cmdline)
out, err, returncode = api.run(mypy_cmdline)
# split lines, remove newlines, and remove directory of test case
for line in (out + err).splitlines():
if line.startswith(test_temp_dir + os.sep):
output.append(line[len(test_temp_dir + os.sep):].rstrip("\r\n"))
else:
output.append(line.rstrip("\r\n"))
if returncode == 0:
# Execute the program.
returncode, interp_out = run([interpreter, program])
out += interp_out
output.extend(interp_out)
# Remove temp file.
os.remove(program_path)
assert_string_arrays_equal(adapt_output(testcase), out,
assert_string_arrays_equal(adapt_output(testcase), output,
'Invalid output ({}, line {})'.format(
testcase.file, testcase.line))

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


def run(
cmdline: List[str], *, env: Optional[Dict[str, str]] = None, timeout: int = 30
cmdline: List[str], *, env: Optional[Dict[str, str]] = None, timeout: int = 300
) -> Tuple[int, List[str]]:
"""A poor man's subprocess.run() for 3.3 and 3.4 compatibility."""
process = subprocess.Popen(
Expand Down