Skip to content

Commit 874d67e

Browse files
elazargilevkivskyi
authored andcommitted
cleanup runtests (#5011)
1 parent e85c78e commit 874d67e

File tree

2 files changed

+13
-98
lines changed

2 files changed

+13
-98
lines changed

runtests.py

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/usr/bin/env python3
22
"""Mypy test runner."""
33

4-
from typing import Dict, List, Optional, Set, Iterable, Tuple
5-
6-
from mypy.waiter import Waiter, LazySubprocess
7-
from mypy import util
4+
from typing import List, Optional, Set, Iterable, Tuple
85

96
import itertools
107
import os
118
from os.path import join, isdir
129
import sys
1310

11+
from waiter import Waiter, LazySubprocess
12+
1413

15-
def get_versions(): # type: () -> List[str]
14+
def get_versions() -> List[str]:
1615
major = sys.version_info[0]
1716
minor = sys.version_info[1]
1817
if major == 2:
@@ -24,9 +23,6 @@ def get_versions(): # type: () -> List[str]
2423
return ['%d.%d' % (major, i) for i in range(minor, -1, -1)]
2524

2625

27-
# Ideally, all tests would be `discover`able so that they can be driven
28-
# (and parallelized) by an external test driver.
29-
3026
class Driver:
3127

3228
def __init__(self, *, whitelist: List[str], blacklist: List[str],
@@ -88,9 +84,6 @@ def add_mypy_modules(self, name: str, modules: Iterable[str], cwd: Optional[str]
8884
def add_mypy_package(self, name: str, packagename: str, *flags: str) -> None:
8985
self.add_mypy_cmd(name, ['-p', packagename] + list(flags))
9086

91-
def add_mypy_string(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
92-
self.add_mypy_cmd(name, ['-c'] + list(args), cwd=cwd)
93-
9487
def add_pytest(self, files: List[Tuple[str, str]], coverage: bool = True) -> None:
9588
pytest_files = [name for kind, name in files
9689
if self.allow('pytest {} {}'.format(kind, name))]
@@ -106,48 +99,6 @@ def add_pytest(self, files: List[Tuple[str, str]], coverage: bool = True) -> Non
10699
passthrough=self.verbosity),
107100
sequential=True)
108101

109-
def add_python(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
110-
name = 'run %s' % name
111-
if not self.allow(name):
112-
return
113-
largs = list(args)
114-
largs[0:0] = [sys.executable]
115-
env = self.env
116-
self.waiter.add(LazySubprocess(name, largs, cwd=cwd, env=env))
117-
118-
def add_python_mod(self, name: str, *args: str, cwd: Optional[str] = None,
119-
coverage: bool = False) -> None:
120-
name = 'run %s' % name
121-
if not self.allow(name):
122-
return
123-
largs = list(args)
124-
if coverage and self.coverage:
125-
largs[0:0] = ['coverage', 'run', '-m']
126-
else:
127-
largs[0:0] = [sys.executable, '-m']
128-
env = self.env
129-
self.waiter.add(LazySubprocess(name, largs, cwd=cwd, env=env))
130-
131-
def add_python_string(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
132-
name = 'run %s' % name
133-
if not self.allow(name):
134-
return
135-
largs = list(args)
136-
largs[0:0] = [sys.executable, '-c']
137-
env = self.env
138-
self.waiter.add(LazySubprocess(name, largs, cwd=cwd, env=env))
139-
140-
def add_python2(self, name: str, *args: str, cwd: Optional[str] = None) -> None:
141-
name = 'run2 %s' % name
142-
if not self.allow(name):
143-
return
144-
largs = list(args)
145-
python2 = util.try_find_python2_interpreter()
146-
assert python2, "Couldn't find a Python 2.7 interpreter"
147-
largs[0:0] = [python2]
148-
env = self.env
149-
self.waiter.add(LazySubprocess(name, largs, cwd=cwd, env=env))
150-
151102
def add_flake8(self, cwd: Optional[str] = None) -> None:
152103
name = 'lint'
153104
if not self.allow(name):
@@ -161,16 +112,9 @@ def list_tasks(self) -> None:
161112
print('{id}:{task}'.format(id=id, task=task.name))
162113

163114

164-
def add_basic(driver: Driver) -> None:
165-
if False:
166-
driver.add_mypy('file setup.py', 'setup.py')
167-
driver.add_mypy('file runtests.py', 'runtests.py')
168-
driver.add_mypy('legacy entry script', 'scripts/mypy')
169-
# needs typed_ast installed:
170-
driver.add_mypy('fast-parse', '--fast-parse', 'test-data/samples/hello.py')
171-
172-
173115
def add_selftypecheck(driver: Driver) -> None:
116+
driver.add_mypy('file runtests.py', 'runtests.py')
117+
driver.add_mypy('file waiter.py', 'waiter.py')
174118
driver.add_mypy_package('package mypy', 'mypy', '--config-file', 'mypy_self_check.ini')
175119

176120

@@ -188,16 +132,6 @@ def file_to_module(file: str) -> str:
188132
return rv
189133

190134

191-
def add_imports(driver: Driver) -> None:
192-
# Make sure each module can be imported originally.
193-
# There is currently a bug in mypy where a module can pass typecheck
194-
# because of *implicit* imports from other modules.
195-
for f in find_files('mypy', suffix='.py'):
196-
mod = file_to_module(f)
197-
if not mod.endswith('.__main__'):
198-
driver.add_python_string('import %s' % mod, 'import %s' % mod)
199-
200-
201135
def test_path(*names: str):
202136
return [os.path.join('mypy', 'test', '{}.py'.format(name))
203137
for name in names]
@@ -235,11 +169,10 @@ def test_path(*names: str):
235169
'teststubgen',
236170
)
237171

238-
for f in find_files('mypy', prefix='test', suffix='.py'):
239-
assert f in PYTEST_FILES + SLOW_FILES, f
240-
241172

242173
def add_pytest(driver: Driver) -> None:
174+
for f in find_files('mypy', prefix='test', suffix='.py'):
175+
assert f in PYTEST_FILES + SLOW_FILES, f
243176
driver.add_pytest([('unit-test', name) for name in PYTEST_FILES] +
244177
[('integration', name) for name in SLOW_FILES])
245178

@@ -248,8 +181,7 @@ def add_stubs(driver: Driver) -> None:
248181
# We only test each module in the one version mypy prefers to find.
249182
# TODO: test stubs for other versions, especially Python 2 stubs.
250183

251-
modules = set() # type: Set[str]
252-
modules.add('typing')
184+
modules = {'typing'}
253185
# TODO: This should also test Python 2, and pass pyversion accordingly.
254186
for version in ["2and3", "3", "3.3", "3.4", "3.5"]:
255187
for stub_type in ['builtins', 'stdlib', 'third_party']:
@@ -280,12 +212,11 @@ def add_stdlibsamples(driver: Driver) -> None:
280212

281213
def add_samples(driver: Driver) -> None:
282214
for f in find_files(os.path.join('test-data', 'samples'), suffix='.py'):
215+
mypy_args = ['--no-strict-optional']
283216
if f == os.path.join('test-data', 'samples', 'crawl2.py'):
284217
# This test requires 3.5 for async functions
285-
driver.add_mypy_cmd('file {}'.format(f), ['--python-version=3.5',
286-
'--no-strict-optional', f])
287-
else:
288-
driver.add_mypy('file %s' % f, '--no-strict-optional', f)
218+
mypy_args.append('--python-version=3.5')
219+
driver.add_mypy_cmd('file {}'.format(f), mypy_args + [f])
289220

290221

291222
def usage(status: int) -> None:
@@ -425,9 +356,7 @@ def main() -> None:
425356

426357
driver.add_flake8()
427358
add_pytest(driver)
428-
add_basic(driver)
429359
add_selftypecheck(driver)
430-
add_imports(driver)
431360
add_stubs(driver)
432361
add_stdlibsamples(driver)
433362
add_samples(driver)

mypy/waiter.py renamed to waiter.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@
99
from multiprocessing import cpu_count
1010
import pipes
1111
import re
12-
from subprocess import Popen, STDOUT, DEVNULL
12+
from subprocess import Popen, STDOUT
1313
import sys
1414
import tempfile
1515
import time
1616
import json
1717
from collections import defaultdict
1818

1919

20-
class WaiterError(Exception):
21-
pass
22-
23-
2420
class LazySubprocess:
2521
"""Wrapper around a subprocess that runs a test task."""
2622

@@ -401,16 +397,6 @@ def parse_test_stats_from_output(output: str, fail_type: Optional[str]) -> Tuple
401397
return (sum(c for k, c in counts.items() if k != 'deselected'),
402398
counts.get('failed', 0))
403399

404-
# myunit
405-
m = re.search('^([0-9]+)/([0-9]+) test cases failed(, ([0-9]+) skipped)?.$', output,
406-
re.MULTILINE)
407-
if m:
408-
return int(m.group(2)), int(m.group(1))
409-
m = re.search('^([0-9]+) test cases run(, ([0-9]+) skipped)?, all passed.$', output,
410-
re.MULTILINE)
411-
if m:
412-
return int(m.group(1)), 0
413-
414400
# Couldn't find test counts, so fall back to single test per tasks.
415401
if fail_type is not None:
416402
return 1, 1

0 commit comments

Comments
 (0)