Fixed #20548 -- Removed all PendingDeprecationWarnings from django test suite

This commit is contained in:
Marc Tamlyn 2013-06-14 15:02:30 +01:00
parent 5459795ef2
commit 46789e76c6
7 changed files with 29 additions and 16 deletions

View File

@ -208,7 +208,8 @@ class RelatedModelFormTests(TestCase):
ref = models.ForeignKey("B") ref = models.ForeignKey("B")
class Meta: class Meta:
model=A model = A
fields = '__all__'
self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta}) self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta})
@ -226,7 +227,8 @@ class RelatedModelFormTests(TestCase):
pass pass
class Meta: class Meta:
model=A model = A
fields = '__all__'
self.assertTrue(issubclass(ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta}), ModelForm)) self.assertTrue(issubclass(ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta}), ModelForm))

View File

@ -52,12 +52,15 @@ class PriceForm(forms.ModelForm):
class BookForm(forms.ModelForm): class BookForm(forms.ModelForm):
class Meta: class Meta:
model = Book model = Book
fields = '__all__'
class DerivedBookForm(forms.ModelForm): class DerivedBookForm(forms.ModelForm):
class Meta: class Meta:
model = DerivedBook model = DerivedBook
fields = '__all__'
class ExplicitPKForm(forms.ModelForm): class ExplicitPKForm(forms.ModelForm):

View File

@ -97,12 +97,14 @@ class PartiallyLocalizedTripleForm(forms.ModelForm):
class Meta: class Meta:
model = Triple model = Triple
localized_fields = ('left', 'right',) localized_fields = ('left', 'right',)
fields = '__all__'
class FullyLocalizedTripleForm(forms.ModelForm): class FullyLocalizedTripleForm(forms.ModelForm):
class Meta: class Meta:
model = Triple model = Triple
localized_fields = "__all__" localized_fields = '__all__'
fields = '__all__'
class LocalizedModelFormTest(TestCase): class LocalizedModelFormTest(TestCase):
def test_model_form_applies_localize_to_some_fields(self): def test_model_form_applies_localize_to_some_fields(self):

View File

@ -5,6 +5,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import warnings
from django import contrib from django import contrib
from django.utils._os import upath from django.utils._os import upath
@ -107,7 +108,9 @@ def setup(verbosity, test_labels):
logger.addHandler(handler) logger.addHandler(handler)
# Load all the ALWAYS_INSTALLED_APPS. # Load all the ALWAYS_INSTALLED_APPS.
get_apps() with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', PendingDeprecationWarning)
get_apps()
# Load all the test model apps. # Load all the test model apps.
test_modules = get_test_modules() test_modules = get_test_modules()

View File

