more typing work
This commit is contained in:
24
test.py
24
test.py
@@ -6,7 +6,7 @@ import importlib
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from typing import NoReturn
|
||||
from typing import Callable, NoReturn, Set
|
||||
|
||||
base = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
@@ -39,9 +39,9 @@ def find_tests_in_dir(path, excludes=('main.py',)):
|
||||
return unittest.TestSuite(suits)
|
||||
|
||||
|
||||
def filter_tests(suite, test_ok):
|
||||
def filter_tests(suite: unittest.TestSuite, test_ok: Callable[[unittest.TestCase], bool]) -> unittest.TestSuite:
|
||||
ans = unittest.TestSuite()
|
||||
added = set()
|
||||
added: Set[unittest.TestCase] = set()
|
||||
for test in itertests(suite):
|
||||
if test_ok(test) and test not in added:
|
||||
ans.addTest(test)
|
||||
@@ -49,20 +49,20 @@ def filter_tests(suite, test_ok):
|
||||
return ans
|
||||
|
||||
|
||||
def filter_tests_by_name(suite, *names):
|
||||
names = {x if x.startswith('test_') else 'test_' + x for x in names}
|
||||
def filter_tests_by_name(suite: unittest.TestSuite, *names: str) -> unittest.TestSuite:
|
||||
names_ = {x if x.startswith('test_') else 'test_' + x for x in names}
|
||||
|
||||
def q(test):
|
||||
return test._testMethodName in names
|
||||
return test._testMethodName in names_
|
||||
return filter_tests(suite, q)
|
||||
|
||||
|
||||
def filter_tests_by_module(suite, *names):
|
||||
names = frozenset(names)
|
||||
def filter_tests_by_module(suite: unittest.TestSuite, *names: str) -> unittest.TestSuite:
|
||||
names_ = frozenset(names)
|
||||
|
||||
def q(test):
|
||||
m = test.__class__.__module__.rpartition('.')[-1]
|
||||
return m in names
|
||||
return m in names_
|
||||
return filter_tests(suite, q)
|
||||
|
||||
|
||||
@@ -93,12 +93,12 @@ def run_tests():
|
||||
run_cli(tests, args.verbosity)
|
||||
|
||||
|
||||
def run_cli(suite, verbosity=4):
|
||||
def run_cli(suite: unittest.TestSuite, verbosity: int = 4) -> None:
|
||||
r = unittest.TextTestRunner
|
||||
r.resultclass = unittest.TextTestResult
|
||||
r.resultclass = unittest.TextTestResult # type: ignore
|
||||
init_env()
|
||||
runner = r(verbosity=verbosity)
|
||||
runner.tb_locals = True
|
||||
runner.tb_locals = True # type: ignore
|
||||
result = runner.run(suite)
|
||||
if not result.wasSuccessful():
|
||||
raise SystemExit(1)
|
||||
|
||||
Reference in New Issue
Block a user