Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1192 from mjtamlyn/assertIsInstance

Use assertIsInstance in test code.
  • Loading branch information...
commit b632baac3c56101d59f6279767e5f3418643e425 2 parents 60585f6 + 09f8652
Marc Tamlyn authored

Showing 31 changed files with 87 additions and 87 deletions. Show diff stats Hide diff stats

  1. 2  tests/admin_views/tests.py
  2. 2  tests/backends/tests.py
  3. 10  tests/basic/tests.py
  4. 8  tests/cache/tests.py
  5. 2  tests/comment_tests/tests/test_comment_form.py
  6. 2  tests/comment_tests/tests/test_templatetags.py
  7. 4  tests/custom_managers/tests.py
  8. 6  tests/datatypes/tests.py
  9. 10  tests/decorators/tests.py
  10. 2  tests/defaultfilters/tests.py
  11. 2  tests/dispatch/tests/test_dispatcher.py
  12. 2  tests/field_defaults/tests.py
  13. 10  tests/field_subclassing/tests.py
  14. 6  tests/file_storage/tests.py
  15. 2  tests/forms_tests/tests/test_formsets.py
  16. 4  tests/forms_tests/tests/tests.py
  17. 2  tests/generic_relations/tests.py
  18. 4  tests/generic_views/test_base.py
  19. 2  tests/generic_views/test_detail.py
  20. 14  tests/generic_views/test_edit.py
  21. 2  tests/generic_views/test_list.py
  22. 2  tests/logging_tests/tests.py
  23. 12  tests/mail/tests.py
  24. 14  tests/model_fields/tests.py
  25. 12  tests/model_forms/tests.py
  26. 16  tests/model_formsets_regress/tests.py
  27. 8  tests/unmanaged_models/tests.py
  28. 6  tests/urlpatterns_reverse/tests.py
  29. 2  tests/utils_tests/test_baseconv.py
  30. 2  tests/utils_tests/test_simplelazyobject.py
  31. 2  tests/view_tests/tests/test_static.py
2  tests/admin_views/tests.py
@@ -1995,7 +1995,7 @@ def test_non_form_errors_is_errorlist(self):
1995 1995
         }
1996 1996
         response = self.client.post('/test_admin/admin/admin_views/person/', data)
1997 1997
         non_form_errors = response.context['cl'].formset.non_form_errors()
1998  
-        self.assertTrue(isinstance(non_form_errors, ErrorList))
  1998
+        self.assertIsInstance(non_form_errors, ErrorList)
1999 1999
         self.assertEqual(str(non_form_errors), str(ErrorList(["Grace is not a Zombie"])))
2000 2000
 
2001 2001
     def test_list_editable_ordering(self):
2  tests/backends/tests.py
@@ -172,7 +172,7 @@ def test_query_encoding(self):
172 172
         sql, params = persons.query.sql_with_params()
173 173
         cursor = persons.query.get_compiler('default').execute_sql(None)
174 174
         last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
175  
-        self.assertTrue(isinstance(last_sql, six.text_type))
  175
+        self.assertIsInstance(last_sql, six.text_type)
176 176
 
177 177
     @unittest.skipUnless(connection.vendor == 'sqlite',
178 178
                          "This test is specific to SQLite.")
10  tests/basic/tests.py
@@ -432,7 +432,7 @@ def test_object_creation(self):
432 432
             Article.objects.all()[0:-5]
433 433
         except Exception as e:
434 434
             error = e
435  
-        self.assertTrue(isinstance(error, AssertionError))
  435
+        self.assertIsInstance(error, AssertionError)
436 436
         self.assertEqual(str(error), "Negative indexing is not supported.")
437 437
 
438 438
         # An Article instance doesn't have access to the "objects" attribute.
@@ -637,15 +637,15 @@ def test_emptyqs(self):
637 637
         # Can't be instantiated
638 638
         with self.assertRaises(TypeError):
639 639
             EmptyQuerySet()
640  
-        self.assertTrue(isinstance(Article.objects.none(), EmptyQuerySet))
  640
+        self.assertIsInstance(Article.objects.none(), EmptyQuerySet)
641 641
 
642 642
     def test_emptyqs_values(self):
643 643
         # test for #15959
644 644
         Article.objects.create(headline='foo', pub_date=datetime.now())
645 645
         with self.assertNumQueries(0):
646 646
             qs = Article.objects.none().values_list('pk')
647  
-            self.assertTrue(isinstance(qs, EmptyQuerySet))
648  
-            self.assertTrue(isinstance(qs, ValuesListQuerySet))
  647
