From 36bc0e27131edda2f3beb4b9d8be22e23d01afe3 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Mon, 2 Oct 2017 20:09:14 -0700 Subject: [PATCH 1/5] move pythoneval to check files with mypy.api --- mypy/test/testpythoneval.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index 635b99cbc0ff..f5a5a91303cc 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -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 @@ -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', @@ -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') @@ -80,21 +75,23 @@ 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) + output.extend([s.rstrip('\r\n').lstrip(test_temp_dir + os.sep) + for s in (out + err).splitlines()]) 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)) @@ -115,8 +112,8 @@ def adapt_output(testcase: DataDrivenTestCase) -> List[str]: def run( - cmdline: List[str], *, env: Optional[Dict[str, str]] = None, timeout: int = 30 -) -> Tuple[int, List[str]]: + 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( cmdline, From 658b8ae22c9277d92cbb97f5dab77c5b1dc5c854 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Mon, 2 Oct 2017 20:49:51 -0700 Subject: [PATCH 2/5] fix style check --- mypy/test/testpythoneval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index f5a5a91303cc..69ba39220763 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -113,7 +113,7 @@ def adapt_output(testcase: DataDrivenTestCase) -> List[str]: def run( cmdline: List[str], *, env: Optional[Dict[str, str]] = None, timeout: int = 300 - ) -> Tuple[int, List[str]]: +) -> Tuple[int, List[str]]: """A poor man's subprocess.run() for 3.3 and 3.4 compatibility.""" process = subprocess.Popen( cmdline, From 1d9d87e2f834bb41b9db588fe69a4202d489ba09 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Mon, 2 Oct 2017 21:13:49 -0700 Subject: [PATCH 3/5] fix testcase scrubbing --- mypy/test/testpythoneval.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index 69ba39220763..bbecf03a89d4 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -83,7 +83,8 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None: output = [] # Type check the program. out, err, returncode = api.run(mypy_cmdline) - output.extend([s.rstrip('\r\n').lstrip(test_temp_dir + os.sep) + # split lines, remove newlines, and remove directory of test case + output.extend([s.rstrip('\r\n')[len(test_temp_dir + os.sep):] for s in (out + err).splitlines()]) if returncode == 0: # Execute the program. From f15c78538cf23de909a32e240e0a4ee79d281f41 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 3 Oct 2017 09:46:39 -0700 Subject: [PATCH 4/5] Make clipping conditional --- mypy/test/testpythoneval.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index bbecf03a89d4..9d0c622e9643 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -84,8 +84,11 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None: # Type check the program. out, err, returncode = api.run(mypy_cmdline) # split lines, remove newlines, and remove directory of test case - output.extend([s.rstrip('\r\n')[len(test_temp_dir + os.sep):] - for s in (out + err).splitlines()]) + for line in out + err: + 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]) From b779f5ede3693bc37c6a1ed3f7c4d01790359ccc Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Tue, 3 Oct 2017 09:46:39 -0700 Subject: [PATCH 5/5] Make clipping conditional --- mypy/test/testpythoneval.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index bbecf03a89d4..f2710432a532 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -84,8 +84,11 @@ def test_python_evaluation(testcase: DataDrivenTestCase) -> None: # Type check the program. out, err, returncode = api.run(mypy_cmdline) # split lines, remove newlines, and remove directory of test case - output.extend([s.rstrip('\r\n')[len(test_temp_dir + os.sep):] - for s in (out + err).splitlines()]) + 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])