Skip to content

Commit c2eefec

Browse files
authored
Move test data out of mypy/ (#1667)
This makes it easier to grep through our codebase to find things quickly without getting noise from matches in our tests -- after all, our test data naturally has a lot of Python code, just like mypy itself. #compilerworldproblems Specifically, move what was mypy/test/data/ inside a new directory test-data/. While we're at it, tuck samples/ and stdlib-samples/ under test-data/ too. This is probably still not the perfect layout (e.g., does stdlib-samples/ need to be special, or can it just be more samples organized into a directory under samples/?), but with all the file moves in this commit I wanted to keep the necessary logic changes to an absolute minimum for ease of reading and reviewing. The `-M` flag to `git show/diff/log` is highly recommended when looking at this commit.
1 parent fa06483 commit c2eefec

File tree

155 files changed

+13
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+13
-15
lines changed

mypy/build.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ def build(sources: List[BuildSource],
169169

170170
if TEST_BUILTINS in flags:
171171
# Use stub builtins (to speed up test cases and to make them easier to
172-
# debug).
173-
lib_path.insert(0, os.path.join(os.path.dirname(__file__), 'test', 'data', 'lib-stub'))
172+
# debug). This is a test-only feature, so assume our files are laid out
173+
# as in the source tree.
174+
root_dir = os.path.dirname(os.path.dirname(__file__))
175+
lib_path.insert(0, os.path.join(root_dir, 'test-data', 'unit', 'lib-stub'))
174176
else:
175177
for source in sources:
176178
if source.path:

mypy/test/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import typing
55

66

7-
PREFIX = ''
7+
this_file_dir = os.path.dirname(os.path.realpath(__file__))
8+
PREFIX = os.path.dirname(os.path.dirname(this_file_dir))
89

910
# Location of test data files such as test case descriptions.
10-
test_data_prefix = os.path.join(PREFIX, 'mypy', 'test', 'data')
11+
test_data_prefix = os.path.join(PREFIX, 'test-data', 'unit')
1112

1213
assert os.path.isdir(test_data_prefix), \
1314
'Test data prefix ({}) not set correctly'.format(test_data_prefix)

mypy/test/helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from mypy import defaults
88
from mypy.myunit import AssertionFailure
9-
from mypy.test import config
109
from mypy.test.data import DataDrivenTestCase
1110

1211

@@ -191,7 +190,7 @@ def clean_up(a: List[str]) -> List[str]:
191190
"""
192191
res = []
193192
for s in a:
194-
prefix = config.PREFIX + os.sep
193+
prefix = os.sep
195194
ss = s
196195
for p in prefix, prefix.replace(os.sep, '/'):
197196
if p != '/' and p != '//' and p != '\\' and p != '\\\\':

mypy/test/testparse.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""Tests for the mypy parser
2-
3-
Test case descriptions are in files test/data/parse[-errors].test."""
1+
"""Tests for the mypy parser."""
42

53
import os.path
64

runtests.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def add_basic(driver: Driver) -> None:
155155
driver.add_mypy('legacy myunit script', 'scripts/myunit')
156156
driver.add_flake8('legacy myunit script', 'scripts/myunit')
157157
# needs typed_ast installed:
158-
driver.add_mypy('fast-parse', '--fast-parse', 'samples/hello.py')
158+
driver.add_mypy('fast-parse', '--fast-parse', 'test-data/samples/hello.py')
159159

160160

161161
def add_selftypecheck(driver: Driver) -> None:
@@ -182,8 +182,6 @@ def add_imports(driver: Driver) -> None:
182182
# because of *implicit* imports from other modules.
183183
for f in find_files('mypy', suffix='.py'):
184184
mod = file_to_module(f)
185-
if '.test.data.' in mod:
186-
continue
187185
if not mod.endswith('.__main__'):
188186
driver.add_python_string('import %s' % mod, 'import %s' % mod)
189187
driver.add_flake8('module %s' % mod, f)
@@ -235,7 +233,7 @@ def add_stubs(driver: Driver) -> None:
235233
def add_stdlibsamples(driver: Driver) -> None:
236234
seen = set() # type: Set[str]
237235
for version in driver.versions:
238-
stdlibsamples_dir = join(driver.cwd, 'stdlib-samples', version)
236+
stdlibsamples_dir = join(driver.cwd, 'test-data', 'stdlib-samples', version)
239237
modules = [] # type: List[str]
240238
for f in find_files(stdlibsamples_dir, prefix='test_', suffix='.py'):
241239
module = file_to_module(f[len(stdlibsamples_dir) + 1:])
@@ -248,7 +246,7 @@ def add_stdlibsamples(driver: Driver) -> None:
248246

249247

250248
def add_samples(driver: Driver) -> None:
251-
for f in find_files('samples', suffix='.py'):
249+
for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'):
252250
if 'codec' in f:
253251
cwd, bf = os.path.dirname(f), os.path.basename(f)
254252
bf = bf[:-len('.py')]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
max-line-length = 99
3-
exclude = mypy/codec/*,mypy/test/data/lib-stub/*,mypy/test/data/fixtures/*
3+
exclude = mypy/codec/*
44
# Thing to ignore:
55
# E251: spaces around default arg value (against our style)
66
# E128: continuation line under-indented (too noisy)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)