+            self.assertIsInstance(qs, EmptyQuerySet)
  648
+            self.assertIsInstance(qs, ValuesListQuerySet)
649 649
             self.assertEqual(len(qs), 0)
650 650
 
651 651
     def test_emptyqs_customqs(self):
@@ -660,7 +660,7 @@ def do_something(self):
660 660
         qs = qs.none()
661 661
         with self.assertNumQueries(0):
662 662
             self.assertEqual(len(qs), 0)
663  
-            self.assertTrue(isinstance(qs, EmptyQuerySet))
  663
+            self.assertIsInstance(qs, EmptyQuerySet)
664 664
             self.assertEqual(qs.do_something(), 'did something')
665 665
 
666 666
     def test_emptyqs_values_order(self):
8  tests/cache/tests.py
@@ -510,13 +510,13 @@ def func(key, *args):
510 510
                 # memcached does not allow whitespace or control characters in keys
511 511
                 self.cache.set('key with spaces', 'value')
512 512
                 self.assertEqual(len(w), 2)
513  
-                self.assertTrue(isinstance(w[0].message, CacheKeyWarning))
  513
+                self.assertIsInstance(w[0].message, CacheKeyWarning)
514 514
             with warnings.catch_warnings(record=True) as w:
515 515
                 warnings.simplefilter("always")
516 516
                 # memcached limits key length to 250
517 517
                 self.cache.set('a' * 251, 'value')
518 518
                 self.assertEqual(len(w), 1)
519  
-                self.assertTrue(isinstance(w[0].message, CacheKeyWarning))
  519
+                self.assertIsInstance(w[0].message, CacheKeyWarning)
520 520
         finally:
521 521
             self.cache.key_func = old_func
522 522
 
@@ -1097,10 +1097,10 @@ class GetCacheTests(unittest.TestCase):
1097 1097
     def test_simple(self):
1098 1098
         cache = get_cache('locmem://')
1099 1099
         from django.core.cache.backends.locmem import LocMemCache
1100  
-        self.assertTrue(isinstance(cache, LocMemCache))
  1100
+        self.assertIsInstance(cache, LocMemCache)
1101 1101
 
1102 1102
         from django.core.cache import cache
1103  
-        self.assertTrue(isinstance(cache, get_cache('default').__class__))
  1103
+        self.assertIsInstance(cache, get_cache('default').__class__)
1104 1104
 
1105 1105
         cache = get_cache(
1106 1106
             'django.core.cache.backends.dummy.DummyCache', **{'TIMEOUT': 120})
2  tests/comment_tests/tests/test_comment_form.py
@@ -54,7 +54,7 @@ def testSecurityErrors(self):
54 54
     def testGetCommentObject(self):
55 55
         f = self.testValidPost()
56 56
         c = f.get_comment_object()
57  
-        self.assertTrue(isinstance(c, Comment))
  57
+        self.assertIsInstance(c, Comment)
58 58
         self.assertEqual(c.content_object, Article.objects.get(pk=1))
59 59
         self.assertEqual(c.comment, "This is my comment")
60 60
         c.save()
2  tests/comment_tests/tests/test_templatetags.py
@@ -32,7 +32,7 @@ def testGetCommentForm(self, tag=None):
32 32
         t = "{% load comments %}" + (tag or "{% get_comment_form for comment_tests.article a.id as form %}")
33 33
         ctx, out = self.render(t, a=Article.objects.get(pk=1))
34 34
         self.assertEqual(out, "")
35  
-        self.assertTrue(isinstance(ctx["form"], CommentForm))
  35
+        self.assertIsInstance(ctx["form"], CommentForm)
36 36
 
37 37
     def testGetCommentFormFromLiteral(self):
38 38
         self.testGetCommentForm("{% get_comment_form for comment_tests.article 1 as form %}")
4  tests/custom_managers/tests.py
@@ -19,7 +19,7 @@ def test_manager(self):
19 19
         )
20 20
         # The RelatedManager used on the 'books' descriptor extends the default
21 21
         # manager
22  
-        self.assertTrue(isinstance(p2.books, PublishedBookManager))
  22
+        self.assertIsInstance(p2.books, PublishedBookManager)
23 23
 
