Skip to content

Commit

Permalink
Move test data out of mypy/ (#1667)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnprice authored Jun 11, 2016
1 parent fa06483 commit c2eefec
Show file tree
Hide file tree
Showing 155 changed files with 13 additions and 15 deletions.
6 changes: 4 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def build(sources: List[BuildSource],

if TEST_BUILTINS in flags:
# Use stub builtins (to speed up test cases and to make them easier to
# debug).
lib_path.insert(0, os.path.join(os.path.dirname(__file__), 'test', 'data', 'lib-stub'))
# debug). This is a test-only feature, so assume our files are laid out
# as in the source tree.
root_dir = os.path.dirname(os.path.dirname(__file__))
lib_path.insert(0, os.path.join(root_dir, 'test-data', 'unit', 'lib-stub'))
else:
for source in sources:
if source.path:
Expand Down
5 changes: 3 additions & 2 deletions mypy/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import typing


PREFIX = ''
this_file_dir = os.path.dirname(os.path.realpath(__file__))
PREFIX = os.path.dirname(os.path.dirname(this_file_dir))

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

assert os.path.isdir(test_data_prefix), \
'Test data prefix ({}) not set correctly'.format(test_data_prefix)
Expand Down
3 changes: 1 addition & 2 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from mypy import defaults
from mypy.myunit import AssertionFailure
from mypy.test import config
from mypy.test.data import DataDrivenTestCase


Expand Down Expand Up @@ -191,7 +190,7 @@ def clean_up(a: List[str]) -> List[str]:
"""
res = []
for s in a:
prefix = config.PREFIX + os.sep
prefix = os.sep
ss = s
for p in prefix, prefix.replace(os.sep, '/'):
if p != '/' and p != '//' and p != '\\' and p != '\\\\':
Expand Down
4 changes: 1 addition & 3 deletions mypy/test/testparse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Tests for the mypy parser
Test case descriptions are in files test/data/parse[-errors].test."""
"""Tests for the mypy parser."""

import os.path

Expand Down
8 changes: 3 additions & 5 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def add_basic(driver: Driver) -> None:
driver.add_mypy('legacy myunit script', 'scripts/myunit')
driver.add_flake8('legacy myunit script', 'scripts/myunit')
# needs typed_ast installed:
driver.add_mypy('fast-parse', '--fast-parse', 'samples/hello.py')
driver.add_mypy('fast-parse', '--fast-parse', 'test-data/samples/hello.py')


def add_selftypecheck(driver: Driver) -> None:
Expand All @@ -182,8 +182,6 @@ def add_imports(driver: Driver) -> None:
# because of *implicit* imports from other modules.
for f in find_files('mypy', suffix='.py'):
mod = file_to_module(f)
if '.test.data.' in mod:
continue
if not mod.endswith('.__main__'):
driver.add_python_string('import %s' % mod, 'import %s' % mod)
driver.add_flake8('module %s' % mod, f)
Expand Down Expand Up @@ -235,7 +233,7 @@ def add_stubs(driver: Driver) -> None:
def add_stdlibsamples(driver: Driver) -> None:
seen = set() # type: Set[str]
for version in driver.versions:
stdlibsamples_dir = join(driver.cwd, 'stdlib-samples', version)
stdlibsamples_dir = join(driver.cwd, 'test-data', 'stdlib-samples', version)
modules = [] # type: List[str]
for f in find_files(stdlibsamples_dir, prefix='test_', suffix='.py'):
module = file_to_module(f[len(stdlibsamples_dir) + 1:])
Expand All @@ -248,7 +246,7 @@ def add_stdlibsamples(driver: Driver) -> None:


def add_samples(driver: Driver) -> None:
for f in find_files('samples', suffix='.py'):
for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'):
if 'codec' in f:
cwd, bf = os.path.dirname(f), os.path.basename(f)
bf = bf[:-len('.py')]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 99
exclude = mypy/codec/*,mypy/test/data/lib-stub/*,mypy/test/data/fixtures/*
exclude = mypy/codec/*
# Thing to ignore:
# E251: spaces around default arg value (against our style)
# E128: continuation line under-indented (too noisy)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c2eefec

Please sign in to comment.