From 09f865276554f35060ff939722ec4cefd578edf6 Mon Sep 17 00:00:00 2001 From: Marc Tamlyn Date: Tue, 21 May 2013 10:42:15 +0100 Subject: [PATCH] Use assertIsInstance in tests. Gives much nicer errors when it fails. --- tests/admin_views/tests.py | 2 +- tests/backends/tests.py | 2 +- tests/basic/tests.py | 10 +++++----- tests/cache/tests.py | 8 ++++---- tests/comment_tests/tests/test_comment_form.py | 2 +- tests/comment_tests/tests/test_templatetags.py | 2 +- tests/custom_managers/tests.py | 4 ++-- tests/datatypes/tests.py | 6 +++--- tests/decorators/tests.py | 10 +++++----- tests/defaultfilters/tests.py | 2 +- tests/dispatch/tests/test_dispatcher.py | 2 +- tests/field_defaults/tests.py | 2 +- tests/field_subclassing/tests.py | 10 +++++----- tests/file_storage/tests.py | 6 +++--- tests/forms_tests/tests/test_formsets.py | 2 +- tests/forms_tests/tests/tests.py | 4 ++-- tests/generic_relations/tests.py | 2 +- tests/generic_views/test_base.py | 4 ++-- tests/generic_views/test_detail.py | 2 +- tests/generic_views/test_edit.py | 14 +++++++------- tests/generic_views/test_list.py | 2 +- tests/logging_tests/tests.py | 2 +- tests/mail/tests.py | 12 ++++++------ tests/model_fields/tests.py | 14 +++++++------- tests/model_forms/tests.py | 12 ++++++------ tests/model_formsets_regress/tests.py | 16 ++++++++-------- tests/unmanaged_models/tests.py | 8 ++++---- tests/urlpatterns_reverse/tests.py | 6 +++--- tests/utils_tests/test_baseconv.py | 2 +- tests/utils_tests/test_simplelazyobject.py | 2 +- tests/view_tests/tests/test_static.py | 2 +- 31 files changed, 87 insertions(+), 87 deletions(-) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 91dc5b4344..c0f6533cb2 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1995,7 +1995,7 @@ class AdminViewListEditable(TestCase): } response = self.client.post('/test_admin/admin/admin_views/person/', data) non_form_errors = response.context['cl'].formset.non_form_errors() - self.assertTrue(isinstance(non_form_errors, ErrorList)) + self.assertIsInstance(non_form_errors, ErrorList) self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"]))) def test_list_editable_ordering(self): diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 81b2851403..79e3dd444e 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -172,7 +172,7 @@ class LastExecutedQueryTest(TestCase): sql, params = persons.query.sql_with_params() cursor = persons.query.get_compiler('default').execute_sql(None) last_sql = cursor.db.ops.last_executed_query(cursor, sql, params) - self.assertTrue(isinstance(last_sql, six.text_type)) + self.assertIsInstance(last_sql, six.text_type) @unittest.skipUnless(connection.vendor == 'sqlite', "This test is specific to SQLite.") diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 95feac0deb..6bf46cce9b 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -432,7 +432,7 @@ class ModelTest(TestCase): Article.objects.all()[0:-5] except Exception as e: error = e - self.assertTrue(isinstance(error, AssertionError)) + self.assertIsInstance(error, AssertionError) self.assertEqual(str(error), "Negative indexing is not supported.") # An Article instance doesn't have access to the "objects" attribute. @@ -637,15 +637,15 @@ class ModelTest(TestCase): # Can't be instantiated with self.assertRaises(TypeError): EmptyQuerySet() - self.assertTrue(isinstance(Article.objects.none(), EmptyQuerySet)) + self.assertIsInstance(Article.objects.none(), EmptyQuerySet) def test_emptyqs_values(self): # test for #15959 Article.objects.create(headline='foo', pub_date=datetime.now()) with self.assertNumQueries(0): qs = Article.objects.none().values_list('pk') - self.assertTrue(isinstance(qs, EmptyQuerySet)) - self.assertTrue(isinstance(qs, ValuesListQuerySet)) + self.assertIsInstance(qs, EmptyQuerySet) + self.assertIsInstance(qs, ValuesListQuerySet) self.assertEqual(len(qs), 0) def test_emptyqs_customqs(self): @@ -660,7 +660,7 @@ class ModelTest(TestCase): qs = qs.none() with self.assertNumQueries(0): self.assertEqual(len(qs), 0) - self.assertTrue(isinstance(qs, EmptyQuerySet)) + self.assertIsInstance(qs, EmptyQuerySet) self.assertEqual(qs.do_something(), 'did something') def test_emptyqs_values_order(self): diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 231a3bfb50..da80c48058 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -510,13 +510,13 @@ class BaseCacheTests(object): # memcached does not allow whitespace or control characters in keys self.cache.set('key with spaces', 'value') self.assertEqual(len(w), 2) - self.assertTrue(isinstance(w[0].message, CacheKeyWarning)) + self.assertIsInstance(w[0].message, CacheKeyWarning) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") # memcached limits key length to 250 self.cache.set('a' * 251, 'value') self.assertEqual(len(w), 1) - self.assertTrue(isinstance(w[0].message, CacheKeyWarning)) + self.assertIsInstance(w[0].message, CacheKeyWarning) finally: self.cache.key_func = old_func @@ -1097,10 +1097,10 @@ class GetCacheTests(unittest.TestCase): def test_simple(self): cache = get_cache('locmem://') from django.core.cache.backends.locmem import LocMemCache - self.assertTrue(isinstance(cache, LocMemCache)) + self.assertIsInstance(cache, LocMemCache) from django.core.cache import cache - self.assertTrue(isinstance(cache, get_cache('default').__class__)) + self.assertIsInstance(cache, get_cache('default').__class__) cache = get_cache( 'django.core.cache.backends.dummy.DummyCache', **{'TIMEOUT': 120}) diff --git a/tests/comment_tests/tests/test_comment_form.py b/tests/comment_tests/tests/test_comment_form.py index 39ba57928d..a30f13a073 100644 --- a/tests/comment_tests/tests/test_comment_form.py +++ b/tests/comment_tests/tests/test_comment_form.py @@ -54,7 +54,7 @@ class CommentFormTests(CommentTestCase): def testGetCommentObject(self): f = self.testValidPost() c = f.get_comment_object() - self.assertTrue(isinstance(c, Comment)) + self.assertIsInstance(c, Comment) self.assertEqual(c.content_object, Article.objects.get(pk=1)) self.assertEqual(c.comment, "This is my comment") c.save() diff --git a/tests/comment_tests/tests/test_templatetags.py b/tests/comment_tests/tests/test_templatetags.py index 185f6de297..1971c21a58 100644 --- a/tests/comment_tests/tests/test_templatetags.py +++ b/tests/comment_tests/tests/test_templatetags.py @@ -32,7 +32,7 @@ class CommentTemplateTagTests(CommentTestCase): t = "{% load comments %}" + (tag or "{% get_comment_form for comment_tests.article a.id as form %}") ctx, out = self.render(t, a=Article.objects.get(pk=1)) self.assertEqual(out, "") - self.assertTrue(isinstance(ctx["form"], CommentForm)) + self.assertIsInstance(ctx["form"], CommentForm) def testGetCommentFormFromLiteral(self): self.testGetCommentForm("{% get_comment_form for comment_tests.article 1 as form %}") diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py index 294920de2b..4fe79fe3fb 100644 --- a/tests/custom_managers/tests.py +++ b/tests/custom_managers/tests.py @@ -19,7 +19,7 @@ class CustomManagerTests(TestCase): ) # The RelatedManager used on the 'books' descriptor extends the default # manager - self.assertTrue(isinstance(p2.books, PublishedBookManager)) + self.assertIsInstance(p2.books, PublishedBookManager) b1 = Book.published_objects.create( title="How to program", author="Rodney Dangerfield", is_published=True @@ -34,7 +34,7 @@ class CustomManagerTests(TestCase): # The RelatedManager used on the 'authors' descriptor extends the # default manager - self.assertTrue(isinstance(b2.authors, PersonManager)) + self.assertIsInstance(b2.authors, PersonManager) self.assertQuerysetEqual( Book.published_objects.all(), [ diff --git a/tests/datatypes/tests.py b/tests/datatypes/tests.py index f0ec5f3c0a..b6b52dedf2 100644 --- a/tests/datatypes/tests.py +++ b/tests/datatypes/tests.py @@ -74,7 +74,7 @@ class DataTypesTestCase(TestCase): database should be unicode.""" d = Donut.objects.create(name='Jelly Donut', review='Outstanding') newd = Donut.objects.get(id=d.id) - self.assertTrue(isinstance(newd.review, six.text_type)) + self.assertIsInstance(newd.review, six.text_type) @skipIfDBFeature('supports_timezones') def test_error_on_timezone(self): @@ -90,7 +90,7 @@ class DataTypesTestCase(TestCase): a Python datetime.date, not a datetime.datetime""" b = RumBaba.objects.create() # Verify we didn't break DateTimeField behavior - self.assertTrue(isinstance(b.baked_timestamp, datetime.datetime)) + self.assertIsInstance(b.baked_timestamp, datetime.datetime) # We need to test this this way because datetime.datetime inherits # from datetime.date: - self.assertTrue(isinstance(b.baked_date, datetime.date) and not isinstance(b.baked_date, datetime.datetime)) + self.assertIsInstance(b.baked_date, datetime.date) and not isinstance(b.baked_date, datetime.datetime) diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index 8a3f340e9f..05016be231 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -126,15 +126,15 @@ class DecoratorsTest(TestCase): my_safe_view = require_safe(my_view) request = HttpRequest() request.method = 'GET' - self.assertTrue(isinstance(my_safe_view(request), HttpResponse)) + self.assertIsInstance(my_safe_view(request), HttpResponse) request.method = 'HEAD' - self.assertTrue(isinstance(my_safe_view(request), HttpResponse)) + self.assertIsInstance(my_safe_view(request), HttpResponse) request.method = 'POST' - self.assertTrue(isinstance(my_safe_view(request), HttpResponseNotAllowed)) + self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed) request.method = 'PUT' - self.assertTrue(isinstance(my_safe_view(request), HttpResponseNotAllowed)) + self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed) request.method = 'DELETE' - self.assertTrue(isinstance(my_safe_view(request), HttpResponseNotAllowed)) + self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed) # For testing method_decorator, a decorator that assumes a single argument. diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index 0a0852cdd9..a97929859e 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -360,7 +360,7 @@ class DefaultFiltersTests(TestCase): escaped = force_escape(' here') self.assertEqual( escaped, '<some html & special characters > here') - self.assertTrue(isinstance(escaped, SafeData)) + self.assertIsInstance(escaped, SafeData) self.assertEqual( force_escape(' here ĐÅ€£'), '<some html & special characters > here'\ diff --git a/tests/dispatch/tests/test_dispatcher.py b/tests/dispatch/tests/test_dispatcher.py index 5f8f92acaf..a1d4c7e176 100644 --- a/tests/dispatch/tests/test_dispatcher.py +++ b/tests/dispatch/tests/test_dispatcher.py @@ -108,7 +108,7 @@ class DispatcherTests(unittest.TestCase): a_signal.connect(fails) result = a_signal.send_robust(sender=self, val="test") err = result[0][1] - self.assertTrue(isinstance(err, ValueError)) + self.assertIsInstance(err, ValueError) self.assertEqual(err.args, ('this',)) a_signal.disconnect(fails) self._testIsClean(a_signal) diff --git a/tests/field_defaults/tests.py b/tests/field_defaults/tests.py index 5d9b45610e..69dabb5168 100644 --- a/tests/field_defaults/tests.py +++ b/tests/field_defaults/tests.py @@ -14,6 +14,6 @@ class DefaultTests(TestCase): now = datetime.now() a.save() - self.assertTrue(isinstance(a.id, six.integer_types)) + self.assertIsInstance(a.id, six.integer_types) self.assertEqual(a.headline, "Default headline") self.assertTrue((now - a.pub_date).seconds < 5) diff --git a/tests/field_subclassing/tests.py b/tests/field_subclassing/tests.py index 9331ff2f3f..4945cff1bf 100644 --- a/tests/field_subclassing/tests.py +++ b/tests/field_subclassing/tests.py @@ -11,21 +11,21 @@ class CustomField(TestCase): def test_defer(self): d = DataModel.objects.create(data=[1, 2, 3]) - self.assertTrue(isinstance(d.data, list)) + self.assertIsInstance(d.data, list) d = DataModel.objects.get(pk=d.pk) - self.assertTrue(isinstance(d.data, list)) + self.assertIsInstance(d.data, list) self.assertEqual(d.data, [1, 2, 3]) d = DataModel.objects.defer("data").get(pk=d.pk) - self.assertTrue(isinstance(d.data, list)) + self.assertIsInstance(d.data, list) self.assertEqual(d.data, [1, 2, 3]) # Refetch for save d = DataModel.objects.defer("data").get(pk=d.pk) d.save() d = DataModel.objects.get(pk=d.pk) - self.assertTrue(isinstance(d.data, list)) + self.assertIsInstance(d.data, list) self.assertEqual(d.data, [1, 2, 3]) def test_custom_field(self): @@ -44,7 +44,7 @@ class CustomField(TestCase): # The data loads back from the database correctly and 'data' has the # right type. m1 = MyModel.objects.get(pk=m.pk) - self.assertTrue(isinstance(m1.data, Small)) + self.assertIsInstance(m1.data, Small) self.assertEqual(str(m1.data), "12") # We can do normal filtering on the custom field (and will get an error diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index e4b71dba82..406a4d79b6 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -588,11 +588,11 @@ class ContentFileTestCase(unittest.TestCase): Test that ContentFile can accept both bytes and unicode and that the retrieved content is of the same type. """ - self.assertTrue(isinstance(ContentFile(b"content").read(), bytes)) + self.assertIsInstance(ContentFile(b"content").read(), bytes) if six.PY3: - self.assertTrue(isinstance(ContentFile("español").read(), six.text_type)) + self.assertIsInstance(ContentFile("español").read(), six.text_type) else: - self.assertTrue(isinstance(ContentFile("español").read(), bytes)) + self.assertIsInstance(ContentFile("español").read(), bytes) def test_content_saving(self): """ diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 787f177677..767a900673 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -982,7 +982,7 @@ class FormsFormsetTestCase(TestCase): ChoiceFormSet = formset_factory(Choice, formset=BaseCustomFormSet) formset = ChoiceFormSet(data, auto_id=False, prefix='choices') - self.assertTrue(isinstance(formset.non_form_errors(), ErrorList)) + self.assertIsInstance(formset.non_form_errors(), ErrorList) self.assertEqual(list(formset.non_form_errors()), ['This is a non-form error']) diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index deda4822b8..847cd6ebdb 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -52,9 +52,9 @@ class TestTicket14567(TestCase): form = OptionalMultiChoiceModelForm({'multi_choice_optional': '', 'multi_choice': [option.pk]}) self.assertTrue(form.is_valid()) # Check that the empty value is a QuerySet - self.assertTrue(isinstance(form.cleaned_data['multi_choice_optional'], models.query.QuerySet)) + self.assertIsInstance(form.cleaned_data['multi_choice_optional'], models.query.QuerySet) # While we're at it, test whether a QuerySet is returned if there *is* a value. - self.assertTrue(isinstance(form.cleaned_data['multi_choice'], models.query.QuerySet)) + self.assertIsInstance(form.cleaned_data['multi_choice'], models.query.QuerySet) class ModelFormCallableModelDefault(TestCase): diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 79c7bc6184..3716dd7560 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -264,4 +264,4 @@ class GenericInlineFormsetTest(TestCase): def test_generic_inlineformset_factory(self): Formset = generic_inlineformset_factory(TaggedItem, TaggedItemForm) form = Formset().forms[0] - self.assertTrue(isinstance(form['tag'].field.widget, CustomWidget)) + self.assertIsInstance(form['tag'].field.widget, CustomWidget) diff --git a/tests/generic_views/test_base.py b/tests/generic_views/test_base.py index ffdad4b69f..9080015f4f 100644 --- a/tests/generic_views/test_base.py +++ b/tests/generic_views/test_base.py @@ -278,7 +278,7 @@ class TemplateViewTest(TestCase): response = self.client.get('/template/simple/bar/') self.assertEqual(response.status_code, 200) self.assertEqual(response.context['foo'], 'bar') - self.assertTrue(isinstance(response.context['view'], View)) + self.assertIsInstance(response.context['view'], View) def test_extra_template_params(self): """ @@ -288,7 +288,7 @@ class TemplateViewTest(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.context['foo'], 'bar') self.assertEqual(response.context['key'], 'value') - self.assertTrue(isinstance(response.context['view'], View)) + self.assertIsInstance(response.context['view'], View) def test_cached_views(self): """ diff --git a/tests/generic_views/test_detail.py b/tests/generic_views/test_detail.py index faee05688e..3a97d27995 100644 --- a/tests/generic_views/test_detail.py +++ b/tests/generic_views/test_detail.py @@ -15,7 +15,7 @@ class DetailViewTest(TestCase): res = self.client.get('/detail/obj/') self.assertEqual(res.status_code, 200) self.assertEqual(res.context['object'], {'foo': 'bar'}) - self.assertTrue(isinstance(res.context['view'], View)) + self.assertIsInstance(res.context['view'], View) self.assertTemplateUsed(res, 'generic_views/detail.html') def test_detail_by_pk(self): diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py index 54eab7ffa4..435e48ba99 100644 --- a/tests/generic_views/test_edit.py +++ b/tests/generic_views/test_edit.py @@ -43,8 +43,8 @@ class CreateViewTests(TestCase): def test_create(self): res = self.client.get('/edit/authors/create/') self.assertEqual(res.status_code, 200) - self.assertTrue(isinstance(res.context['form'], forms.ModelForm)) - self.assertTrue(isinstance(res.context['view'], View)) + self.assertIsInstance(res.context['form'], forms.ModelForm) + self.assertIsInstance(res.context['view'], View) self.assertFalse('object' in res.context) self.assertFalse('author' in res.context) self.assertTemplateUsed(res, 'generic_views/author_form.html') @@ -89,7 +89,7 @@ class CreateViewTests(TestCase): def test_create_with_special_properties(self): res = self.client.get('/edit/authors/create/special/') self.assertEqual(res.status_code, 200) - self.assertTrue(isinstance(res.context['form'], views.AuthorForm)) + self.assertIsInstance(res.context['form'], views.AuthorForm) self.assertFalse('object' in res.context) self.assertFalse('author' in res.context) self.assertTemplateUsed(res, 'generic_views/form.html') @@ -165,7 +165,7 @@ class UpdateViewTests(TestCase): ) res = self.client.get('/edit/author/%d/update/' % a.pk) self.assertEqual(res.status_code, 200) - self.assertTrue(isinstance(res.context['form'], forms.ModelForm)) + self.assertIsInstance(res.context['form'], forms.ModelForm) self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk)) self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk)) self.assertTemplateUsed(res, 'generic_views/author_form.html') @@ -247,7 +247,7 @@ class UpdateViewTests(TestCase): ) res = self.client.get('/edit/author/%d/update/special/' % a.pk) self.assertEqual(res.status_code, 200) - self.assertTrue(isinstance(res.context['form'], views.AuthorForm)) + self.assertIsInstance(res.context['form'], views.AuthorForm) self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk)) self.assertEqual(res.context['thingy'], Author.objects.get(pk=a.pk)) self.assertFalse('author' in res.context) @@ -279,8 +279,8 @@ class UpdateViewTests(TestCase): ) res = self.client.get('/edit/author/update/') self.assertEqual(res.status_code, 200) - self.assertTrue(isinstance(res.context['form'], forms.ModelForm)) - self.assertTrue(isinstance(res.context['view'], View)) + self.assertIsInstance(res.context['form'], forms.ModelForm) + self.assertIsInstance(res.context['view'], View) self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk)) self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk)) self.assertTemplateUsed(res, 'generic_views/author_form.html') diff --git a/tests/generic_views/test_list.py b/tests/generic_views/test_list.py index cc4d2f5966..a77a6418a3 100644 --- a/tests/generic_views/test_list.py +++ b/tests/generic_views/test_list.py @@ -24,7 +24,7 @@ class ListViewTests(TestCase): self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'generic_views/author_list.html') self.assertEqual(list(res.context['object_list']), list(Author.objects.all())) - self.assertTrue(isinstance(res.context['view'], View)) + self.assertIsInstance(res.context['view'], View) self.assertIs(res.context['author_list'], res.context['object_list']) self.assertIsNone(res.context['paginator']) self.assertIsNone(res.context['page_obj']) diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 27ae651042..8e5445cd42 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -293,7 +293,7 @@ class AdminEmailHandlerTest(TestCase): def my_mail_admins(*args, **kwargs): connection = kwargs['connection'] - self.assertTrue(isinstance(connection, MyEmailBackend)) + self.assertIsInstance(connection, MyEmailBackend) mail_admins_called['called'] = True # Monkeypatches diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 0a843db9e7..c90dc7e22a 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -251,16 +251,16 @@ class MailTests(TestCase): def test_backend_arg(self): """Test backend argument of mail.get_connection()""" - self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend)) - self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.locmem.EmailBackend'), locmem.EmailBackend)) - self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.dummy.EmailBackend'), dummy.EmailBackend)) - self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.console.EmailBackend'), console.EmailBackend)) + self.assertIsInstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend) + self.assertIsInstance(mail.get_connection('django.core.mail.backends.locmem.EmailBackend'), locmem.EmailBackend) + self.assertIsInstance(mail.get_connection('django.core.mail.backends.dummy.EmailBackend'), dummy.EmailBackend) + self.assertIsInstance(mail.get_connection('django.core.mail.backends.console.EmailBackend'), console.EmailBackend) tmp_dir = tempfile.mkdtemp() try: - self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.filebased.EmailBackend', file_path=tmp_dir), filebased.EmailBackend)) + self.assertIsInstance(mail.get_connection('django.core.mail.backends.filebased.EmailBackend', file_path=tmp_dir), filebased.EmailBackend) finally: shutil.rmtree(tmp_dir) - self.assertTrue(isinstance(mail.get_connection(), locmem.EmailBackend)) + self.assertIsInstance(mail.get_connection(), locmem.EmailBackend) @override_settings( EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend', diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index e1e38d0ec7..ccff8b8cfa 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -193,28 +193,28 @@ class BooleanFieldTests(unittest.TestCase): b.bfield = True b.save() b2 = BooleanModel.objects.get(pk=b.pk) - self.assertTrue(isinstance(b2.bfield, bool)) + self.assertIsInstance(b2.bfield, bool) self.assertEqual(b2.bfield, True) b3 = BooleanModel() b3.bfield = False b3.save() b4 = BooleanModel.objects.get(pk=b3.pk) - self.assertTrue(isinstance(b4.bfield, bool)) + self.assertIsInstance(b4.bfield, bool) self.assertEqual(b4.bfield, False) b = NullBooleanModel() b.nbfield = True b.save() b2 = NullBooleanModel.objects.get(pk=b.pk) - self.assertTrue(isinstance(b2.nbfield, bool)) + self.assertIsInstance(b2.nbfield, bool) self.assertEqual(b2.nbfield, True) b3 = NullBooleanModel() b3.nbfield = False b3.save() b4 = NullBooleanModel.objects.get(pk=b3.pk) - self.assertTrue(isinstance(b4.nbfield, bool)) + self.assertIsInstance(b4.nbfield, bool) self.assertEqual(b4.nbfield, False) # http://code.djangoproject.com/ticket/13293 @@ -371,11 +371,11 @@ class BigIntegerFieldTests(test.TestCase): def test_types(self): b = BigInt(value = 0) - self.assertTrue(isinstance(b.value, six.integer_types)) + self.assertIsInstance(b.value, six.integer_types) b.save() - self.assertTrue(isinstance(b.value, six.integer_types)) + self.assertIsInstance(b.value, six.integer_types) b = BigInt.objects.all()[0] - self.assertTrue(isinstance(b.value, six.integer_types)) + self.assertIsInstance(b.value, six.integer_types) def test_coercing(self): BigInt.objects.create(value ='10') diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index c5db011404..db8b6cf0e7 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -274,8 +274,8 @@ class ModelFormBaseTest(TestCase): model = Category fields = '__all__' - self.assertTrue(isinstance(ReplaceField.base_fields['url'], - forms.fields.BooleanField)) + self.assertIsInstance(ReplaceField.base_fields['url'], + forms.fields.BooleanField) def test_replace_field_variant_2(self): # Should have the same result as before, @@ -287,8 +287,8 @@ class ModelFormBaseTest(TestCase): model = Category fields = ['url'] - self.assertTrue(isinstance(ReplaceField.base_fields['url'], - forms.fields.BooleanField)) + self.assertIsInstance(ReplaceField.base_fields['url'], + forms.fields.BooleanField) def test_replace_field_variant_3(self): # Should have the same result as before, @@ -300,8 +300,8 @@ class ModelFormBaseTest(TestCase): model = Category fields = [] # url will still appear, since it is explicit above - self.assertTrue(isinstance(ReplaceField.base_fields['url'], - forms.fields.BooleanField)) + self.assertIsInstance(ReplaceField.base_fields['url'], + forms.fields.BooleanField) def test_override_field(self): class AuthorForm(forms.ModelForm): diff --git a/tests/model_formsets_regress/tests.py b/tests/model_formsets_regress/tests.py index c8fb1e76c1..179f79fbcb 100644 --- a/tests/model_formsets_regress/tests.py +++ b/tests/model_formsets_regress/tests.py @@ -236,11 +236,11 @@ class FormsetTests(TestCase): formset = Formset(data) # check if the returned error classes are correct # note: formset.errors returns a list as documented - self.assertTrue(isinstance(formset.errors, list)) - self.assertTrue(isinstance(formset.non_form_errors(), ErrorList)) + self.assertIsInstance(formset.errors, list) + self.assertIsInstance(formset.non_form_errors(), ErrorList) for form in formset.forms: - self.assertTrue(isinstance(form.errors, ErrorDict)) - self.assertTrue(isinstance(form.non_field_errors(), ErrorList)) + self.assertIsInstance(form.errors, ErrorDict) + self.assertIsInstance(form.non_field_errors(), ErrorList) def test_initial_data(self): User.objects.create(username="bibi", serial=1) @@ -296,16 +296,16 @@ class FormfieldCallbackTests(TestCase): def test_inlineformset_factory_default(self): Formset = inlineformset_factory(User, UserSite, form=UserSiteForm, fields="__all__") form = Formset().forms[0] - self.assertTrue(isinstance(form['id'].field.widget, CustomWidget)) - self.assertTrue(isinstance(form['data'].field.widget, CustomWidget)) + self.assertIsInstance(form['id'].field.widget, CustomWidget) + self.assertIsInstance(form['data'].field.widget, CustomWidget) self.assertFalse(form.fields['id'].localize) self.assertTrue(form.fields['data'].localize) def test_modelformset_factory_default(self): Formset = modelformset_factory(UserSite, form=UserSiteForm) form = Formset().forms[0] - self.assertTrue(isinstance(form['id'].field.widget, CustomWidget)) - self.assertTrue(isinstance(form['data'].field.widget, CustomWidget)) + self.assertIsInstance(form['id'].field.widget, CustomWidget) + self.assertIsInstance(form['data'].field.widget, CustomWidget) self.assertFalse(form.fields['id'].localize) self.assertTrue(form.fields['data'].localize) diff --git a/tests/unmanaged_models/tests.py b/tests/unmanaged_models/tests.py index 64e33bbb47..d7cf961a37 100644 --- a/tests/unmanaged_models/tests.py +++ b/tests/unmanaged_models/tests.py @@ -23,14 +23,14 @@ class SimpleTests(TestCase): # ... and pull it out via the other set. a2 = A02.objects.all()[0] - self.assertTrue(isinstance(a2, A02)) + self.assertIsInstance(a2, A02) self.assertEqual(a2.f_a, "foo") b2 = B02.objects.all()[0] - self.assertTrue(isinstance(b2, B02)) + self.assertIsInstance(b2, B02) self.assertEqual(b2.f_a, "fred") - self.assertTrue(isinstance(b2.fk_a, A02)) + self.assertIsInstance(b2.fk_a, A02) self.assertEqual(b2.fk_a.f_a, "foo") self.assertEqual(list(C02.objects.filter(f_a=None)), []) @@ -38,7 +38,7 @@ class SimpleTests(TestCase): resp = list(C02.objects.filter(mm_a=a.id)) self.assertEqual(len(resp), 1) - self.assertTrue(isinstance(resp[0], C02)) + self.assertIsInstance(resp[0], C02) self.assertEqual(resp[0].f_a, 'barney') diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py index 24f96fac7c..d5d9b3a709 100644 --- a/tests/urlpatterns_reverse/tests.py +++ b/tests/urlpatterns_reverse/tests.py @@ -246,7 +246,7 @@ class ResolverTests(unittest.TestCase): self.assertEqual(len(e.args[0]['tried']), len(url_types_names), 'Wrong number of tried URLs returned. Expected %s, got %s.' % (len(url_types_names), len(e.args[0]['tried']))) for tried, expected in zip(e.args[0]['tried'], url_types_names): for t, e in zip(tried, expected): - self.assertTrue(isinstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type'])) + self.assertIsInstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type']) if 'name' in e: if not e['name']: self.assertTrue(t.name is None, 'Expected no URL name but found %s.' % t.name) @@ -278,11 +278,11 @@ class ReverseShortcutTests(TestCase): return "/hi-there/" res = redirect(FakeObj()) - self.assertTrue(isinstance(res, HttpResponseRedirect)) + self.assertIsInstance(res, HttpResponseRedirect) self.assertEqual(res.url, '/hi-there/') res = redirect(FakeObj(), permanent=True) - self.assertTrue(isinstance(res, HttpResponsePermanentRedirect)) + self.assertIsInstance(res, HttpResponsePermanentRedirect) self.assertEqual(res.url, '/hi-there/') def test_redirect_to_view_name(self): diff --git a/tests/utils_tests/test_baseconv.py b/tests/utils_tests/test_baseconv.py index cc413b4e8e..ee545b432b 100644 --- a/tests/utils_tests/test_baseconv.py +++ b/tests/utils_tests/test_baseconv.py @@ -39,4 +39,4 @@ class TestBaseConv(TestCase): def test_exception(self): self.assertRaises(ValueError, BaseConverter, 'abc', sign='a') - self.assertTrue(isinstance(BaseConverter('abc', sign='d'), BaseConverter)) + self.assertIsInstance(BaseConverter('abc', sign='d'), BaseConverter) diff --git a/tests/utils_tests/test_simplelazyobject.py b/tests/utils_tests/test_simplelazyobject.py index ca7c2672eb..4c01bd3adf 100644 --- a/tests/utils_tests/test_simplelazyobject.py +++ b/tests/utils_tests/test_simplelazyobject.py @@ -68,7 +68,7 @@ class TestUtilsSimpleLazyObject(TestCase): # Second, for an evaluated SimpleLazyObject name = x.name # evaluate - self.assertTrue(isinstance(x._wrapped, _ComplexObject)) + self.assertIsInstance(x._wrapped, _ComplexObject) # __repr__ contains __repr__ of wrapped object self.assertEqual("" % x._wrapped, repr(x)) diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py index bdd9fbfc0b..6104ad063e 100644 --- a/tests/view_tests/tests/test_static.py +++ b/tests/view_tests/tests/test_static.py @@ -60,7 +60,7 @@ class StaticTests(TestCase): # This is 24h before max Unix time. Remember to fix Django and # update this test well before 2038 :) ) - self.assertTrue(isinstance(response, HttpResponseNotModified)) + self.assertIsInstance(response, HttpResponseNotModified) def test_invalid_if_modified_since(self): """Handle bogus If-Modified-Since values gracefully