24 24
         b1 = Book.published_objects.create(
25 25
             title="How to program", author="Rodney Dangerfield", is_published=True
@@ -34,7 +34,7 @@ def test_manager(self):
34 34
 
35 35
         # The RelatedManager used on the 'authors' descriptor extends the
36 36
         # default manager
37  
-        self.assertTrue(isinstance(b2.authors, PersonManager))
  37
+        self.assertIsInstance(b2.authors, PersonManager)
38 38
 
39 39
         self.assertQuerysetEqual(
40 40
             Book.published_objects.all(), [
6  tests/datatypes/tests.py
@@ -74,7 +74,7 @@ def test_textfields_unicode(self):
74 74
         database should be unicode."""
75 75
         d = Donut.objects.create(name='Jelly Donut', review='Outstanding')
76 76
         newd = Donut.objects.get(id=d.id)
77  
-        self.assertTrue(isinstance(newd.review, six.text_type))
  77
+        self.assertIsInstance(newd.review, six.text_type)
78 78
 
79 79
     @skipIfDBFeature('supports_timezones')
80 80
     def test_error_on_timezone(self):
@@ -90,7 +90,7 @@ def test_datefield_auto_now_add(self):
90 90
         a Python datetime.date, not a datetime.datetime"""
91 91
         b = RumBaba.objects.create()
92 92
         # Verify we didn't break DateTimeField behavior
93  
-        self.assertTrue(isinstance(b.baked_timestamp, datetime.datetime))
  93
+        self.assertIsInstance(b.baked_timestamp, datetime.datetime)
94 94
         # We need to test this this way because datetime.datetime inherits
95 95
         # from datetime.date:
96  
-        self.assertTrue(isinstance(b.baked_date, datetime.date) and not isinstance(b.baked_date, datetime.datetime))
  96
+        self.assertIsInstance(b.baked_date, datetime.date) and not isinstance(b.baked_date, datetime.datetime)
10  tests/decorators/tests.py
@@ -126,15 +126,15 @@ def my_view(request):
126 126
         my_safe_view = require_safe(my_view)
127 127
         request = HttpRequest()
128 128
         request.method = 'GET'
129  
-        self.assertTrue(isinstance(my_safe_view(request), HttpResponse))
  129
+        self.assertIsInstance(my_safe_view(request), HttpResponse)
130 130
         request.method = 'HEAD'
131  
-        self.assertTrue(isinstance(my_safe_view(request), HttpResponse))
  131
+        self.assertIsInstance(my_safe_view(request), HttpResponse)
132 132
         request.method = 'POST'
133  
-        self.assertTrue(isinstance(my_safe_view(request), HttpResponseNotAllowed))
  133
+        self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed)
134 134
         request.method = 'PUT'
135  
-        self.assertTrue(isinstance(my_safe_view(request), HttpResponseNotAllowed))
  135
+        self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed)
136 136
         request.method = 'DELETE'
137  
-        self.assertTrue(isinstance(my_safe_view(request), HttpResponseNotAllowed))
  137
+        self.assertIsInstance(my_safe_view(request), HttpResponseNotAllowed)
138 138
 
139 139
 
140 140
 # For testing method_decorator, a decorator that assumes a single argument.
2  tests/defaultfilters/tests.py
@@ -360,7 +360,7 @@ def test_force_escape(self):
360 360
         escaped = force_escape('<some html & special characters > here')
361 361
         self.assertEqual(
362 362
             escaped, '&lt;some html &amp; special characters &gt; here')
363  
-        self.assertTrue(isinstance(escaped, SafeData))
  363
+        self.assertIsInstance(escaped, SafeData)
364 364
         self.assertEqual(
365 365
             force_escape('<some html & special characters > here ĐÅ€£'),
366 366
             '&lt;some html &amp; special characters &gt; here'\
2  tests/dispatch/tests/test_dispatcher.py
@@ -108,7 +108,7 @@ def fails(val, **kwargs):
108 108
         a_signal.connect(fails)
109 109
         result = a_signal.send_robust(sender=self, val="test")
110 110
         err = result[0][1]
111  
-        self.assertTrue(isinstance(err, ValueError))
  111
+        self.assertIsInstance(err, ValueError)
112 112
         self.assertEqual(err.args, ('this',))
113 113
         a_signal.disconnect(fails)
114 114
         self._testIsClean(a_signal)
2  tests/field_defaults/tests.py
@@ -14,6 +14,6 @@ def test_field_defaults(self):
14 14
         now = datetime.now()
15 15
         a.save()
16 16
 
17  
-        self.assertTrue(isinstance(a.id, six.integer_types))
  17
+        self.assertIsInstance(a.id, six.integer_types)
18 18
         self.assertEqual(a.headline, "Default headline")
19 19
         self.assertTrue((now - a.pub_date).seconds < 5)
10  tests/field_subclassing/tests.py
@@ -11,21 +11,21 @@ class CustomField(TestCase):
11 11
     def test_defer(self):
12 12
         d = DataModel.objects.create(data=[1, 2, 3])
13 13
 
14  
-        self.assertTrue(isinstance(d.data, list))
  14
+        self.assertIsInstance(d.data, list)
15 15
 
16 16
         d = DataModel.objects.get(pk=d.pk)
17  
-        self.assertTrue(isinstance(d.data, list))
  17
+        self.assertIsInstance(d.data, list)
18 18
         self.assertEqual(d.data, [1, 2, 3])
19 19
 
20 20
         d = DataModel.objects.defer("data").get(pk=d.pk)
21  
-        self.assertTrue(isinstance(d.data, list))
  21
+        self.assertIsInstance(d.data, list)
22 22
         self.assertEqual(d.data, [1, 2, 3])
23 23
         # Refetch for save
24 24
         d = DataModel.objects.defer("data").get(pk=d.pk)
25 25
         d.save()
26 26
 
27 27
         d = DataModel.objects.get(pk=d.pk)
28  
-        self.assertTrue(isinstance(d.data, list))
  28
+        self.assertIsInstance(d.data, list)
29 29
         self.assertEqual(d.data, [1, 2, 3])
30 30
 
31 31
     def test_custom_field(self):
@@ -44,7 +44,7 @@ def test_custom_field(self):
44 44
         # The data loads back from the database correctly and 'data' has the
45 45
         # right type.
46 46
         m1 = MyModel.objects.get(pk=m.pk)
47  
-        self.assertTrue(isinstance(m1.data, Small))
  47
+        self.assertIsInstance(m1.data, Small)
48 48
         self.assertEqual(str(m1.data), "12")
49 49
 
50 50
         # We can do normal filtering on the custom field (and will get an error
6  tests/file_storage/tests.py
@@ -588,11 +588,11 @@ def test_content_file_input_type(self):
588 588
         Test that ContentFile can accept both bytes and unicode and that the
589 589
         retrieved content is of the same type.
590 590
         """
591  
-        self.assertTrue(isinstance(ContentFile(b"content").read(), bytes))
  591
+        self.assertIsInstance(ContentFile(b"content").read(), bytes)
592 592
         if six.PY3:
593  
-            self.assertTrue(isinstance(ContentFile("español").read(), six.text_type))
  593
+            self.assertIsInstance(ContentFile("español").read(), six.text_type)
594 594
         else:
595  
-            self.assertTrue(isinstance(ContentFile("español").read(), bytes))
  595
+            self.assertIsInstance(ContentFile("español").read(), bytes)
596 596
 
597 597
     def test_content_saving(self):
598 598
         """
2  tests/forms_tests/tests/test_formsets.py
@@ -982,7 +982,7 @@ def clean(self):
982 982
 
983 983
         ChoiceFormSet = formset_factory(Choice, formset=BaseCustomFormSet)
984 984
         formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
985  
-        self.assertTrue(isinstance(formset.non_form_errors(), ErrorList))
  985
+        self.assertIsInstance(formset.non_form_errors(), ErrorList)
986 986
         self.assertEqual(list(formset.non_form_errors()),
987 987
             ['This is a non-form error'])
988 988
 
4  tests/forms_tests/tests/tests.py
@@ -52,9 +52,9 @@ def test_empty_queryset_return(self):
52 52
         form = OptionalMultiChoiceModelForm({'multi_choice_optional': '', 'multi_choice': [option.pk]})
53 53
         self.assertTrue(form.is_valid())
54 54
         # Check that the empty value is a QuerySet
55  
-        self.assertTrue(isinstance(form.cleaned_data['multi_choice_optional'], models.query.QuerySet))
  55
+        self.assertIsInstance(form.cleaned_data['multi_choice_optional'], models.query.QuerySet)
56 56
         # While we're at it, test whether a QuerySet is returned if there *is* a value.
57  
-        self.assertTrue(isinstance(form.cleaned_data['multi_choice'], models.query.QuerySet))
  57
+        self.assertIsInstance(form.cleaned_data['multi_choice'], models.query.QuerySet)
58 58
 
59 59
 
60 60
 class ModelFormCallableModelDefault(TestCase):
2  tests/generic_relations/tests.py
@@ -264,4 +264,4 @@ class GenericInlineFormsetTest(TestCase):
264 264
     def test_generic_inlineformset_factory(self):
265 265
         Formset = generic_inlineformset_factory(TaggedItem, TaggedItemForm)
266 266
         form = Formset().forms[0]
267  
-        self.assertTrue(isinstance(form['tag'].field.widget, CustomWidget))
  267
+        self.assertIsInstance(form['tag'].field.widget, CustomWidget)
4  tests/generic_views/test_base.py
@@ -278,7 +278,7 @@ def test_template_params(self):
278 278
         response = self.client.get('/template/simple/bar/')
279 279
         self.assertEqual(response.status_code, 200)
280 280
         self.assertEqual(response.context['foo'], 'bar')
281  
-        self.assertTrue(isinstance(response.context['view'], View))
  281
+        self.assertIsInstance(response.context['view'], View)
282 282
 
283 283
     def test_extra_template_params(self):
284 284
         """
@@ -288,7 +288,7 @@ def test_extra_template_params(self):
288 288
         self.assertEqual(response.status_code, 200)
289 289
         self.assertEqual(response.context['foo'], 'bar')
290 290
         self.assertEqual(response.context['key'], 'value')
291  
-        self.assertTrue(isinstance(response.context['view'], View))
  291
+        self.assertIsInstance(response.context['view'], View)
292 292
 
293 293
     def test_cached_views(self):
294 294
         """
2  tests/generic_views/test_detail.py
@@ -15,7 +15,7 @@ def test_simple_object(self):
15 15
         res = self.client.get('/detail/obj/')
16 16
         self.assertEqual(res.status_code, 200)
17 17
         self.assertEqual(res.context['object'], {'foo': 'bar'})
18  
-        self.assertTrue(isinstance(res.context['view'], View))
  18
+        self.assertIsInstance(res.context['view'], View)
19 19
         self.assertTemplateUsed(res, 'generic_views/detail.html')
20 20
 
21 21
     def test_detail_by_pk(self):
14  tests/generic_views/test_edit.py
@@ -43,8 +43,8 @@ class CreateViewTests(TestCase):
43 43
     def test_create(self):
44 44
         res = self.client.get('/edit/authors/create/')
45 45
         self.assertEqual(res.status_code, 200)
46  
-        self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
47  
-        self.assertTrue(isinstance(res.context['view'], View))
  46
+        self.assertIsInstance(res.context['form'], forms.ModelForm)
  47
+        self.assertIsInstance(res.context['view'], View)
48 48
         self.assertFalse('object' in res.context)
49 49
         self.assertFalse('author' in res.context)
50 50
         self.assertTemplateUsed(res, 'generic_views/author_form.html')
@@ -89,7 +89,7 @@ def test_create_with_interpolated_redirect(self):
89 89
     def test_create_with_special_properties(self):
90 90
         res = self.client.get('/edit/authors/create/special/')
91 91
         self.assertEqual(res.status_code, 200)
92  
-        self.assertTrue(isinstance(res.context['form'], views.AuthorForm))
  92
+        self.assertIsInstance(res.context['form'], views.AuthorForm)
93 93
         self.assertFalse('object' in res.context)
94 94
         self.assertFalse('author' in res.context)
95 95
         self.assertTemplateUsed(res, 'generic_views/form.html')
@@ -165,7 +165,7 @@ def test_update_post(self):
165 165
         )
166 166
         res = self.client.get('/edit/author/%d/update/' % a.pk)
167 167
         self.assertEqual(res.status_code, 200)
168  
-        self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
  168
+        self.assertIsInstance(res.context['form'], forms.ModelForm)
169 169
         self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
170 170
         self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
171 171
         self.assertTemplateUsed(res, 'generic_views/author_form.html')
@@ -247,7 +247,7 @@ def test_update_with_special_properties(self):
247 247
         )
