1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Merge branch 'master' into schema-alteration

This commit is contained in:
Andrew Godwin
2013-07-02 10:49:53 +01:00
240 changed files with 694 additions and 4096 deletions

View File

@@ -54,7 +54,7 @@ import warnings
warnings.warn(
"The django.test._doctest module is deprecated; "
"use the doctest module from the Python standard library instead.",
PendingDeprecationWarning)
DeprecationWarning)
__docformat__ = 'reStructuredText en'

View File

@@ -1,12 +1,12 @@
import os
from optparse import make_option
import unittest
from unittest import TestSuite, defaultTestLoader
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.utils import setup_test_environment, teardown_test_environment
from django.utils import unittest
from django.utils.unittest import TestSuite, defaultTestLoader
class DiscoverRunner(object):

View File

@@ -12,6 +12,8 @@ from django.db.models import get_app, get_apps
from django.test import _doctest as doctest
from django.test import runner
from django.test.utils import compare_xml, strip_quotes
# django.utils.unittest is deprecated, but so is django.test.simple,
# and the latter will be removed before the former.
from django.utils import unittest
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
@@ -21,7 +23,7 @@ __all__ = ('DjangoTestSuiteRunner',)
warnings.warn(
"The django.test.simple module and DjangoTestSuiteRunner are deprecated; "
"use django.test.runner.DiscoverRunner instead.",
PendingDeprecationWarning)
DeprecationWarning)
# The module name for tests outside models.py
TEST_MODULE = 'tests'

View File

@@ -8,14 +8,16 @@ import json
import os
import re
import sys
import select
import socket
import threading
import unittest
from unittest import skipIf # Imported here for backward compatibility
from unittest.util import safe_repr
try:
from urllib.parse import urlsplit, urlunsplit
except ImportError: # Python 2
from urlparse import urlsplit, urlunsplit
import select
import socket
import threading
import warnings
from django.conf import settings
from django.contrib.staticfiles.handlers import StaticFilesHandler
@@ -37,10 +39,8 @@ from django.test.html import HTMLParseError, parse_html
from django.test.signals import template_rendered
from django.test.utils import (CaptureQueriesContext, ContextList,
override_settings, compare_xml)
from django.utils import six, unittest as ut2
from django.utils import six
from django.utils.encoding import force_text
from django.utils.unittest import skipIf # Imported here for backward compatibility
from django.utils.unittest.util import safe_repr
from django.views.static import serve
@@ -156,16 +156,12 @@ class _AssertTemplateNotUsedContext(_AssertTemplateUsedContext):
return '%s was rendered.' % self.template_name
class SimpleTestCase(ut2.TestCase):
class SimpleTestCase(unittest.TestCase):
# The class we'll use for the test client self.client.
# Can be overridden in derived classes.
client_class = Client
_warn_txt = ("save_warnings_state/restore_warnings_state "
"django.test.*TestCase methods are deprecated. Use Python's "
"warnings.catch_warnings context manager instead.")
def __call__(self, result=None):
"""
Wrapper around default __call__ method to perform common Django test
@@ -225,21 +221,6 @@ class SimpleTestCase(ut2.TestCase):
settings.ROOT_URLCONF = self._old_root_urlconf
clear_url_caches()
def save_warnings_state(self):
"""
Saves the state of the warnings module
"""
warnings.warn(self._warn_txt, DeprecationWarning, stacklevel=2)
self._warnings_state = warnings.filters[:]
def restore_warnings_state(self):
"""
Restores the state of the warnings module to the state
saved by save_warnings_state()
"""
warnings.warn(self._warn_txt, DeprecationWarning, stacklevel=2)
warnings.filters = self._warnings_state[:]
def settings(self, **kwargs):
"""
A context manager that temporarily sets a setting and reverts
@@ -906,7 +887,7 @@ def _deferredSkip(condition, reason):
@wraps(test_func)
def skip_wrapper(*args, **kwargs):
if condition():
raise ut2.SkipTest(reason)
raise unittest.SkipTest(reason)
return test_func(*args, **kwargs)
test_item = skip_wrapper
else:

View File

@@ -124,31 +124,6 @@ def teardown_test_environment():
del mail.outbox
warn_txt = ("get_warnings_state/restore_warnings_state functions from "
"django.test.utils are deprecated. Use Python's warnings.catch_warnings() "
"context manager instead.")
def get_warnings_state():
"""
Returns an object containing the state of the warnings module
"""
# There is no public interface for doing this, but this implementation of
# get_warnings_state and restore_warnings_state appears to work on Python
# 2.4 to 2.7.
warnings.warn(warn_txt, DeprecationWarning, stacklevel=2)
return warnings.filters[:]
def restore_warnings_state(state):
"""
Restores the state of the warnings module when passed an object that was
returned by get_warnings_state()
"""
warnings.warn(warn_txt, DeprecationWarning, stacklevel=2)
warnings.filters = state[:]
def get_runner(settings, test_runner_class=None):
if not test_runner_class:
test_runner_class = settings.TEST_RUNNER
@@ -402,13 +377,14 @@ class CaptureQueriesContext(object):
class IgnoreDeprecationWarningsMixin(object):
warning_class = DeprecationWarning
warning_classes = [DeprecationWarning]
def setUp(self):
super(IgnoreDeprecationWarningsMixin, self).setUp()
self.catch_warnings = warnings.catch_warnings()
self.catch_warnings.__enter__()
warnings.filterwarnings("ignore", category=self.warning_class)
for warning_class in self.warning_classes:
warnings.filterwarnings("ignore", category=warning_class)
def tearDown(self):
self.catch_warnings.__exit__(*sys.exc_info())
@@ -417,7 +393,12 @@ class IgnoreDeprecationWarningsMixin(object):
class IgnorePendingDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
warning_class = PendingDeprecationWarning
warning_classes = [PendingDeprecationWarning]
class IgnoreAllDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
warning_classes = [PendingDeprecationWarning, DeprecationWarning]
@contextmanager