From c564277937a1f0b78b2c2b701e6381319d9685c2 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sun, 9 Mar 2014 21:37:05 +0100 Subject: [PATCH] Fixed #22237 -- Removed some warnings in the test suite Thanks Aymeric Augustin for the report. --- tests/cache/tests.py | 10 +++++----- tests/fixtures/tests.py | 10 ++++++---- tests/modeladmin/tests.py | 3 ++- tests/test_runner/tests.py | 9 +++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/cache/tests.py b/tests/cache/tests.py index e2d027f689..c08a489939 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1237,14 +1237,14 @@ class DefaultNonExpiringCacheKeyTests(TestCase): This value is defined inside the __init__() method of the :class:`django.core.cache.backends.base.BaseCache` type. """ - self.assertEquals(300, self.DEFAULT_TIMEOUT) + self.assertEqual(300, self.DEFAULT_TIMEOUT) def test_caches_with_unset_timeout_has_correct_default_timeout(self): """Caches that have the TIMEOUT parameter undefined in the default settings will use the default 5 minute timeout. """ cache = caches[DEFAULT_CACHE_ALIAS] - self.assertEquals(self.DEFAULT_TIMEOUT, cache.default_timeout) + self.assertEqual(self.DEFAULT_TIMEOUT, cache.default_timeout) @override_settings(CACHES=NEVER_EXPIRING_CACHES_SETTINGS) def test_caches_set_with_timeout_as_none_has_correct_default_timeout(self): @@ -1255,7 +1255,7 @@ class DefaultNonExpiringCacheKeyTests(TestCase): """ cache = caches[DEFAULT_CACHE_ALIAS] self.assertIs(None, cache.default_timeout) - self.assertEquals(None, cache.get_backend_timeout()) + self.assertEqual(None, cache.get_backend_timeout()) @override_settings(CACHES=DEFAULT_MEMORY_CACHES_SETTINGS) def test_caches_with_unset_timeout_set_expiring_key(self): @@ -1267,7 +1267,7 @@ class DefaultNonExpiringCacheKeyTests(TestCase): cache = caches[DEFAULT_CACHE_ALIAS] cache.set(key, value) cache_key = cache.make_key(key) - self.assertNotEquals(None, cache._expire_info[cache_key]) + self.assertNotEqual(None, cache._expire_info[cache_key]) @override_settings(CACHES=NEVER_EXPIRING_CACHES_SETTINGS) def text_caches_set_with_timeout_as_none_set_non_expiring_key(self): @@ -1279,7 +1279,7 @@ class DefaultNonExpiringCacheKeyTests(TestCase): cache = caches[DEFAULT_CACHE_ALIAS] cache.set(key, value) cache_key = cache.make_key(key) - self.assertEquals(None, cache._expire_info[cache_key]) + self.assertEqual(None, cache._expire_info[cache_key]) @override_settings( diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 88eadae6b9..fb807bb97c 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -337,7 +337,10 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): """ Verifies that the --app option works. """ - management.call_command('loaddata', 'db_fixture_1', verbosity=0, app_label="someotherapp") + with warnings.catch_warnings(): + # Ignore: No fixture named ... + warnings.filterwarnings("ignore", category=UserWarning) + management.call_command('loaddata', 'db_fixture_1', verbosity=0, app_label="someotherapp") self.assertQuerysetEqual(Article.objects.all(), []) management.call_command('loaddata', 'db_fixture_1', verbosity=0, app_label="fixtures") self.assertQuerysetEqual(Article.objects.all(), [ @@ -355,10 +358,9 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): def test_unmatched_identifier_loading(self): # Try to load db fixture 3. This won't load because the database identifier doesn't match - with warnings.catch_warnings(record=True): + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=UserWarning) management.call_command('loaddata', 'db_fixture_3', verbosity=0) - - with warnings.catch_warnings(record=True): management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default') self.assertQuerysetEqual(Article.objects.all(), []) diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 1f4fd4e86d..9cf54c8b9f 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -16,6 +16,7 @@ from django.core.exceptions import ImproperlyConfigured from django.forms.models import BaseModelFormSet from django.forms.widgets import Select from django.test import TestCase +from django.utils import six from django.utils.deprecation import RemovedInDjango19Warning from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel @@ -565,7 +566,7 @@ class CheckTestCase(TestCase): self.assertEqual(error.hint, hint) self.assertEqual(error.obj, invalid_obj) self.assertEqual(error.id, id) - self.assertRegexpMatches(error.msg, msg) + six.assertRegex(self, error.msg, msg) def assertIsValid(self, model_admin, model): errors = model_admin.check(model=model) diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index 3bc89bf2ab..20e7f6b892 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -254,21 +254,22 @@ class Sqlite3InMemoryTestDbs(TestCase): def test_transaction_support(self): """Ticket #16329: sqlite3 in-memory test databases""" old_db_connections = db.connections - for option in ('NAME', 'TEST_NAME'): + for option_key, option_value in ( + ('NAME', ':memory:'), ('TEST', {'NAME': ':memory:'})): try: db.connections = db.ConnectionHandler({ 'default': { 'ENGINE': 'django.db.backends.sqlite3', - option: ':memory:', + option_key: option_value, }, 'other': { 'ENGINE': 'django.db.backends.sqlite3', - option: ':memory:', + option_key: option_value, }, }) other = db.connections['other'] 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_key # Transaction support should be properly initialized for the 'other' DB self.assertTrue(other.features.supports_transactions, msg) # And all the DBs should report that they support transactions