1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Refs #23919 -- Removed django.test.mock Python 2 compatibility shim.

This commit is contained in:
Tim Graham 2017-01-19 12:16:04 -05:00
parent 042b7350a0
commit 7aba69145d
49 changed files with 97 additions and 81 deletions

View File

@ -18,12 +18,3 @@ __all__ = [
'skipUnlessAnyDBFeature', 'skipUnlessDBFeature', 'ignore_warnings',
'modify_settings', 'override_settings', 'override_system_checks', 'tag',
]
# To simplify Django's test suite; not meant as a public API
try:
from unittest import mock # NOQA
except ImportError:
try:
import mock # NOQA
except ImportError:
pass

View File

@ -13,6 +13,7 @@ import sys
import tempfile
import unittest
from io import StringIO
from unittest import mock
import django
from django import conf, get_version
@ -24,7 +25,7 @@ from django.db import ConnectionHandler
from django.db.migrations.exceptions import MigrationSchemaMissing
from django.db.migrations.recorder import MigrationRecorder
from django.test import (
LiveServerTestCase, SimpleTestCase, TestCase, mock, override_settings,
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
)
from django.utils.encoding import force_text

View File

@ -1,8 +1,10 @@
from unittest import mock
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.models import User
from django.db import connections
from django.test import TestCase, mock, override_settings
from django.test import TestCase, override_settings
from django.urls import reverse
from .models import Book

View File

@ -1,9 +1,11 @@
from unittest import mock
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.db import connections
from django.test import TestCase, mock, override_settings
from django.test import TestCase, override_settings
from django.urls import reverse

View File

