Skip to content

Commit f83683e

Browse files
committed
Fixing Windows tests [wip]
1 parent addd9f4 commit f83683e

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

mypy/test/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def parse_test_cases(
6565
tcout = [] # type: List[str]
6666
if i < len(p) and p[i].id == 'out':
6767
tcout = p[i].data
68+
if p[i].arg == 'pathfix':
69+
tcout = [s.replace('/', os.path.sep) for s in tcout]
6870
ok = True
6971
i += 1
7072
elif optional_out:

mypy/test/data/cmdline.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ undef
1818
[file pkg/subpkg/a.py]
1919
undef
2020
import pkg.subpkg.a
21-
[out]
21+
[out pathfix]
2222
pkg/a.py:1: error: Name 'undef' is not defined
2323
pkg/subpkg/a.py:1: error: Name 'undef' is not defined
2424

@@ -31,7 +31,7 @@ undef
3131
[file pkg/subpkg/a.py]
3232
undef
3333
import pkg.subpkg.a
34-
[out]
34+
[out pathfix]
3535
pkg/a.py:1: error: Name 'undef' is not defined
3636
pkg/subpkg/a.py:1: error: Name 'undef' is not defined
3737

@@ -41,7 +41,7 @@ pkg/subpkg/a.py:1: error: Name 'undef' is not defined
4141
undef
4242
[file dir/subdir/a.py]
4343
undef
44-
[out]
44+
[out pathfix]
4545
dir/a.py:1: error: Name 'undef' is not defined
4646

4747
[case testCmdlineNonPackageSlash]
@@ -50,7 +50,7 @@ dir/a.py:1: error: Name 'undef' is not defined
5050
undef
5151
[file dir/subdir/a.py]
5252
undef
53-
[out]
53+
[out pathfix]
5454
dir/a.py:1: error: Name 'undef' is not defined
5555

5656
[case testCmdlinePackageContainingSubdir]
@@ -60,7 +60,7 @@ dir/a.py:1: error: Name 'undef' is not defined
6060
undef
6161
[file pkg/subdir/a.py]
6262
undef
63-
[out]
63+
[out pathfix]
6464
pkg/a.py:1: error: Name 'undef' is not defined
6565

6666
[case testCmdlineNonPackageContainingPackage]
@@ -71,6 +71,6 @@ import subpkg.a
7171
[file dir/subpkg/__init__.py]
7272
[file dir/subpkg/a.py]
7373
undef
74-
[out]
74+
[out pathfix]
7575
dir/subpkg/a.py:1: error: Name 'undef' is not defined
7676
dir/a.py:1: error: Name 'undef' is not defined

mypy/test/data/semanal-modules.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ import m.x
770770
[file m/__init__.py]
771771
[file m/x.py]
772772
from .x import nonexistent
773-
[out]
773+
[out pathfix]
774774
main:1: note: In module imported here:
775775
tmp/m/x.py:1: error: Module has no attribute 'nonexistent'
776776

@@ -779,7 +779,7 @@ import m.x
779779
[file m/__init__.py]
780780
[file m/x.py]
781781
from m.x import nonexistent
782-
[out]
782+
[out pathfix]
783783
main:1: note: In module imported here:
784784
tmp/m/x.py:1: error: Module has no attribute 'nonexistent'
785785

@@ -846,7 +846,7 @@ import m
846846
x
847847
[file m.py]
848848
y
849-
[out]
849+
[out pathfix]
850850
main:1: note: In module imported here:
851851
tmp/m.py:1: error: Name 'y' is not defined
852852
main:2: error: Name 'x' is not defined

mypy/test/testcheck.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def find_error_paths(self, a: List[str]) -> Set[str]:
152152
for line in a:
153153
m = re.match(r'([^\s:]+):\d+: error:', line)
154154
if m:
155-
hits.add(m.group(1))
155+
p = m.group(1).replace('/', os.path.sep)
156+
hits.add(p)
156157
return hits
157158

158159
def find_module_files(self) -> Dict[str, str]:

mypy/test/teststubgen.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,34 +108,35 @@ def test_stubgen(testcase):
108108
sys.path.insert(0, 'stubgen-test-path')
109109
os.mkdir('stubgen-test-path')
110110
source = '\n'.join(testcase.input)
111-
handle = tempfile.NamedTemporaryFile(prefix='prog_', suffix='.py', dir='stubgen-test-path')
111+
handle = tempfile.NamedTemporaryFile(prefix='prog_', suffix='.py', dir='stubgen-test-path',
112+
delete=False)
112113
assert os.path.isabs(handle.name)
113114
path = os.path.basename(handle.name)
114115
name = path[:-3]
115116
path = os.path.join('stubgen-test-path', path)
116117
out_dir = '_out'
117118
os.mkdir(out_dir)
118119
try:
119-
with open(path, 'w') as file:
120-
file.write(source)
121-
file.close()
122-
# Without this we may sometimes be unable to import the module below, as importlib
123-
# caches os.listdir() results in Python 3.3+ (Guido explained this to me).
124-
reset_importlib_caches()
125-
try:
126-
if testcase.name.endswith('_import'):
127-
generate_stub_for_module(name, out_dir, quiet=True)
128-
else:
129-
generate_stub(path, out_dir)
130-
a = load_output(out_dir)
131-
except CompileError as e:
132-
a = e.messages
133-
assert_string_arrays_equal(testcase.output, a,
134-
'Invalid output ({}, line {})'.format(
135-
testcase.file, testcase.line))
120+
handle.write(bytes(source, 'ascii'))
121+
handle.close()
122+
# Without this we may sometimes be unable to import the module below, as importlib
123+
# caches os.listdir() results in Python 3.3+ (Guido explained this to me).
124+
reset_importlib_caches()
125+
try:
126+
if testcase.name.endswith('_import'):
127+
generate_stub_for_module(name, out_dir, quiet=True)
128+
else:
129+
generate_stub(path, out_dir)
130+
a = load_output(out_dir)
131+
except CompileError as e:
132+
a = e.messages
133+
assert_string_arrays_equal(testcase.output, a,
134+
'Invalid output ({}, line {})'.format(
135+
testcase.file, testcase.line))
136136
finally:
137-
shutil.rmtree(out_dir)
138137
handle.close()
138+
os.unlink(handle.name)
139+
shutil.rmtree(out_dir)
139140

140141

141142
def reset_importlib_caches():

0 commit comments

Comments
 (0)