248 248
         res = self.client.get('/edit/author/%d/update/special/' % a.pk)
249 249
         self.assertEqual(res.status_code, 200)
250  
-        self.assertTrue(isinstance(res.context['form'], views.AuthorForm))
  250
+        self.assertIsInstance(res.context['form'], views.AuthorForm)
251 251
         self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
252 252
         self.assertEqual(res.context['thingy'], Author.objects.get(pk=a.pk))
253 253
         self.assertFalse('author' in res.context)
@@ -279,8 +279,8 @@ def test_update_get_object(self):
279 279
         )
280 280
         res = self.client.get('/edit/author/update/')
281 281
         self.assertEqual(res.status_code, 200)
282  
-        self.assertTrue(isinstance(res.context['form'], forms.ModelForm))
283  
-        self.assertTrue(isinstance(res.context['view'], View))
  282
+        self.assertIsInstance(res.context['form'], forms.ModelForm)
  283
+        self.assertIsInstance(res.context['view'], View)
284 284
         self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
285 285
         self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
286 286
         self.assertTemplateUsed(res, 'generic_views/author_form.html')
2  tests/generic_views/test_list.py
@@ -24,7 +24,7 @@ def test_queryset(self):
24 24
         self.assertEqual(res.status_code, 200)
25 25
         self.assertTemplateUsed(res, 'generic_views/author_list.html')
