Add Django 3.0 testing to CI (#246)

* add Django 3.0 testing to CI

* remove importlib_metadata usage

* conditionally load choices module for tests
This commit is contained in:
Maksim Kurnikov
2019-12-06 23:36:24 +03:00
committed by GitHub
parent cadd6c963b
commit 4ac43c6ed6
18 changed files with 125 additions and 34 deletions

View File

@@ -1,3 +1,5 @@
import django
SECRET_KEY = '1'
SITE_ID = 1
@@ -41,7 +43,6 @@ test_modules = [
'bulk_create',
'cache',
'check_framework',
'choices',
'conditional_processing',
'constraints',
'contenttypes_tests',
@@ -219,6 +220,9 @@ test_modules = [
'wsgi',
]
if django.VERSION[0] == 2:
test_modules += ['choices']
invalid_apps = {
'import_error_package',
}

View File

@@ -264,6 +264,8 @@ IGNORED_ERRORS = {
'Incompatible types in assignment (expression has type "Type[Person',
'Incompatible types in assignment (expression has type "FloatModel", variable has type',
'"ImageFile" has no attribute "was_opened"',
'Incompatible type for "size" of "FloatModel" (got "object", expected "Union[float, int, str, Combinable]")',
'Incompatible type for "value" of "IntegerModel" (got "object", expected',
],
'model_indexes': [
'Argument "condition" to "Index" has incompatible type "str"; expected "Optional[Q]"'
@@ -291,6 +293,9 @@ IGNORED_ERRORS = {
'model_options': [
'expression has type "Dict[str, Type[Model]]", target has type "OrderedDict',
],
'model_enums': [
"'bool' is not a valid base class",
],
'multiple_database': [
'Unexpected attribute "extra_arg" for model "Book"'
],
@@ -341,12 +346,14 @@ IGNORED_ERRORS = {
'"Collection[Any]" has no attribute "explain"',
"Cannot resolve keyword 'unknown_field' into field",
'Incompatible type for lookup \'tag\': (got "str", expected "Union[Tag, int, None]")',
'No overload variant of "__getitem__" of "QuerySet" matches argument type "str"',
],
'requests': [
'Incompatible types in assignment (expression has type "Dict[str, str]", variable has type "QueryDict")'
],
'responses': [
'Argument 1 to "TextIOWrapper" has incompatible type "HttpResponse"; expected "IO[bytes]"'
'Argument 1 to "TextIOWrapper" has incompatible type "HttpResponse"; expected "IO[bytes]"',
'"FileLike" has no attribute "closed"',
],
'reverse_lookup': [
"Cannot resolve keyword 'choice' into field"
@@ -424,6 +431,7 @@ IGNORED_ERRORS = {
'"WSGIRequest" has no attribute "process_response_content"',
'No overload variant of "join" matches argument types "str", "None"',
'Argument 1 to "Archive" has incompatible type "None"; expected "str"',
'Argument 1 to "to_path" has incompatible type "int"; expected "Union[Path, str]"',
],
'view_tests': [
@@ -431,10 +439,15 @@ IGNORED_ERRORS = {
'Value of type "Optional[List[str]]" is not indexable',
'ExceptionUser',
'view_tests.tests.test_debug.User',
'Exception must be derived from BaseException',
"No binding for nonlocal 'tb_frames' found",
],
'validation': [
'has no attribute "name"',
],
'wsgi': [
'"HttpResponse" has no attribute "block_size"',
],
}

View File

@@ -2,15 +2,23 @@ import itertools
import shutil
import subprocess
import sys
from argparse import ArgumentParser
from collections import defaultdict
from pathlib import Path
from typing import Dict, List, Pattern, Union
from git import Repo
from scripts.enabled_test_modules import (
EXTERNAL_MODULES, IGNORED_ERRORS, IGNORED_MODULES, MOCK_OBJECTS,
)
DJANGO_COMMIT_REFS = {
'2.2': 'e8b0903976077b951795938b260211214ed7fe41',
'3.0': '7ec5962638144cbf4c2e47ea7d8dc02d1ce44394'
}
PROJECT_DIRECTORY = Path(__file__).parent.parent
DJANGO_SOURCE_DIRECTORY = PROJECT_DIRECTORY / 'django-sources' # type: Path
def get_unused_ignores(ignored_message_freq: Dict[str, Dict[Union[str, Pattern], int]]) -> List[str]:
@@ -67,11 +75,29 @@ def replace_with_clickable_location(error: str, abs_test_folder: Path) -> str:
return error.replace(raw_path, clickable_location)
def get_django_repo_object() -> Repo:
if not DJANGO_SOURCE_DIRECTORY.exists():
DJANGO_SOURCE_DIRECTORY.mkdir(exist_ok=True, parents=False)
return Repo.clone_from('https://github.com/django/django.git', DJANGO_SOURCE_DIRECTORY)
else:
repo = Repo(DJANGO_SOURCE_DIRECTORY)
return repo
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--django_version', choices=['2.2', '3.0'], required=True)
args = parser.parse_args()
commit_sha = DJANGO_COMMIT_REFS[args.django_version]
repo = get_django_repo_object()
if repo.head.commit.hexsha != commit_sha:
repo.git.fetch('origin')
repo.git.checkout(commit_sha)
mypy_config_file = (PROJECT_DIRECTORY / 'scripts' / 'mypy.ini').absolute()
repo_directory = PROJECT_DIRECTORY / 'django-sources'
mypy_cache_dir = Path(__file__).parent / '.mypy_cache'
tests_root = repo_directory / 'tests'
tests_root = DJANGO_SOURCE_DIRECTORY / 'tests'
global_rc = 0
try: