disable globbing for tests folders, add regex support for ignored errors

This commit is contained in:
Maxim Kurnikov
2019-01-29 20:06:40 +03:00
parent f07a9ecbb8
commit ece2b87318

View File

@@ -1,8 +1,9 @@
import glob
import os import os
import re
import sys import sys
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path from pathlib import Path
from typing import Pattern
from git import Repo from git import Repo
from mypy import build from mypy import build
@@ -19,13 +20,13 @@ IGNORED_ERROR_PATTERNS = [
'LazySettings', 'LazySettings',
'Cannot infer type of lambda', 'Cannot infer type of lambda',
'Incompatible types in assignment (expression has type "Callable[', 'Incompatible types in assignment (expression has type "Callable[',
'"Callable[[Any], Any]" has no attribute',
'"Callable[[Any, Any], Any]" has no attribute',
'Invalid value for a to= parameter', 'Invalid value for a to= parameter',
'"HttpResponseBase" has no attribute "user"' re.compile(r'"Callable\[\[(Any(, )?)+\], Any\]" has no attribute'),
re.compile(r'"HttpResponseBase" has no attribute "[A-Za-z_]+"'),
] ]
TESTS_DIRS = [ TESTS_DIRS = [
'absolute_url_overrides', 'absolute_url_overrides',
'admin_autodiscover'
] ]
@@ -46,6 +47,10 @@ def cd(path):
def is_ignored(line: str) -> bool: def is_ignored(line: str) -> bool:
for pattern in IGNORED_ERROR_PATTERNS: for pattern in IGNORED_ERROR_PATTERNS:
if isinstance(pattern, Pattern):
if pattern.search(line):
return True
else:
if pattern in line: if pattern in line:
return True return True
return False return False
@@ -79,11 +84,9 @@ if __name__ == '__main__':
repo.git.checkout(DJANGO_COMMIT_SHA) repo.git.checkout(DJANGO_COMMIT_SHA)
for dirname in TESTS_DIRS: for dirname in TESTS_DIRS:
paths = glob.glob(str(tests_root / dirname)) abs_path = (project_directory / tests_root / dirname).absolute()
for path in paths:
abs_path = (project_directory / path).absolute()
print(f'Checking {abs_path.as_uri()}') print(f'Checking {abs_path.as_uri()}')
rc = check_with_mypy(abs_path, mypy_config_file) rc = check_with_mypy(abs_path, mypy_config_file)
if rc != 0: if rc != 0:
global_rc = 1 global_rc = 1