add basic test infrastructure

This commit is contained in:
Maxim Kurnikov
2018-11-10 16:56:38 +03:00
parent ab14ccbbc1
commit 1016ece491
4 changed files with 67 additions and 0 deletions

3
conftest.py Normal file
View File

@@ -0,0 +1,3 @@
pytest_plugins = [
'mypy.test.data'
]

7
pytest.ini Normal file
View File

@@ -0,0 +1,7 @@
[pytest]
testpaths = test
python_files = test*.py
addopts =
-nauto
--tb=native

View File

@@ -0,0 +1,9 @@
[case testBasicCheck]
from typing import Any
class A:
pass
class B(A):
pass
[out]

48
test/testdjango.py Normal file
View File

@@ -0,0 +1,48 @@
import os
import sys
from pathlib import Path
from mypy import api
from mypy.test.config import test_temp_dir
from mypy.test.data import DataSuite, DataDrivenTestCase
from mypy.test.helpers import assert_string_arrays_equal
ROOT_DIR = Path(__file__).parent.parent
TEST_DATA_DIR = ROOT_DIR / 'test' / 'test-data'
class DjangoTestSuite(DataSuite):
files = [
'basic-check.test'
]
data_prefix = str(TEST_DATA_DIR)
def run_case(self, testcase: DataDrivenTestCase) -> None:
assert testcase.old_cwd is not None, "test was not properly set up"
mypy_cmdline = []
mypy_cmdline.append('--python-version={}'.format('.'.join(map(str,
sys.version_info[:2]))))
program_path = os.path.join(test_temp_dir, 'main.py')
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.
out, err, returncode = api.run(mypy_cmdline)
# split lines, remove newlines, and remove directory of test case
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").replace('.py', ''))
else:
output.append(line.rstrip("\r\n"))
# Remove temp file.
os.remove(program_path)
assert_string_arrays_equal(testcase.output, output,
'Invalid output ({}, line {})'.format(
testcase.file, testcase.line))