26 26
         self.assertEqual(list(res.context['object_list']), list(Author.objects.all()))
27  
-        self.assertTrue(isinstance(res.context['view'], View))
  27
+        self.assertIsInstance(res.context['view'], View)
28 28
         self.assertIs(res.context['author_list'], res.context['object_list'])
29 29
         self.assertIsNone(res.context['paginator'])
30 30
         self.assertIsNone(res.context['page_obj'])
2  tests/logging_tests/tests.py
@@ -293,7 +293,7 @@ def test_uses_custom_email_backend(self):
293 293
 
294 294
         def my_mail_admins(*args, **kwargs):
295 295
             connection = kwargs['connection']
296  
-            self.assertTrue(isinstance(connection, MyEmailBackend))
  296
+            self.assertIsInstance(connection, MyEmailBackend)
297 297
             mail_admins_called['called'] = True
298 298
 
299 299
         # Monkeypatches
12  tests/mail/tests.py
@@ -251,16 +251,16 @@ def test_custom_backend(self):
251 251
 
252 252
     def test_backend_arg(self):
253 253
         """Test backend argument of mail.get_connection()"""
254  
-        self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend))
255  
-        self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.locmem.EmailBackend'), locmem.EmailBackend))
256  
-        self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.dummy.EmailBackend'), dummy.EmailBackend))
257  
-        self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.console.EmailBackend'), console.EmailBackend))
  254