@ -10,8 +10,8 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command from django.core.management import call_command
from django import db from django import db
from django.test import runner, TransactionTestCase, skipUnlessDBFeature from django.test import runner, TransactionTestCase, skipUnlessDBFeature
from django.test.simple import DjangoTestSuiteRunner, get_tests
from django.test.testcases import connections_support_transactions from django.test.testcases import connections_support_transactions
from django.test.utils import IgnorePendingDeprecationWarningsMixin
from django.utils import unittest from django.utils import unittest
from django.utils.importlib import import_module from django.utils.importlib import import_module
@ -225,15 +225,17 @@ class Ticket17477RegressionTests(AdminScriptTestCase):
self.assertNoOutput(err) self.assertNoOutput(err)
class ModulesTestsPackages(unittest.TestCase): class ModulesTestsPackages(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
def test_get_tests(self): def test_get_tests(self):
"Check that the get_tests helper function can find tests in a directory" "Check that the get_tests helper function can find tests in a directory"
from django.test.simple import get_tests
module = import_module(TEST_APP_OK) module = import_module(TEST_APP_OK)
tests = get_tests(module) tests = get_tests(module)
self.assertIsInstance(tests, type(module)) self.assertIsInstance(tests, type(module))
def test_import_error(self): def test_import_error(self):
"Test for #12658 - Tests with ImportError's shouldn't fail silently" "Test for #12658 - Tests with ImportError's shouldn't fail silently"
from django.test.simple import get_tests
module = import_module(TEST_APP_ERROR) module = import_module(TEST_APP_ERROR)
self.assertRaises(ImportError, get_tests, module) self.assertRaises(ImportError, get_tests, module)
@ -258,7 +260,7 @@ class Sqlite3InMemoryTestDbs(unittest.TestCase):
}, },
}) })
other = db.connections['other'] other = db.connections['other']
DjangoTestSuiteRunner(verbosity=0).setup_databases() runner.DiscoverRunner(verbosity=0).setup_databases()
msg = "DATABASES setting '%s' option set to sqlite3's ':memory:' value shouldn't interfere with transaction support detection." % option msg = "DATABASES setting '%s' option set to sqlite3's ':memory:' value shouldn't interfere with transaction support detection." % option
# Transaction support should be properly initialised for the 'other' DB # Transaction support should be properly initialised for the 'other' DB
self.assertTrue(other.features.supports_transactions, msg) self.assertTrue(other.features.supports_transactions, msg)
@ -273,12 +275,12 @@ class DummyBackendTest(unittest.TestCase):
""" """
Test that setup_databases() doesn't fail with dummy database backend. Test that setup_databases() doesn't fail with dummy database backend.
""" """
runner = DjangoTestSuiteRunner(verbosity=0) runner_instance = runner.DiscoverRunner(verbosity=0)
old_db_connections = db.connections old_db_connections = db.connections
try: try:
db.connections = db.ConnectionHandler({}) db.connections = db.ConnectionHandler({})
old_config = runner.setup_databases() old_config = runner_instance.setup_databases()
runner.teardown_databases(old_config) runner_instance.teardown_databases(old_config)
except Exception as e: except Exception as e:
self.fail("setup_databases/teardown_databases unexpectedly raised " self.fail("setup_databases/teardown_databases unexpectedly raised "
"an error: %s" % e) "an error: %s" % e)

View File

@ -1,5 +1,5 @@
from django.db.models import get_app from django.db.models import get_app
from django.test.simple import build_suite from django.test.utils import IgnorePendingDeprecationWarningsMixin
from django.utils import unittest from django.utils import unittest
@ -9,7 +9,7 @@ def suite():
return testSuite return testSuite
class SuiteOverrideTest(unittest.TestCase): class SuiteOverrideTest(IgnorePendingDeprecationWarningsMixin, unittest.TestCase):
def test_suite_override(self): def test_suite_override(self):
""" """
Validate that you can define a custom suite when running tests with Validate that you can define a custom suite when running tests with
@ -17,6 +17,7 @@ class SuiteOverrideTest(unittest.TestCase):
suite using ``build_suite``). suite using ``build_suite``).
""" """
from django.test.simple import build_suite
app = get_app("test_suite_override") app = get_app("test_suite_override")
suite = build_suite(app) suite = build_suite(app)
self.assertEqual(suite.countTestCases(), 1) self.assertEqual(suite.countTestCases(), 1)

View File

@ -8,8 +8,7 @@ from django.http import HttpResponse
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.html import HTMLParseError, parse_html from django.test.html import HTMLParseError, parse_html
from django.test.simple import make_doctest from django.test.utils import CaptureQueriesContext, IgnorePendingDeprecationWarningsMixin
from django.test.utils import CaptureQueriesContext
from django.utils import six from django.utils import six
from django.utils import unittest from django.utils import unittest
from django.utils.unittest import skip from django.utils.unittest import skip
@ -624,9 +623,10 @@ class AssertFieldOutputTests(SimpleTestCase):
self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None) self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
class DoctestNormalizerTest(SimpleTestCase): class DoctestNormalizerTest(IgnorePendingDeprecationWarningsMixin, SimpleTestCase):
def test_normalizer(self): def test_normalizer(self):
from django.test.simple import make_doctest
suite = make_doctest("test_utils.doctest_output") suite = make_doctest("test_utils.doctest_output")
failures = unittest.TextTestRunner(stream=six.StringIO()).run(suite) failures = unittest.TextTestRunner(stream=six.StringIO()).run(suite)
self.assertEqual(failures.failures, []) self.assertEqual(failures.failures, [])