8000 Make tests runnable on Windows and add appveyor.yaml by gvanrossum · Pull Request #1593 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Make tests runnable on Windows and add appveyor.yaml #1593

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 4 commits into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
More subtle translation of / to \ in error messages for Windows.
(The goal is to avoid having to mark up tests just because they need
this kind of translation.)
  • Loading branch information
Guido van Rossum committed May 29, 2016
commit 48aaf7147c9030b97ec4c605732a0a99413d9dcc
23 changes: 19 additions & 4 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def parse_test_cases(
perform: Callable[['DataDrivenTestCase'], None],
base_path: str = '.',
optional_out: bool = False,
include_path: str = None) -> List['DataDrivenTestCase']:
include_path: str = None,
native_sep: bool = False) -> List['DataDrivenTestCase']:
"""Parse a file with test case descriptions.

Return an array of test cases.
Expand Down Expand Up @@ -65,8 +66,8 @@ def parse_test_cases(
tcout = [] # type: List[str]
if i < len(p) and p[i].id == 'out':
tcout = p[i].data
if p[i].arg == 'pathfix':
tcout = [s.replace('/', os.path.sep) for s in tcout]
if native_sep and os.path.sep == '\\':
tcout = [fix_win_path(line) for line in tcout]
ok = True
i += 1
elif optional_out:
Expand Down Expand Up @@ -293,7 +294,7 @@ def expand_includes(a: List[str], base_path: str) -> List[str]:
return res


def expand_errors(input, output, fnam):
def expand_errors(input: List[str], output: List[str], fnam: str) -> None:
"""Transform comments such as '# E: message' in input.

The result is lines like 'fnam:line: error: message'.
Expand All @@ -304,3 +305,17 @@ def expand_errors(input, output, fnam):
if m:
severity = 'error' if m.group(1) == 'E' else 'note'
output.append('{}:{}: {}: {}'.format(fnam, i + 1, severity, m.group(2)))


def fix_win_path(line: str) -> str:
r"""Changes paths to Windows paths in error messages.

E.g. foo/bar.py -> foo\bar.py.
"""
m = re.match(r'^([\S/]+):(\d+:)?(\s+.*)', line)
if not m:
return line
else:
filename, lineno, message = m.groups()
return '{}:{}{}'.format(filename.replace('/', '\\'),
lineno or '', message)
12 changes: 6 additions & 6 deletions mypy/test/data/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ undef
[file pkg/subpkg/a.py]
undef
import pkg.subpkg.a
[out pathfix]
[out]
pkg/a.py:1: error: Name 'undef' is not defined
pkg/subpkg/a.py:1: error: Name 'undef' is not defined

Expand All @@ -31,7 +31,7 @@ undef
[file pkg/subpkg/a.py]
undef
import pkg.subpkg.a
[out pathfix]
[out]
pkg/a.py:1: error: Name 'undef' is not defined
pkg/subpkg/a.py:1: error: Name 'undef' is not defined

Expand All @@ -41,7 +41,7 @@ pkg/subpkg/a.py:1: error: Name 'undef' is not defined
undef
[file dir/subdir/a.py]
undef
[out pathfix]
[out]
dir/a.py:1: error: Name 'undef' is not defined

[case testCmdlineNonPackageSlash]
Expand All @@ -50,7 +50,7 @@ dir/a.py:1: error: Name 'undef' is not defined
undef
[file dir/subdir/a.py]
undef
[out pathfix]
[out]
dir/a.py:1: error: Name 'undef' is not defined

[case testCmdlinePackageContainingSubdir]
Expand All @@ -60,7 +60,7 @@ dir/a.py:1: error: Name 'undef' is not defined
undef
[file pkg/subdir/a.py]
undef
[out pathfix]
[out]
pkg/a.py:1: error: Name 'undef' is not defined

[case testCmdlineNonPackageContainingPackage]
Expand All @@ -71,6 +71,6 @@ import subpkg.a
[file dir/subpkg/__init__.py]
[file dir/subpkg/a.py]
undef
[out pathfix]
[out]
dir/subpkg/a.py:1: error: Name 'undef' is not defined
dir/a.py:1: error: Name 'undef' is not defined
6 changes: 3 additions & 3 deletions mypy/test/data/semanal-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ import m.x
[file m/__init__.py]
[file m/x.py]
from .x import nonexistent
[out pathfix]
[out]
main:1: note: In module imported here:
tmp/m/x.py:1: error: Module has no attribute 'nonexistent'

Expand All @@ -779,7 +779,7 @@ import m.x
[file m/__init__.py]
[file m/x.py]
from m.x import nonexistent
[out pathfix]
[out]
main:1: note: In module imported here:
tmp/m/x.py:1: error: Module has no attribute 'nonexistent'

Expand Down Expand Up @@ -846,7 +846,7 @@ import m
x
[file m.py]
y
[out pathfix]
[out]
main:1: note: In module imported here:
tmp/m.py:1: error: Name 'y' is not defined
main:2: error: Name 'x' is not defined
Expand Down
ED48
5 changes: 4 additions & 1 deletion mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def cases(self) -> List[DataDrivenTestCase]:
c = [] # type: List[DataDrivenTestCase]
for f in cmdline_files:
c += parse_test_cases(os.path.join(test_data_prefix, f),
test_python_evaluation, test_temp_dir, True)
test_python_evaluation,
base_path=test_temp_dir,
optional_out=True,
native_sep=True)
return c


Expand Down
5 changes: 4 additions & 1 deletion mypy/test/testsemanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def cases(self):
c = []
for f in semanal_files:
c += parse_test_cases(os.path.join(test_data_prefix, f),
test_semanal, test_temp_dir, optional_out=True)
test_semanal,
base_path=test_temp_dir,
optional_out=True,
native_sep=True)
return c


Expand Down
4 changes: 3 additions & 1 deletion mypy/test/testtransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def cases(self):
c = []
for f in self.transform_files:
c += parse_test_cases(os.path.join(test_data_prefix, f),
test_transform, test_temp_dir)
test_transform,
base_path=test_temp_dir,
native_sep=True)
return c


Expand Down
0