+        self.assertIsInstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend)
  255
+        self.assertIsInstance(mail.get_connection('django.core.mail.backends.locmem.EmailBackend'), locmem.EmailBackend)
  256
+        self.assertIsInstance(mail.get_connection('django.core.mail.backends.dummy.EmailBackend'), dummy.EmailBackend)
  257
+        self.assertIsInstance(mail.get_connection('django.core.mail.backends.console.EmailBackend'), console.EmailBackend)
258 258
         tmp_dir = tempfile.mkdtemp()
259 259
         try:
260  
-            self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.filebased.EmailBackend', file_path=tmp_dir), filebased.EmailBackend))
  260
+            self.assertIsInstance(mail.get_connection('django.core.mail.backends.filebased.EmailBackend', file_path=tmp_dir), filebased.EmailBackend)
261 261
         finally:
262 262
             shutil.rmtree(tmp_dir)
263  
-        self.assertTrue(isinstance(mail.get_connection(), locmem.EmailBackend))
  263
+        self.assertIsInstance(mail.get_connection(), locmem.EmailBackend)
264 264
 
265 265
     @override_settings(
266 266
         EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend',
14  tests/model_fields/tests.py
@@ -193,28 +193,28 @@ def test_return_type(self):
193 193
         b.bfield = True
194 194
         b.save()
195 195
         b2 = BooleanModel.objects.get(pk=b.pk)
196  
-        self.assertTrue(isinstance(b2.bfield, bool))
  196
+        self.assertIsInstance(b2.bfield, bool)
197 197
         self.assertEqual(b2.bfield, True)
198 198
 
199 199
         b3 = BooleanModel()
200 200
         b3.bfield = False
201 201
         b3.save()
202 202
         b4 = BooleanModel.objects.get(pk=b3.pk)
203  
-        self.assertTrue(isinstance(b4.bfield, bool))
  203
+        self.assertIsInstance(b4.bfield, bool)
204 204
         self.assertEqual(b4.bfield, False)
205 205
 
206 206
         b = NullBooleanModel()
207 207
         b.nbfield = True
208 208
         b.save()
209 209
         b2 = NullBooleanModel.objects.get(pk=b.pk)
210  
-        self.assertTrue(isinstance(b2.nbfield, bool))
  210
+        self.assertIsInstance(b2.nbfield, bool)
211 211
         self.assertEqual(b2.nbfield, True)
212 212
 
213 213
         b3 = NullBooleanModel()
214 214
         b3.nbfield = False
215 215
         b3.save()
216 216
         b4 = NullBooleanModel.objects.get(pk=b3.pk)
217  
-        self.assertTrue(isinstance(b4.nbfield, bool))
  217
+        self.assertIsInstance(b4.nbfield, bool)
218 218
         self.assertEqual(b4.nbfield, False)
219 219
 
220 220
         # http://code.djangoproject.com/ticket/13293
@@ -371,11 +371,11 @@ def test_limits(self):
371 371
 
372 372
     def test_types(self):
373 373
         b = BigInt(value = 0)
374  
-        self.assertTrue(isinstance(b.value, six.integer_types))
  374
+        self.assertIsInstance(b.value, six.integer_types)
375 375
         b.save()
376  
-        self.assertTrue(isinstance(b.value, six.integer_types))
  376
+        self.assertIsInstance(b.value, six.integer_types)
377 377
         b = BigInt.objects.all()[0]
378  
-        self.assertTrue(isinstance(b.value, six.integer_types))
  378
+        self.assertIsInstance(b.value, six.integer_types)
379 379
 
380 380
     def test_coercing(self):
381 381
         BigInt.objects.create(value ='10')
12  tests/model_forms/tests.py
@@ -274,8 +274,8 @@ class Meta:
274 274
                 model = Category
275 275
                 fields = '__all__'
276 276
 
277  
-        self.assertTrue(isinstance(ReplaceField.base_fields['url'],
278  
-                                     forms.fields.BooleanField))
  277
+        self.assertIsInstance(ReplaceField.base_fields['url'],
  278
+                                     forms.fields.BooleanField)
279 279
 
280 280
     def test_replace_field_variant_2(self):
281 281
         # Should have the same result as before,
@@ -287,8 +287,8 @@ class Meta:
287 287
                 model = Category
288 288
                 fields = ['url']
289 289
 
290  
-        self.assertTrue(isinstance(ReplaceField.base_fields['url'],
291  
-                                     forms.fields.BooleanField))
  290
+        self.assertIsInstance(ReplaceField.base_fields['url'],
  291
+                                     forms.fields.BooleanField)
292 292
 
293 293
     def test_replace_field_variant_3(self):
294 294
         # Should have the same result as before,
@@ -300,8 +300,8 @@ class Meta:
300 300
                 model = Category
301 301
                 fields = [] # url will still appear, since it is explicit above
302 302
 
303  
-        self.assertTrue(isinstance(ReplaceField.base_fields['url'],
304  
-                                     forms.fields.BooleanField))
  303
+        self.assertIsInstance(ReplaceField.base_fields['url'],
  304
+                                     forms.fields.BooleanField)
305 305
 
306 306
     def test_override_field(self):
307 307
         class AuthorForm(forms.ModelForm):
16  tests/model_formsets_regress/tests.py
@@ -236,11 +236,11 @@ def test_error_class(self):
236 236
         formset = Formset(data)
237 237
         # check if the returned error classes are correct
238 238
         # note: formset.errors returns a list as documented
239  
-        self.assertTrue(isinstance(formset.errors, list))
240  
-        self.assertTrue(isinstance(formset.non_form_errors(), ErrorList))
  239
+        self.assertIsInstance(formset.errors, list)
  240
+        self.assertIsInstance(formset.non_form_errors(), ErrorList)
241 241
         for form in formset.forms:
242  
-            self.assertTrue(isinstance(form.errors, ErrorDict))
243  
-            self.assertTrue(isinstance(form.non_field_errors(), ErrorList))
  242
+            self.assertIsInstance(form.errors, ErrorDict)
  243
+            self.assertIsInstance(form.non_field_errors(), ErrorList)
244 244
 
245 245
     def test_initial_data(self):
246 246
         User.objects.create(username="bibi", serial=1)
@@ -296,16 +296,16 @@ class FormfieldCallbackTests(TestCase):
296 296
     def test_inlineformset_factory_default(self):
297 297
         Formset = inlineformset_factory(User, UserSite, form=UserSiteForm, fields="__all__")
298 298
         form = Formset().forms[0]
299  
-        self.assertTrue(isinstance(form['id'].field.widget, CustomWidget))
300  
-        self.assertTrue(isinstance(form['data'].field.widget, CustomWidget))
  299
+        self.assertIsInstance(form['id'].field.widget, CustomWidget)
  300
+        self.assertIsInstance(form['data'].field.widget, CustomWidget)
301 301
         self.assertFalse(form.fields['id'].localize)
302 302
         self.assertTrue(form.fields['data'].localize)
303 303
 
304 304
     def test_modelformset_factory_default(self):
305 305
         Formset = modelformset_factory(UserSite, form=UserSiteForm)
306 306
         form = Formset().forms[0]
307  
-        self.assertTrue(isinstance(form['id'].field.widget, CustomWidget))
308  
-        self.assertTrue(isinstance(form['data'].field.widget, CustomWidget))
  307
+        self.assertIsInstance(form['id'].field.widget, CustomWidget)
  308
+        self.assertIsInstance(form['data'].field.widget, CustomWidget)
309 309
         self.assertFalse(form.fields['id'].localize)
310 310
         self.assertTrue(form.fields['data'].localize)
311 311
 
8  tests/unmanaged_models/tests.py
@@ -23,14 +23,14 @@ def test_simple(self):
23 23
 
24 24
         # ... and pull it out via the other set.
25 25
         a2 = A02.objects.all()[0]
26  
-        self.assertTrue(isinstance(a2, A02))
  26
+        self.assertIsInstance(a2, A02)
27 27
         self.assertEqual(a2.f_a, "foo")
28 28
 
29 29
         b2 = B02.objects.all()[0]
30  
-        self.assertTrue(isinstance(b2, B02))
  30
+        self.assertIsInstance(b2, B02)
31 31
         self.assertEqual(b2.f_a, "fred")
32 32
 
33  
-        self.assertTrue(isinstance(b2.fk_a, A02))
  33
+        self.assertIsInstance(b2.fk_a, A02)
34 34
         self.assertEqual(b2.fk_a.f_a, "foo")
35 35
 
36 36
         self.assertEqual(list(C02.objects.filter(f_a=None)), [])
@@ -38,7 +38,7 @@ def test_simple(self):
38 38
         resp = list(C02.objects.filter(mm_a=a.id))
39 39
         self.assertEqual(len(resp), 1)
40 40
 
41  
-        self.assertTrue(isinstance(resp[0], C02))
  41
+        self.assertIsInstance(resp[0], C02)
42 42
         self.assertEqual(resp[0].f_a, 'barney')
43 43
 
44 44
 
6  tests/urlpatterns_reverse/tests.py
@@ -246,7 +246,7 @@ def test_404_tried_urls_have_names(self):
246 246
             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'])))
247 247
             for tried, expected in zip(e.args[0]['tried'], url_types_names):
248 248
                 for t, e in zip(tried, expected):
249  
-                    self.assertTrue(isinstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type']))
  249
+                    self.assertIsInstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type'])
250 250
                     if 'name' in e:
251 251
                         if not e['name']:
252 252
                             self.assertTrue(t.name is None, 'Expected no URL name but found %s.' % t.name)
@@ -278,11 +278,11 @@ def get_absolute_url(self):
278 278
                 return "/hi-there/"
279 279
 
280 280
         res = redirect(FakeObj())
281  
-        self.assertTrue(isinstance(res, HttpResponseRedirect))
  281
+        self.assertIsInstance(res, HttpResponseRedirect)
282 282
         self.assertEqual(res.url, '/hi-there/')
283 283
 
284 284
         res = redirect(FakeObj(), permanent=True)
285  
-        self.assertTrue(isinstance(res, HttpResponsePermanentRedirect))
  285
+        self.assertIsInstance(res, HttpResponsePermanentRedirect)
286 286
         self.assertEqual(res.url, '/hi-there/')
287 287
 
288 288
     def test_redirect_to_view_name(self):
2  tests/utils_tests/test_baseconv.py
@@ -39,4 +39,4 @@ def test_base7(self):
39 39
 
40 40
     def test_exception(self):
41 41
         self.assertRaises(ValueError, BaseConverter, 'abc', sign='a')
42  
-        self.assertTrue(isinstance(BaseConverter('abc', sign='d'), BaseConverter))
  42
+        self.assertIsInstance(BaseConverter('abc', sign='d'), BaseConverter)
2  tests/utils_tests/test_simplelazyobject.py
@@ -68,7 +68,7 @@ def test_repr(self):
68 68
 
69 69
         # Second, for an evaluated SimpleLazyObject
70 70
         name = x.name  # evaluate
71  
-        self.assertTrue(isinstance(x._wrapped, _ComplexObject))
  71
+        self.assertIsInstance(x._wrapped, _ComplexObject)
72 72
         # __repr__ contains __repr__ of wrapped object
73 73
         self.assertEqual("<SimpleLazyObject: %r>" % x._wrapped, repr(x))
74 74
 
2  tests/view_tests/tests/test_static.py
@@ -60,7 +60,7 @@ def test_not_modified_since(self):
60 60
             # This is 24h before max Unix time. Remember to fix Django and
61 61
             # update this test well before 2038 :)
62 62
             )
63  
-        self.assertTrue(isinstance(response, HttpResponseNotModified))
  63
+        self.assertIsInstance(response, HttpResponseNotModified)
64 64
 
65 65
     def test_invalid_if_modified_since(self):
66 66
         """Handle bogus If-Modified-Since values gracefully

0 notes on commit b632baa

Please sign in to comment.
Something went wrong with that request. Please try again.