Skip to content

Commit

Permalink
Switched TestCase to SimpleTestCase where possible in Django's tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Nov 27, 2018
1 parent f091ea3 commit 193c109
Show file tree
Hide file tree
Showing 37 changed files with 130 additions and 134 deletions.
4 changes: 2 additions & 2 deletions tests/admin_docs/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
docutils_is_available, parse_docstring, parse_rst, trim_docstring,
)

from .tests import AdminDocsTestCase
from .tests import AdminDocsSimpleTestCase


@unittest.skipUnless(docutils_is_available, "no docutils installed.")
class TestUtils(AdminDocsTestCase):
class TestUtils(AdminDocsSimpleTestCase):
"""
This __doc__ output is required for testing. I copied this example from
`admindocs` documentation. (TITLE)
Expand Down
10 changes: 9 additions & 1 deletion tests/admin_docs/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.contrib.auth.models import User
from django.test import TestCase, modify_settings, override_settings
from django.test import (
SimpleTestCase, TestCase, modify_settings, override_settings,
)


class TestDataMixin:
Expand All @@ -9,6 +11,12 @@ def setUpTestData(cls):
cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')


@override_settings(ROOT_URLCONF='admin_docs.urls')
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.admindocs'})
class AdminDocsSimpleTestCase(SimpleTestCase):
pass


@override_settings(ROOT_URLCONF='admin_docs.urls')
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.admindocs'})
class AdminDocsTestCase(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/auth_tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.test import RequestFactory, TestCase
from django.test import RequestFactory, SimpleTestCase, TestCase
from django.views.generic import View


Expand Down Expand Up @@ -111,7 +111,7 @@ def test_stacked_mixins_not_logged_in(self):
view(request)


class UserPassesTestTests(TestCase):
class UserPassesTestTests(SimpleTestCase):

factory = RequestFactory()

Expand Down
2 changes: 1 addition & 1 deletion tests/auth_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_make_random_password(self):
self.assertIn(char, allowed_chars)


class AbstractBaseUserTests(TestCase):
class AbstractBaseUserTests(SimpleTestCase):

def test_has_usable_password(self):
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/auth_tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase, override_settings
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.utils import isolate_apps
from django.utils.html import conditional_escape

Expand All @@ -22,7 +22,7 @@
'min_length': 12,
}},
])
class PasswordValidationTest(TestCase):
class PasswordValidationTest(SimpleTestCase):
def test_get_default_password_validators(self):
validators = get_default_password_validators()
self.assertEqual(len(validators), 2)
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_empty_password_validator_help_text_html(self):
self.assertEqual(password_validators_help_text_html(), '')


class MinimumLengthValidatorTest(TestCase):
class MinimumLengthValidatorTest(SimpleTestCase):
def test_validate(self):
expected_error = "This password is too short. It must contain at least %d characters."
self.assertIsNone(MinimumLengthValidator().validate('12345678'))
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_help_text(self):
)


class CommonPasswordValidatorTest(TestCase):
class CommonPasswordValidatorTest(SimpleTestCase):
def test_validate(self):
expected_error = "This password is too common."
self.assertIsNone(CommonPasswordValidator().validate('a-safe-password'))
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_help_text(self):
)


class NumericPasswordValidatorTest(TestCase):
class NumericPasswordValidatorTest(SimpleTestCase):
def test_validate(self):
expected_error = "This password is entirely numeric."
self.assertIsNone(NumericPasswordValidator().validate('a-safe-password'))
Expand All @@ -231,7 +231,7 @@ def test_help_text(self):
)


class UsernameValidatorsTests(TestCase):
class UsernameValidatorsTests(SimpleTestCase):
def test_unicode_validator(self):
valid_usernames = ['joe', 'René', 'ᴮᴵᴳᴮᴵᴿᴰ', 'أحمد']
invalid_usernames = [
Expand Down
4 changes: 2 additions & 2 deletions tests/backends/base/test_features.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.db import connection
from django.test import TestCase
from django.test import SimpleTestCase


class TestDatabaseFeatures(TestCase):
class TestDatabaseFeatures(SimpleTestCase):

def test_nonexistent_feature(self):
self.assertFalse(hasattr(connection.features, 'nonexistent'))
2 changes: 1 addition & 1 deletion tests/cache/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ def test_head_with_cached_get(self):
('es', 'Spanish'),
],
)
class CacheI18nTest(TestCase):
class CacheI18nTest(SimpleTestCase):

def setUp(self):
self.path = '/cache/test/'
Expand Down
5 changes: 2 additions & 3 deletions tests/check_framework/test_multi_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import mock

from django.db import connections, models
from django.test import TestCase
from django.test import SimpleTestCase
from django.test.utils import isolate_apps, override_settings


Expand All @@ -15,8 +15,7 @@ def allow_migrate(self, db, app_label, model_name=None, **hints):

@override_settings(DATABASE_ROUTERS=[TestRouter()])
@isolate_apps('check_framework')
class TestMultiDBChecks(TestCase):
multi_db = True
class TestMultiDBChecks(SimpleTestCase):

def _patch_check_field_on(self, db):
return mock.patch.object(connections[db].validation, 'check_field')
Expand Down
6 changes: 3 additions & 3 deletions tests/custom_lookups/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.core.exceptions import FieldError
from django.db import connection, models
from django.test import TestCase, override_settings
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.utils import register_lookup
from django.utils import timezone

Expand Down Expand Up @@ -513,7 +513,7 @@ def get_transform(self, lookup_name):
return super().get_transform(lookup_name)


class LookupTransformCallOrderTests(TestCase):
class LookupTransformCallOrderTests(SimpleTestCase):
def test_call_order(self):
with register_lookup(models.DateField, TrackCallsYearTransform):
# junk lookup - tries lookup, then transform, then fails
Expand All @@ -540,7 +540,7 @@ def test_call_order(self):
['lookup'])


class CustomisedMethodsTests(TestCase):
class CustomisedMethodsTests(SimpleTestCase):

def test_overridden_get_lookup(self):
q = CustomModel.objects.filter(field__lookupfunc_monkeys=3)
Expand Down
2 changes: 1 addition & 1 deletion tests/expressions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ def test_multiple_transforms_in_values(self):
)


class ReprTests(TestCase):
class ReprTests(SimpleTestCase):

def test_expressions(self):
self.assertEqual(
Expand Down
12 changes: 6 additions & 6 deletions tests/invalid_models_tests/test_ordinary_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.core.checks import Error, Warning as DjangoWarning
from django.db import connection, models
from django.test import SimpleTestCase, TestCase, skipIfDBFeature
from django.test import SimpleTestCase, skipIfDBFeature
from django.test.utils import isolate_apps, override_settings
from django.utils.functional import lazy
from django.utils.timezone import now
Expand Down Expand Up @@ -40,7 +40,7 @@ class Model(models.Model):


@isolate_apps('invalid_models_tests')
class CharFieldTests(TestCase):
class CharFieldTests(SimpleTestCase):

def test_valid_field(self):
class Model(models.Model):
Expand Down Expand Up @@ -312,7 +312,7 @@ class Model(models.Model):


@isolate_apps('invalid_models_tests')
class DateFieldTests(TestCase):
class DateFieldTests(SimpleTestCase):
maxDiff = None

def test_auto_now_and_auto_now_add_raise_error(self):
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_fix_default_value_tz(self):


@isolate_apps('invalid_models_tests')
class DateTimeFieldTests(TestCase):
class DateTimeFieldTests(SimpleTestCase):
maxDiff = None

def test_fix_default_value(self):
Expand Down Expand Up @@ -638,7 +638,7 @@ class Model(models.Model):


@isolate_apps('invalid_models_tests')
class TimeFieldTests(TestCase):
class TimeFieldTests(SimpleTestCase):
maxDiff = None

def test_fix_default_value(self):
Expand Down Expand Up @@ -680,7 +680,7 @@ def test_fix_default_value_tz(self):


@isolate_apps('invalid_models_tests')
class TextFieldTests(TestCase):
class TextFieldTests(SimpleTestCase):

@skipIfDBFeature('supports_index_on_text_field')
def test_max_length_warning(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/managers_regress/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.template import Context, Template
from django.test import TestCase, override_settings
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.utils import isolate_apps

from .models import (
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_field_can_be_called_exact(self):


@isolate_apps('managers_regress')
class TestManagerInheritance(TestCase):
class TestManagerInheritance(SimpleTestCase):
def test_implicit_inheritance(self):
class CustomManager(models.Manager):
pass
Expand Down
4 changes: 2 additions & 2 deletions tests/migrations/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.db.migrations.recorder import MigrationRecorder
from django.db.utils import DatabaseError
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature,
SimpleTestCase, modify_settings, override_settings, skipUnlessDBFeature,
)

from .test_base import MigrationTestBase
Expand Down Expand Up @@ -685,7 +685,7 @@ def __repr__(self):
return 'M<%s>' % self.name


class ExecutorUnitTests(TestCase):
class ExecutorUnitTests(SimpleTestCase):
"""(More) isolated unit tests for executor methods."""
def test_minimize_rollbacks(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/model_fields/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Field(models.Field):
pass


class BasicFieldTests(TestCase):
class BasicFieldTests(SimpleTestCase):

def test_show_hidden_initial(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/model_forms/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,7 @@ def test_modelform_factory_metaclass(self):
self.assertEqual(new_cls.base_fields, {})


class StrictAssignmentTests(TestCase):
class StrictAssignmentTests(SimpleTestCase):
"""
Should a model do anything special with __setattr__() or descriptors which
raise a ValidationError, a model form should catch the error (#24706).
Expand Down
4 changes: 2 additions & 2 deletions tests/model_inheritance/test_abstract_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from django.core.checks import Error
from django.core.exceptions import FieldDoesNotExist, FieldError
from django.db import models
from django.test import TestCase
from django.test import SimpleTestCase
from django.test.utils import isolate_apps


@isolate_apps('model_inheritance')
class AbstractInheritanceTests(TestCase):
class AbstractInheritanceTests(SimpleTestCase):
def test_single_parent(self):
class AbstractBase(models.Model):
name = models.CharField(max_length=30)
Expand Down
4 changes: 2 additions & 2 deletions tests/model_regress/test_pickle.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pickle

from django.db import DJANGO_VERSION_PICKLE_KEY, models
from django.test import TestCase
from django.test import SimpleTestCase
from django.utils.version import get_version


class ModelPickleTestCase(TestCase):
class ModelPickleTests(SimpleTestCase):
def test_missing_django_version_unpickling(self):
"""
#21430 -- Verifies a warning is raised for models that are
Expand Down
2 changes: 1 addition & 1 deletion tests/multiple_database/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ def allow_relation(self, obj1, obj2, **hints):


@override_settings(DATABASE_ROUTERS=[NoRelationRouter()])
class RelationAssignmentTests(TestCase):
class RelationAssignmentTests(SimpleTestCase):
"""allow_relation() is called with unsaved model instances."""
multi_db = True
router_prevents_msg = 'the current database router prevents this relation'
Expand Down
4 changes: 2 additions & 2 deletions tests/order_with_respect_to/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from operator import attrgetter

from django.db import models
from django.test import TestCase
from django.test import SimpleTestCase, TestCase
from django.test.utils import isolate_apps

from .base_tests import BaseOrderWithRespectToTests
Expand All @@ -14,7 +14,7 @@ class OrderWithRespectToBaseTests(BaseOrderWithRespectToTests, TestCase):
Question = Question


class OrderWithRespectToTests(TestCase):
class OrderWithRespectToTests(SimpleTestCase):

@isolate_apps('order_with_respect_to')
def test_duplicate_order_field(self):
Expand Down
9 changes: 7 additions & 2 deletions tests/postgres_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from forms_tests.widget_tests.base import WidgetTest

from django.db import connection
from django.test import TestCase, modify_settings
from django.test import SimpleTestCase, TestCase, modify_settings


@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
class PostgreSQLSimpleTestCase(SimpleTestCase):
pass


@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
Expand All @@ -14,5 +19,5 @@ class PostgreSQLTestCase(TestCase):
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific tests")
# To locate the widget's template.
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'})
class PostgreSQLWidgetTestCase(WidgetTest, PostgreSQLTestCase):
class PostgreSQLWidgetTestCase(WidgetTest, PostgreSQLSimpleTestCase):
pass

0 comments on commit 193c109

Please sign in to comment.