@ -1,4 +1,5 @@
from datetime import date
from unittest import mock
from django.contrib.auth import (
BACKEND_SESSION_KEY, SESSION_KEY, authenticate, get_user, signals,
@ -10,7 +11,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpRequest
from django.test import (
SimpleTestCase, TestCase, mock, modify_settings, override_settings,
SimpleTestCase, TestCase, modify_settings, override_settings,
)
from .models import (

View File

@ -1,5 +1,6 @@
import datetime
import re
from unittest import mock
from django import forms
from django.contrib.auth.forms import (
@ -13,7 +14,7 @@ from django.contrib.sites.models import Site
from django.core import mail
from django.core.mail import EmailMultiAlternatives
from django.forms.fields import CharField, Field, IntegerField
from django.test import SimpleTestCase, TestCase, mock, override_settings
from django.test import SimpleTestCase, TestCase, override_settings
from django.utils import translation
from django.utils.encoding import force_text
from django.utils.text import capfirst

View File

@ -1,4 +1,4 @@
from unittest import skipUnless
from unittest import mock, skipUnless
from django.conf.global_settings import PASSWORD_HASHERS
from django.contrib.auth.hashers import (
@ -7,7 +7,7 @@ from django.contrib.auth.hashers import (
check_password, get_hasher, identify_hasher, is_password_usable,
make_password,
)
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
from django.test.utils import override_settings
from django.utils.encoding import force_bytes

View File

@ -2,6 +2,7 @@ import builtins
import sys
from datetime import date
from io import StringIO
from unittest import mock
from django.apps import apps
from django.contrib.auth import management
@ -14,7 +15,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.management import call_command
from django.core.management.base import CommandError
from django.db import migrations
from django.test import TestCase, mock, override_settings
from django.test import TestCase, override_settings
from django.utils.translation import ugettext_lazy as _
from .models import (

View File

@ -1,3 +1,5 @@
from unittest import mock
from django.contrib.auth import models
from django.contrib.auth.mixins import (
LoginRequiredMixin, PermissionRequiredMixin, UserPassesTestMixin,
@ -5,7 +7,7 @@ from django.contrib.auth.mixins import (
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.test import RequestFactory, TestCase, mock
from django.test import RequestFactory, TestCase
from django.views.generic import View

View File

@ -1,3 +1,5 @@
from unittest import mock
from django.conf.global_settings import PASSWORD_HASHERS
from django.contrib.auth import get_user_model
from django.contrib.auth.base_user import AbstractBaseUser
@ -8,7 +10,7 @@ from django.contrib.auth.models import (
from django.contrib.contenttypes.models import ContentType
from django.core import mail
from django.db.models.signals import post_save
from django.test import TestCase, mock, override_settings
from django.test import TestCase, override_settings
from .models.with_custom_email_field import CustomEmailField

View File

@ -1,7 +1,7 @@
from unittest import skipUnless
from unittest import mock, skipUnless
from django.db import connection
from django.test import TestCase, mock
from django.test import TestCase
class TestDatabaseFeatures(TestCase):

View File

@ -5,6 +5,7 @@ import threading
import unittest
import warnings
from decimal import Decimal, Rounded
from unittest import mock
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import no_style
@ -20,7 +21,7 @@ from django.db.models import Avg, StdDev, Sum, Variance
from django.db.models.sql.constants import CURSOR
from django.db.utils import ConnectionHandler
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings,
SimpleTestCase, TestCase, TransactionTestCase, override_settings,
skipIfDBFeature, skipUnlessDBFeature,
)

View File

@ -11,6 +11,7 @@ import threading
import time
import unittest
import warnings
from unittest import mock
from django.conf import settings
from django.core import management, signals
@ -31,7 +32,7 @@ from django.template.context_processors import csrf
from django.template.response import TemplateResponse
from django.test import (
RequestFactory, SimpleTestCase, TestCase, TransactionTestCase,
ignore_warnings, mock, override_settings,
ignore_warnings, override_settings,
)
from django.test.signals import setting_changed
from django.utils import timezone, translation

View File

@ -1,9 +1,10 @@
import unittest
from unittest import mock
from django.core.checks import Tags, run_checks
from django.core.checks.registry import CheckRegistry
from django.db import connection
from django.test import TestCase, mock
from django.test import TestCase
class DatabaseCheckTests(TestCase):

View File

@ -1,5 +1,7 @@
from unittest import mock
from django.db import connections, models
from django.test import TestCase, mock
from django.test import TestCase
from django.test.utils import isolate_apps, override_settings

View File

@ -1,4 +1,5 @@
import datetime
from unittest import mock
from django.apps.registry import Apps, apps
from django.conf import settings
@ -12,7 +13,7 @@ from django.core import checks, management
from django.core.management import call_command
from django.db import connections, migrations, models
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings,
SimpleTestCase, TestCase, TransactionTestCase, override_settings,
)
from django.test.utils import captured_stdout, isolate_apps
from django.utils.encoding import force_text

View File

@ -1,7 +1,8 @@
import os
from unittest import mock
from django.db.backends.postgresql.client import DatabaseClient
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
class PostgreSqlDbshellCommandTestCase(SimpleTestCase):

View File

@ -4,13 +4,13 @@ import struct
import tempfile
import unittest
from io import BytesIO, StringIO, TextIOWrapper
from unittest import mock
from django.core.files import File
from django.core.files.base import ContentFile
from django.core.files.move import file_move_safe
from django.core.files.temp import NamedTemporaryFile
from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile
from django.test import mock
try:
from PIL import Image

View File

@ -4,6 +4,7 @@ import tempfile
import unittest
import warnings
from io import StringIO
from unittest import mock
from django.apps import apps
from django.contrib.sites.models import Site
@ -13,9 +14,7 @@ from django.core.management import CommandError
from django.core.management.commands.dumpdata import ProxyModelWarning
from django.core.serializers.base import ProgressBar
from django.db import IntegrityError, connection
from django.test import (
TestCase, TransactionTestCase, mock, skipUnlessDBFeature,
)
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
from django.utils.encoding import force_text
from .models import (

View File

@ -1,5 +1,6 @@
import datetime
from collections import Counter
from unittest import mock
from django.forms import (
BaseForm, CharField, DateField, FileField, Form, IntegerField,
@ -7,7 +8,7 @@ from django.forms import (
)
from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.utils import ErrorList
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
from django.utils.encoding import force_text

View File

@ -1,7 +1,7 @@
import unittest
from unittest import mock
from django.contrib.gis.gdal import HAS_GDAL
from django.test import mock
if HAS_GDAL:
from django.contrib.gis.gdal import Driver, GDALException

View File

@ -4,7 +4,7 @@ import pickle
import random
from binascii import a2b_hex, b2a_hex
from io import BytesIO
from unittest import skipUnless
from unittest import mock, skipUnless
from django.contrib.gis import gdal
from django.contrib.gis.gdal import HAS_GDAL
@ -17,7 +17,7 @@ from django.contrib.gis.geos.libgeos import geos_version_info
from django.contrib.gis.shortcuts import numpy
from django.template import Context
from django.template.engine import Engine
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
from django.utils.encoding import force_bytes
from ..test_data import TestDataMixin

View File

@ -1,11 +1,10 @@
import os
import unittest
from unittest import skipUnless
from unittest import mock, skipUnless
from django.conf import settings
from django.contrib.gis.geoip2 import HAS_GEOIP2
from django.contrib.gis.geos import HAS_GEOS, GEOSGeometry
from django.test import mock
if HAS_GEOIP2:
from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception

View File

@ -1,7 +1,8 @@
import ctypes
from unittest import mock
from django.contrib.gis.ptr import CPointerBase
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
class CPointerBaseTests(SimpleTestCase):

View File

@ -4,6 +4,7 @@ import stat
import unittest
from io import StringIO
from subprocess import Popen
from unittest import mock
from django.core.management import (
CommandError, call_command, execute_from_command_line,
@ -11,7 +12,7 @@ from django.core.management import (
from django.core.management.commands.makemessages import \
Command as MakeMessagesCommand
from django.core.management.utils import find_command
from django.test import SimpleTestCase, mock, override_settings
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, captured_stdout
from django.utils import translation
from django.utils.encoding import force_text

View File

@ -4,7 +4,7 @@ import shutil
import time
import warnings
from io import StringIO
from unittest import skipUnless
from unittest import mock, skipUnless
from admin_scripts.tests import AdminScriptTestCase
@ -14,7 +14,7 @@ from django.core.management.base import CommandError
from django.core.management.commands.makemessages import \
Command as MakeMessagesCommand
from django.core.management.utils import find_command
from django.test import SimpleTestCase, mock, override_settings
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, captured_stdout
from django.utils.encoding import force_text
from django.utils.translation import TranslatorCommentWarning

View File

@ -1,10 +1,10 @@
import re
from io import StringIO
from unittest import skipUnless
from unittest import mock, skipUnless
from django.core.management import call_command
from django.db import connection
from django.test import TestCase, mock, skipUnlessDBFeature
from django.test import TestCase, skipUnlessDBFeature
from django.utils.encoding import force_text
from .models import ColumnTypes

View File

@ -1,8 +1,8 @@
from unittest import skipUnless
from unittest import mock, skipUnless
from django.db import connection
from django.db.utils import DatabaseError
from django.test import TransactionTestCase, mock, skipUnlessDBFeature
from django.test import TransactionTestCase, skipUnlessDBFeature
from django.test.utils import ignore_warnings
from django.utils.deprecation import RemovedInDjango21Warning

View File

@ -1,6 +1,8 @@
from unittest import mock
from django.core.checks import Error
from django.db import connections, models
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
from django.test.utils import isolate_apps

View File

@ -1,5 +1,6 @@
import functools
import re
from unittest import mock
from django.apps import apps
from django.conf import settings
@ -11,7 +12,7 @@ from django.db.migrations.graph import MigrationGraph
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.questioner import MigrationQuestioner
from django.db.migrations.state import ModelState, ProjectState
from django.test import TestCase, mock, override_settings
from django.test import TestCase, override_settings
from django.test.utils import isolate_lru_cache
from .models import FoodManager, FoodQuerySet

View File

@ -3,6 +3,7 @@ import importlib
import io
import os
import sys
from unittest import mock
from django.apps import apps
from django.core.management import CommandError, call_command
@ -14,7 +15,7 @@ from django.db.migrations.exceptions import (
InconsistentMigrationHistory, MigrationSchemaMissing,
)
from django.db.migrations.recorder import MigrationRecorder
from django.test import mock, override_settings
from django.test import override_settings
from django.utils.encoding import force_text
from .models import UnicodeModel, UnserializableModel

View File

@ -7,6 +7,7 @@ import os
import re
import sys
import uuid
from unittest import mock
import custom_migration_operations.more_operations
import custom_migration_operations.operations
@ -18,7 +19,7 @@ from django.db import migrations, models
from django.db.migrations.writer import (
MigrationWriter, OperationWriter, SettingsReference,
)
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
from django.utils import datetime_safe
from django.utils.deconstruct import deconstructible
from django.utils.functional import SimpleLazyObject

View File

@ -1,3 +1,5 @@
from unittest import mock
from django.db import migrations
try:
@ -6,7 +8,6 @@ try:
TrigramExtension, UnaccentExtension,
)
except ImportError:
from django.test import mock
BtreeGinExtension = mock.Mock()
CreateExtension = mock.Mock()
HStoreExtension = mock.Mock()

View File

@ -1,5 +0,0 @@
-r base.txt
enum34
# Due to https://github.com/linsomniac/python-memcached/issues/79 in newer versions.
python-memcached <= 1.53
mock

View File

@ -437,16 +437,6 @@ if __name__ == "__main__":
options = parser.parse_args()
# mock is a required dependency
try:
from django.test import mock # NOQA
except ImportError:
print(
"Please install test dependencies first: \n"
"$ pip install -r requirements/py%s.txt" % sys.version_info.major
)
sys.exit(1)
# Allow including a trailing slash on app_labels for tab completion convenience
options.modules = [os.path.normpath(labels) for labels in options.modules]

View File

@ -2,6 +2,7 @@ import datetime
import itertools
import unittest
from copy import copy
from unittest import mock
from django.db import (
DatabaseError, IntegrityError, OperationalError, connection,
@ -19,7 +20,7 @@ from django.db.models.fields.related import (
from django.db.models.indexes import Index
from django.db.transaction import TransactionManagementError, atomic
from django.test import (
TransactionTestCase, mock, skipIfDBFeature, skipUnlessDBFeature,
TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature,
)
from django.test.utils import CaptureQueriesContext
from django.utils import timezone

View File

@ -1,5 +1,6 @@
import threading
import time
from unittest import mock
from multiple_database.routers import TestRouter
@ -7,7 +8,7 @@ from django.db import (
DatabaseError, connection, connections, router, transaction,
)
from django.test import (
TransactionTestCase, mock, override_settings, skipIfDBFeature,
TransactionTestCase, override_settings, skipIfDBFeature,
skipUnlessDBFeature,
)
from django.test.utils import CaptureQueriesContext

View File

@ -1,14 +1,13 @@
from datetime import datetime
from io import StringIO
from unittest import mock
from django.core import serializers
from django.core.serializers import SerializerDoesNotExist
from django.core.serializers.base import ProgressBar
from django.db import connection, transaction
from django.http import HttpResponse
from django.test import (
SimpleTestCase, mock, override_settings, skipUnlessDBFeature,
)
from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature
from django.test.utils import Approximate
from django.utils.functional import curry

View File

@ -1,9 +1,10 @@
import sys
import unittest
from unittest import mock
from django import __version__
from django.core.management import CommandError, call_command
from django.test import SimpleTestCase, mock
from django.test import SimpleTestCase
from django.test.utils import captured_stdin, captured_stdout, patch_logger

View File

@ -1,8 +1,10 @@
from unittest import mock
from django.apps.registry import Apps
from django.db import models
from django.db.models import signals
from django.dispatch import receiver
from django.test import TestCase, mock
from django.test import TestCase
from django.test.utils import isolate_apps
from .models import Author, Book, Car, Person

View File

@ -1,5 +1,6 @@
from unittest import mock
from django.core.management import call_command
from django.test import mock
from .base import SitemapTestsBase

View File

@ -1,10 +1,11 @@
from unittest import mock
from urllib.parse import urlencode
from django.contrib.sitemaps import (
SitemapNotFound, _get_sitemap_full_url, ping_google,
)
from django.core.exceptions import ImproperlyConfigured
from django.test import mock, modify_settings, override_settings
from django.test import modify_settings, override_settings
from .base import SitemapTestsBase

View File

@ -5,6 +5,7 @@ import shutil
import tempfile
import unittest
from io import StringIO
from unittest import mock
from admin_scripts.tests import AdminScriptTestCase
@ -13,7 +14,7 @@ from django.contrib.staticfiles import storage
from django.contrib.staticfiles.management.commands import collectstatic
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.test import mock, override_settings
from django.test import override_settings
from django.test.utils import extend_sys_path
from django.utils import timezone
from django.utils._os import symlinks_supported

View File

@ -2,6 +2,7 @@
Tests for django test runner
"""
import unittest
from unittest import mock
from admin_scripts.tests import AdminScriptTestCase
@ -10,7 +11,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.test import (
TestCase, TransactionTestCase, mock, skipUnlessDBFeature, testcases,
TestCase, TransactionTestCase, skipUnlessDBFeature, testcases,
)
from django.test.runner import DiscoverRunner
from django.test.testcases import connections_support_transactions

View File

@ -1,4 +1,6 @@
from django.test import TransactionTestCase, mock
from unittest import mock
from django.test import TransactionTestCase
class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase):

View File

@ -1,7 +1,8 @@
import os
from unittest import mock
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase, mock, override_settings
from django.test import SimpleTestCase, override_settings
from django.urls import LocaleRegexProvider
from django.urls.resolvers import LocaleRegexDescriptor
from django.utils import translation

View File

@ -1,5 +1,6 @@
import os
from io import StringIO
from unittest import mock
from admin_scripts.tests import AdminScriptTestCase
@ -8,7 +9,7 @@ from django.core import management
from django.core.management import BaseCommand, CommandError, find_commands
from django.core.management.utils import find_command, popen_wrapper
from django.db import connection
from django.test import SimpleTestCase, mock, override_settings
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, extend_sys_path
from django.utils import translation

View File

@ -3,12 +3,13 @@ import os
import shutil
import tempfile
from importlib import import_module
from unittest import mock
import _thread
from django import conf
from django.contrib import admin
from django.test import SimpleTestCase, mock, override_settings
from django.test import SimpleTestCase, override_settings
from django.test.utils import extend_sys_path
from django.utils import autoreload
from django.utils.translation import trans_real

View File

@ -1,9 +1,10 @@
import datetime
import pickle
from unittest import mock
import pytz
from django.test import SimpleTestCase, mock, override_settings
from django.test import SimpleTestCase, override_settings
from django.utils import timezone
CET = pytz.timezone("Europe/Paris")