diff --git a/docs/intro/tutorial05.txt b/docs/intro/tutorial05.txt index bfb43358e65..f88f6686bda 100644 --- a/docs/intro/tutorial05.txt +++ b/docs/intro/tutorial05.txt @@ -180,7 +180,7 @@ Put the following in the ``tests.py`` file in the ``polls`` application: """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) - self.assertEqual(future_question.was_published_recently(), False) + self.assertIs(future_question.was_published_recently(), False) What we have done here is created a :class:`django.test.TestCase` subclass with a method that creates a ``Question`` instance with a ``pub_date`` in the @@ -203,8 +203,8 @@ and you'll see something like:: ---------------------------------------------------------------------- Traceback (most recent call last): File "/path/to/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_question - self.assertEqual(future_question.was_published_recently(), False) - AssertionError: True != False + self.assertIs(future_question.was_published_recently(), False) + AssertionError: True is not False ---------------------------------------------------------------------- Ran 1 test in 0.001s @@ -285,7 +285,7 @@ more comprehensively: """ time = timezone.now() - datetime.timedelta(days=30) old_question = Question(pub_date=time) - self.assertEqual(old_question.was_published_recently(), False) + self.assertIs(old_question.was_published_recently(), False) def test_was_published_recently_with_recent_question(self): """ @@ -294,7 +294,7 @@ more comprehensively: """ time = timezone.now() - datetime.timedelta(hours=1) recent_question = Question(pub_date=time) - self.assertEqual(recent_question.was_published_recently(), True) + self.assertIs(recent_question.was_published_recently(), True) And now we have three tests that confirm that ``Question.was_published_recently()`` returns sensible values for past, recent, and future questions. diff --git a/docs/topics/testing/overview.txt b/docs/topics/testing/overview.txt index eca477bdd91..aa6a7af191d 100644 --- a/docs/topics/testing/overview.txt +++ b/docs/topics/testing/overview.txt @@ -304,8 +304,8 @@ failed:: ---------------------------------------------------------------------- Traceback (most recent call last): File "/dev/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_poll - self.assertEqual(future_poll.was_published_recently(), False) - AssertionError: True != False + self.assertIs(future_poll.was_published_recently(), False) + AssertionError: True is not False ---------------------------------------------------------------------- Ran 1 test in 0.003s diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 9756c0ea53f..7d477a16d2a 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -95,7 +95,7 @@ class ChangeListTests(TestCase): request, Child, *get_changelist_args(ia, list_select_related=ia.get_list_select_related(request)) ) - self.assertEqual(cl.queryset.query.select_related, False) + self.assertIs(cl.queryset.query.select_related, False) def test_get_select_related_custom_method(self): class GetListSelectRelatedAdmin(admin.ModelAdmin): diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py index ba6934f4ed7..940bb3ce8c1 100644 --- a/tests/admin_filters/tests.py +++ b/tests/admin_filters/tests.py @@ -336,7 +336,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][4] self.assertEqual(force_text(filterspec.title), 'date registered') choice = select_by(filterspec.choices(changelist), "display", "Today") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual( choice['query_string'], '?date_registered__gte=%s&date_registered__lt=%s' % ( @@ -361,7 +361,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][4] self.assertEqual(force_text(filterspec.title), 'date registered') choice = select_by(filterspec.choices(changelist), "display", "This month") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual( choice['query_string'], '?date_registered__gte=%s&date_registered__lt=%s' % ( @@ -386,7 +386,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][4] self.assertEqual(force_text(filterspec.title), 'date registered') choice = select_by(filterspec.choices(changelist), "display", "This year") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual( choice['query_string'], '?date_registered__gte=%s&date_registered__lt=%s' % ( @@ -409,7 +409,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][4] self.assertEqual(force_text(filterspec.title), 'date registered') choice = select_by(filterspec.choices(changelist), "display", "Past 7 days") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual( choice['query_string'], '?date_registered__gte=%s&date_registered__lt=%s' % ( @@ -431,7 +431,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][4] self.assertEqual(force_text(filterspec.title), 'date registered') choice = select_by(filterspec.choices(changelist), 'display', 'No date') - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?date_registered__isnull=True') request = self.request_factory.get('/', {'date_registered__isnull': 'False'}) @@ -446,7 +446,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][4] self.assertEqual(force_text(filterspec.title), 'date registered') choice = select_by(filterspec.choices(changelist), 'display', 'Has date') - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?date_registered__isnull=False') @unittest.skipIf( @@ -473,7 +473,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][0] self.assertEqual(force_text(filterspec.title), 'year') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[-1]['selected'], True) + self.assertIs(choices[-1]['selected'], True) self.assertEqual(choices[-1]['query_string'], '?year__isnull=True') request = self.request_factory.get('/', {'year': '2002'}) @@ -483,7 +483,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][0] self.assertEqual(force_text(filterspec.title), 'year') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[2]['selected'], True) + self.assertIs(choices[2]['selected'], True) self.assertEqual(choices[2]['query_string'], '?year=2002') def test_allvaluesfieldlistfilter_custom_qs(self): @@ -524,7 +524,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][1] self.assertEqual(force_text(filterspec.title), 'Verbose Author') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[-1]['selected'], True) + self.assertIs(choices[-1]['selected'], True) self.assertEqual(choices[-1]['query_string'], '?author__isnull=True') request = self.request_factory.get('/', {'author__id__exact': self.alfred.pk}) @@ -535,7 +535,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'Verbose Author') # order of choices depends on User model, which has no order choice = select_by(filterspec.choices(changelist), "display", "alfred") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?author__id__exact=%d' % self.alfred.pk) def test_relatedfieldlistfilter_manytomany(self): @@ -560,7 +560,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][2] self.assertEqual(force_text(filterspec.title), 'Verbose Contributors') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[-1]['selected'], True) + self.assertIs(choices[-1]['selected'], True) self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True') request = self.request_factory.get('/', {'contributors__id__exact': self.bob.pk}) @@ -570,7 +570,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][2] self.assertEqual(force_text(filterspec.title), 'Verbose Contributors') choice = select_by(filterspec.choices(changelist), "display", "bob") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?contributors__id__exact=%d' % self.bob.pk) def test_relatedfieldlistfilter_reverse_relationships(self): @@ -588,7 +588,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][0] self.assertEqual(force_text(filterspec.title), 'book') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[-1]['selected'], True) + self.assertIs(choices[-1]['selected'], True) self.assertEqual(choices[-1]['query_string'], '?books_authored__isnull=True') request = self.request_factory.get('/', {'books_authored__id__exact': self.bio_book.pk}) @@ -598,7 +598,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][0] self.assertEqual(force_text(filterspec.title), 'book') choice = select_by(filterspec.choices(changelist), "display", self.bio_book.title) - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?books_authored__id__exact=%d' % self.bio_book.pk) # M2M relationship ----- @@ -613,7 +613,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][1] self.assertEqual(force_text(filterspec.title), 'book') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[-1]['selected'], True) + self.assertIs(choices[-1]['selected'], True) self.assertEqual(choices[-1]['query_string'], '?books_contributed__isnull=True') request = self.request_factory.get('/', {'books_contributed__id__exact': self.django_book.pk}) @@ -623,7 +623,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][1] self.assertEqual(force_text(filterspec.title), 'book') choice = select_by(filterspec.choices(changelist), "display", self.django_book.title) - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?books_contributed__id__exact=%d' % self.django_book.pk) # With one book, the list filter should appear because there is also a @@ -719,7 +719,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][3] self.assertEqual(force_text(filterspec.title), 'is best seller') choice = select_by(filterspec.choices(changelist), "display", "No") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?is_best_seller__exact=0') request = self.request_factory.get('/', {'is_best_seller__exact': 1}) @@ -733,7 +733,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][3] self.assertEqual(force_text(filterspec.title), 'is best seller') choice = select_by(filterspec.choices(changelist), "display", "Yes") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?is_best_seller__exact=1') request = self.request_factory.get('/', {'is_best_seller__isnull': 'True'}) @@ -747,7 +747,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][3] self.assertEqual(force_text(filterspec.title), 'is best seller') choice = select_by(filterspec.choices(changelist), "display", "Unknown") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?is_best_seller__isnull=True') def test_fieldlistfilter_underscorelookup_tuple(self): @@ -782,7 +782,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[0]['display'], 'All') - self.assertEqual(choices[0]['selected'], True) + self.assertIs(choices[0]['selected'], True) self.assertEqual(choices[0]['query_string'], '?') # Look for books in the 1980s ---------------------------------------- @@ -798,7 +798,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[1]['display'], 'the 1980\'s') - self.assertEqual(choices[1]['selected'], True) + self.assertIs(choices[1]['selected'], True) self.assertEqual(choices[1]['query_string'], '?publication-decade=the+80s') # Look for books in the 1990s ---------------------------------------- @@ -814,7 +814,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[2]['display'], 'the 1990\'s') - self.assertEqual(choices[2]['selected'], True) + self.assertIs(choices[2]['selected'], True) self.assertEqual(choices[2]['query_string'], '?publication-decade=the+90s') # Look for books in the 2000s ---------------------------------------- @@ -830,7 +830,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[3]['display'], 'the 2000\'s') - self.assertEqual(choices[3]['selected'], True) + self.assertIs(choices[3]['selected'], True) self.assertEqual(choices[3]['query_string'], '?publication-decade=the+00s') # Combine multiple filters ------------------------------------------- @@ -846,7 +846,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[3]['display'], 'the 2000\'s') - self.assertEqual(choices[3]['selected'], True) + self.assertIs(choices[3]['selected'], True) self.assertEqual( choices[3]['query_string'], '?author__id__exact=%s&publication-decade=the+00s' % self.alfred.pk @@ -855,7 +855,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][0] self.assertEqual(force_text(filterspec.title), 'Verbose Author') choice = select_by(filterspec.choices(changelist), "display", "alfred") - self.assertEqual(choice['selected'], True) + self.assertIs(choice['selected'], True) self.assertEqual(choice['query_string'], '?author__id__exact=%s&publication-decade=the+00s' % self.alfred.pk) def test_listfilter_without_title(self): @@ -910,15 +910,15 @@ class ListFiltersTests(TestCase): self.assertEqual(len(choices), 3) self.assertEqual(choices[0]['display'], 'All') - self.assertEqual(choices[0]['selected'], True) + self.assertIs(choices[0]['selected'], True) self.assertEqual(choices[0]['query_string'], '?') self.assertEqual(choices[1]['display'], 'the 1990\'s') - self.assertEqual(choices[1]['selected'], False) + self.assertIs(choices[1]['selected'], False) self.assertEqual(choices[1]['query_string'], '?publication-decade=the+90s') self.assertEqual(choices[2]['display'], 'the 2000\'s') - self.assertEqual(choices[2]['selected'], False) + self.assertIs(choices[2]['selected'], False) self.assertEqual(choices[2]['query_string'], '?publication-decade=the+00s') def test_two_characters_long_field(self): @@ -936,7 +936,7 @@ class ListFiltersTests(TestCase): filterspec = changelist.get_filters(request)[0][-1] self.assertEqual(force_text(filterspec.title), 'number') choices = list(filterspec.choices(changelist)) - self.assertEqual(choices[2]['selected'], True) + self.assertIs(choices[2]['selected'], True) self.assertEqual(choices[2]['query_string'], '?no=207') def test_parameter_ends_with__in__or__isnull(self): @@ -958,7 +958,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[2]['display'], 'the 1990\'s') - self.assertEqual(choices[2]['selected'], True) + self.assertIs(choices[2]['selected'], True) self.assertEqual(choices[2]['query_string'], '?decade__in=the+90s') # When it ends with '__isnull' --------------------------------------- @@ -975,7 +975,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'publication decade') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[2]['display'], 'the 1990\'s') - self.assertEqual(choices[2]['selected'], True) + self.assertIs(choices[2]['selected'], True) self.assertEqual(choices[2]['query_string'], '?decade__isnull=the+90s') def test_lookup_with_non_string_value(self): @@ -995,7 +995,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'department') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[1]['display'], 'DEV') - self.assertEqual(choices[1]['selected'], True) + self.assertIs(choices[1]['selected'], True) self.assertEqual(choices[1]['query_string'], '?department=%s' % self.john.department.pk) def test_lookup_with_non_string_value_underscored(self): @@ -1015,7 +1015,7 @@ class ListFiltersTests(TestCase): self.assertEqual(force_text(filterspec.title), 'department') choices = list(filterspec.choices(changelist)) self.assertEqual(choices[1]['display'], 'DEV') - self.assertEqual(choices[1]['selected'], True) + self.assertIs(choices[1]['selected'], True) self.assertEqual(choices[1]['query_string'], '?department__whatever=%s' % self.john.department.pk) def test_fk_with_to_field(self): @@ -1036,15 +1036,15 @@ class ListFiltersTests(TestCase): choices = list(filterspec.choices(changelist)) self.assertEqual(choices[0]['display'], 'All') - self.assertEqual(choices[0]['selected'], True) + self.assertIs(choices[0]['selected'], True) self.assertEqual(choices[0]['query_string'], '?') self.assertEqual(choices[1]['display'], 'Development') - self.assertEqual(choices[1]['selected'], False) + self.assertIs(choices[1]['selected'], False) self.assertEqual(choices[1]['query_string'], '?department__code__exact=DEV') self.assertEqual(choices[2]['display'], 'Design') - self.assertEqual(choices[2]['selected'], False) + self.assertIs(choices[2]['selected'], False) self.assertEqual(choices[2]['query_string'], '?department__code__exact=DSN') # Filter by Department=='Development' -------------------------------- @@ -1061,15 +1061,15 @@ class ListFiltersTests(TestCase): choices = list(filterspec.choices(changelist)) self.assertEqual(choices[0]['display'], 'All') - self.assertEqual(choices[0]['selected'], False) + self.assertIs(choices[0]['selected'], False) self.assertEqual(choices[0]['query_string'], '?') self.assertEqual(choices[1]['display'], 'Development') - self.assertEqual(choices[1]['selected'], True) + self.assertIs(choices[1]['selected'], True) self.assertEqual(choices[1]['query_string'], '?department__code__exact=DEV') self.assertEqual(choices[2]['display'], 'Design') - self.assertEqual(choices[2]['selected'], False) + self.assertIs(choices[2]['selected'], False) self.assertEqual(choices[2]['query_string'], '?department__code__exact=DSN') def test_lookup_with_dynamic_value(self): diff --git a/tests/admin_views/test_adminsite.py b/tests/admin_views/test_adminsite.py index 6fb76ac5fcf..7077d4be58f 100644 --- a/tests/admin_views/test_adminsite.py +++ b/tests/admin_views/test_adminsite.py @@ -39,7 +39,7 @@ class SiteEachContextTest(TestCase): self.assertEqual(ctx['site_header'], 'Django administration') self.assertEqual(ctx['site_title'], 'Django site admin') self.assertEqual(ctx['site_url'], '/') - self.assertEqual(ctx['has_permission'], True) + self.assertIs(ctx['has_permission'], True) def test_each_context_site_url_with_script_name(self): request = RequestFactory().get(reverse('test_adminsite:index'), SCRIPT_NAME='/my-script-name/') @@ -66,12 +66,12 @@ class SiteEachContextTest(TestCase): self.assertEqual(user['object_name'], 'User') self.assertEqual(auth['app_url'], '/test_admin/admin/auth/') - self.assertEqual(auth['has_module_perms'], True) + self.assertIs(auth['has_module_perms'], True) self.assertIn('perms', user) - self.assertEqual(user['perms']['add'], True) - self.assertEqual(user['perms']['change'], True) - self.assertEqual(user['perms']['delete'], True) + self.assertIs(user['perms']['add'], True) + self.assertIs(user['perms']['change'], True) + self.assertIs(user['perms']['delete'], True) self.assertEqual(user['admin_url'], '/test_admin/admin/auth/user/') self.assertEqual(user['add_url'], '/test_admin/admin/auth/user/add/') self.assertEqual(user['name'], 'Users') diff --git a/tests/admin_views/test_templatetags.py b/tests/admin_views/test_templatetags.py index ff40a45116b..a62c1caf893 100644 --- a/tests/admin_views/test_templatetags.py +++ b/tests/admin_views/test_templatetags.py @@ -22,5 +22,5 @@ class AdminTemplateTagsTest(AdminViewBasicTestCase): extra_context = {'extra': True} response = admin.change_view(request, str(self.superuser.pk), extra_context=extra_context) template_context = submit_row(response.context_data) - self.assertEqual(template_context['extra'], True) - self.assertEqual(template_context['show_save'], True) + self.assertIs(template_context['extra'], True) + self.assertIs(template_context['show_save'], True) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 281084a8a19..589d7d9298c 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1554,7 +1554,7 @@ class AdminViewPermissionsTest(TestCase): # Change User should not have access to add articles self.client.force_login(self.changeuser) # make sure the view removes test cookie - self.assertEqual(self.client.session.test_cookie_worked(), False) + self.assertIs(self.client.session.test_cookie_worked(), False) response = self.client.get(reverse('admin:admin_views_article_add')) self.assertEqual(response.status_code, 403) # Try POST just to make sure @@ -1607,7 +1607,7 @@ class AdminViewPermissionsTest(TestCase): # Check and make sure that if user expires, data still persists self.client.force_login(self.superuser) # make sure the view removes test cookie - self.assertEqual(self.client.session.test_cookie_worked(), False) + self.assertIs(self.client.session.test_cookie_worked(), False) def test_change_view(self): """Change view should restrict access and allow users to edit items.""" @@ -2587,7 +2587,7 @@ class AdminViewListEditable(TestCase): } self.client.post(reverse('admin:admin_views_person_changelist'), data) - self.assertEqual(Person.objects.get(name="John Mauchly").alive, False) + self.assertIs(Person.objects.get(name="John Mauchly").alive, False) self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2) # test a filtered page @@ -2608,7 +2608,7 @@ class AdminViewListEditable(TestCase): } self.client.post(reverse('admin:admin_views_person_changelist') + '?gender__exact=1', data) - self.assertEqual(Person.objects.get(name="John Mauchly").alive, True) + self.assertIs(Person.objects.get(name="John Mauchly").alive, True) # test a searched page data = { @@ -2623,7 +2623,7 @@ class AdminViewListEditable(TestCase): } self.client.post(reverse('admin:admin_views_person_changelist') + '?q=john', data) - self.assertEqual(Person.objects.get(name="John Mauchly").alive, False) + self.assertIs(Person.objects.get(name="John Mauchly").alive, False) def test_non_field_errors(self): ''' Ensure that non field errors are displayed for each of the @@ -2819,7 +2819,7 @@ class AdminViewListEditable(TestCase): } self.client.post(reverse('admin:admin_views_person_changelist'), data) - self.assertEqual(Person.objects.get(name="John Mauchly").alive, True) + self.assertIs(Person.objects.get(name="John Mauchly").alive, True) self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 1) def test_list_editable_action_choices(self): @@ -2846,7 +2846,7 @@ class AdminViewListEditable(TestCase): } self.client.post(reverse('admin:admin_views_person_changelist'), data) - self.assertEqual(Person.objects.get(name="John Mauchly").alive, False) + self.assertIs(Person.objects.get(name="John Mauchly").alive, False) self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2) def test_list_editable_popup(self): @@ -3318,7 +3318,7 @@ action) def test_model_without_action(self): "Tests a ModelAdmin without any action" response = self.client.get(reverse('admin:admin_views_oldsubscriber_changelist')) - self.assertEqual(response.context["action_form"], None) + self.assertIsNone(response.context["action_form"]) self.assertNotContains( response, ' def test_model_without_action_still_has_jquery(self): "Tests that a ModelAdmin without any actions still gets jQuery included in page" response = self.client.get(reverse('admin:admin_views_oldsubscriber_changelist')) - self.assertEqual(response.context["action_form"], None) + self.assertIsNone(response.context["action_form"]) self.assertContains( response, 'jquery.min.js', msg_prefix="jQuery missing from admin pages for model with no admin actions" @@ -3337,7 +3337,7 @@ action) def test_action_column_class(self): "Tests that the checkbox column class is present in the response" response = self.client.get(reverse('admin:admin_views_subscriber_changelist')) - self.assertNotEqual(response.context["action_form"], None) + self.assertIsNotNone(response.context["action_form"]) self.assertContains(response, 'action-checkbox-column') def test_multiple_actions_form(self): @@ -3395,10 +3395,10 @@ action) def test_popup_actions(self): """ Actions should not be shown in popups. """ response = self.client.get(reverse('admin:admin_views_subscriber_changelist')) - self.assertNotEqual(response.context["action_form"], None) + self.assertIsNotNone(response.context["action_form"]) response = self.client.get( reverse('admin:admin_views_subscriber_changelist') + '?%s' % IS_POPUP_VAR) - self.assertEqual(response.context["action_form"], None) + self.assertIsNone(response.context["action_form"]) def test_popup_template_response(self): """ @@ -4159,17 +4159,17 @@ class NeverCacheTests(TestCase): "Check the never-cache status of the password change view" self.client.logout() response = self.client.get(reverse('admin:password_change')) - self.assertEqual(get_max_age(response), None) + self.assertIsNone(get_max_age(response)) def test_password_change_done(self): "Check the never-cache status of the password change done view" response = self.client.get(reverse('admin:password_change_done')) - self.assertEqual(get_max_age(response), None) + self.assertIsNone(get_max_age(response)) def test_JS_i18n(self): "Check the never-cache status of the JavaScript i18n view" response = self.client.get(reverse('admin:jsi18n')) - self.assertEqual(get_max_age(response), None) + self.assertIsNone(get_max_age(response)) @override_settings(ROOT_URLCONF='admin_views.urls') diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index a1006af7c74..378a9290b79 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -116,7 +116,7 @@ class AdminFormfieldForDBFieldTests(SimpleTestCase): def test_radio_fields_ForeignKey(self): ff = self.assertFormfield(models.Event, 'main_band', widgets.AdminRadioSelect, radio_fields={'main_band': admin.VERTICAL}) - self.assertEqual(ff.empty_label, None) + self.assertIsNone(ff.empty_label) def test_many_to_many(self): self.assertFormfield(models.Band, 'members', forms.SelectMultiple) diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py index 91f92397a25..e850772f35b 100644 --- a/tests/auth_tests/test_auth_backends.py +++ b/tests/auth_tests/test_auth_backends.py @@ -56,21 +56,21 @@ class BaseModelBackendTest(object): def test_has_perm(self): user = self.UserModel._default_manager.get(pk=self.user.pk) - self.assertEqual(user.has_perm('auth.test'), False) + self.assertIs(user.has_perm('auth.test'), False) user.is_staff = True user.save() - self.assertEqual(user.has_perm('auth.test'), False) + self.assertIs(user.has_perm('auth.test'), False) user.is_superuser = True user.save() - self.assertEqual(user.has_perm('auth.test'), True) + self.assertIs(user.has_perm('auth.test'), True) user.is_staff = True user.is_superuser = True user.is_active = False user.save() - self.assertEqual(user.has_perm('auth.test'), False) + self.assertIs(user.has_perm('auth.test'), False) def test_custom_perms(self): user = self.UserModel._default_manager.get(pk=self.user.pk) @@ -80,10 +80,10 @@ class BaseModelBackendTest(object): # reloading user to purge the _perm_cache user = self.UserModel._default_manager.get(pk=self.user.pk) - self.assertEqual(user.get_all_permissions() == {'auth.test'}, True) + self.assertEqual(user.get_all_permissions(), {'auth.test'}) self.assertEqual(user.get_group_permissions(), set()) - self.assertEqual(user.has_module_perms('Group'), False) - self.assertEqual(user.has_module_perms('auth'), True) + self.assertIs(user.has_module_perms('Group'), False) + self.assertIs(user.has_module_perms('auth'), True) perm = Permission.objects.create(name='test2', content_type=content_type, codename='test2') user.user_permissions.add(perm) @@ -91,9 +91,9 @@ class BaseModelBackendTest(object): user.user_permissions.add(perm) user = self.UserModel._default_manager.get(pk=self.user.pk) self.assertEqual(user.get_all_permissions(), {'auth.test2', 'auth.test', 'auth.test3'}) - self.assertEqual(user.has_perm('test'), False) - self.assertEqual(user.has_perm('auth.test'), True) - self.assertEqual(user.has_perms(['auth.test2', 'auth.test3']), True) + self.assertIs(user.has_perm('test'), False) + self.assertIs(user.has_perm('auth.test'), True) + self.assertIs(user.has_perms(['auth.test2', 'auth.test3']), True) perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group') group = Group.objects.create(name='test_group') @@ -103,11 +103,11 @@ class BaseModelBackendTest(object): exp = {'auth.test2', 'auth.test', 'auth.test3', 'auth.test_group'} self.assertEqual(user.get_all_permissions(), exp) self.assertEqual(user.get_group_permissions(), {'auth.test_group'}) - self.assertEqual(user.has_perms(['auth.test3', 'auth.test_group']), True) + self.assertIs(user.has_perms(['auth.test3', 'auth.test_group']), True) user = AnonymousUser() - self.assertEqual(user.has_perm('test'), False) - self.assertEqual(user.has_perms(['auth.test2', 'auth.test3']), False) + self.assertIs(user.has_perm('test'), False) + self.assertIs(user.has_perms(['auth.test2', 'auth.test3']), False) def test_has_no_object_perm(self): """Regressiontest for #12462""" @@ -116,9 +116,9 @@ class BaseModelBackendTest(object): perm = Permission.objects.create(name='test', content_type=content_type, codename='test') user.user_permissions.add(perm) - self.assertEqual(user.has_perm('auth.test', 'object'), False) + self.assertIs(user.has_perm('auth.test', 'object'), False) self.assertEqual(user.get_all_permissions('object'), set()) - self.assertEqual(user.has_perm('auth.test'), True) + self.assertIs(user.has_perm('auth.test'), True) self.assertEqual(user.get_all_permissions(), {'auth.test'}) def test_anonymous_has_no_permissions(self): @@ -391,13 +391,13 @@ class RowlevelBackendTest(TestCase): ContentType.objects.clear_cache() def test_has_perm(self): - self.assertEqual(self.user1.has_perm('perm', TestObj()), False) - self.assertEqual(self.user2.has_perm('perm', TestObj()), True) - self.assertEqual(self.user2.has_perm('perm'), False) - self.assertEqual(self.user2.has_perms(['simple', 'advanced'], TestObj()), True) - self.assertEqual(self.user3.has_perm('perm', TestObj()), False) - self.assertEqual(self.user3.has_perm('anon', TestObj()), False) - self.assertEqual(self.user3.has_perms(['simple', 'advanced'], TestObj()), False) + self.assertIs(self.user1.has_perm('perm', TestObj()), False) + self.assertIs(self.user2.has_perm('perm', TestObj()), True) + self.assertIs(self.user2.has_perm('perm'), False) + self.assertIs(self.user2.has_perms(['simple', 'advanced'], TestObj()), True) + self.assertIs(self.user3.has_perm('perm', TestObj()), False) + self.assertIs(self.user3.has_perm('anon', TestObj()), False) + self.assertIs(self.user3.has_perms(['simple', 'advanced'], TestObj()), False) def test_get_all_permissions(self): self.assertEqual(self.user1.get_all_permissions(TestObj()), {'simple'}) @@ -422,16 +422,16 @@ class AnonymousUserBackendTest(SimpleTestCase): self.user1 = AnonymousUser() def test_has_perm(self): - self.assertEqual(self.user1.has_perm('perm', TestObj()), False) - self.assertEqual(self.user1.has_perm('anon', TestObj()), True) + self.assertIs(self.user1.has_perm('perm', TestObj()), False) + self.assertIs(self.user1.has_perm('anon', TestObj()), True) def test_has_perms(self): - self.assertEqual(self.user1.has_perms(['anon'], TestObj()), True) - self.assertEqual(self.user1.has_perms(['anon', 'perm'], TestObj()), False) + self.assertIs(self.user1.has_perms(['anon'], TestObj()), True) + self.assertIs(self.user1.has_perms(['anon', 'perm'], TestObj()), False) def test_has_module_perms(self): - self.assertEqual(self.user1.has_module_perms("app1"), True) - self.assertEqual(self.user1.has_module_perms("app2"), False) + self.assertIs(self.user1.has_module_perms("app1"), True) + self.assertIs(self.user1.has_module_perms("app2"), False) def test_get_all_permissions(self): self.assertEqual(self.user1.get_all_permissions(TestObj()), {'anon'}) @@ -462,12 +462,12 @@ class InActiveUserBackendTest(TestCase): self.user1.save() def test_has_perm(self): - self.assertEqual(self.user1.has_perm('perm', TestObj()), False) - self.assertEqual(self.user1.has_perm('inactive', TestObj()), True) + self.assertIs(self.user1.has_perm('perm', TestObj()), False) + self.assertIs(self.user1.has_perm('inactive', TestObj()), True) def test_has_module_perms(self): - self.assertEqual(self.user1.has_module_perms("app1"), False) - self.assertEqual(self.user1.has_module_perms("app2"), False) + self.assertIs(self.user1.has_module_perms("app1"), False) + self.assertIs(self.user1.has_module_perms("app2"), False) class PermissionDeniedBackend(object): @@ -505,7 +505,7 @@ class PermissionDeniedBackendTest(TestCase): @modify_settings(AUTHENTICATION_BACKENDS={'prepend': backend}) def test_permission_denied(self): "user is not authenticated after a backend raises permission denied #2550" - self.assertEqual(authenticate(username='test', password='test'), None) + self.assertIsNone(authenticate(username='test', password='test')) # user_login_failed signal is sent. self.assertEqual(self.user_login_failed, [{'password': '********************', 'username': 'test'}]) diff --git a/tests/auth_tests/test_basic.py b/tests/auth_tests/test_basic.py index caefa9c7a06..e6b4cab87fa 100644 --- a/tests/auth_tests/test_basic.py +++ b/tests/auth_tests/test_basic.py @@ -89,7 +89,7 @@ class BasicTestCase(TestCase): def test_anonymous_user(self): "Check the properties of the anonymous user" a = AnonymousUser() - self.assertEqual(a.pk, None) + self.assertIsNone(a.pk) self.assertEqual(a.username, '') self.assertEqual(a.get_username(), '') self.assertTrue(a.is_anonymous) diff --git a/tests/auth_tests/test_models.py b/tests/auth_tests/test_models.py index 975cf230af9..1f9edbc77c0 100644 --- a/tests/auth_tests/test_models.py +++ b/tests/auth_tests/test_models.py @@ -220,7 +220,7 @@ class IsActiveTestCase(TestCase): def test_builtin_user_isactive(self): user = User.objects.create(username='foo', email='foo@bar.com') # is_active is true by default - self.assertEqual(user.is_active, True) + self.assertIs(user.is_active, True) user.is_active = False user.save() user_fetched = User.objects.get(pk=user.pk) @@ -234,14 +234,14 @@ class IsActiveTestCase(TestCase): """ UserModel = get_user_model() user = UserModel(username='foo') - self.assertEqual(user.is_active, True) + self.assertIs(user.is_active, True) # you can set the attribute - but it will not save user.is_active = False # there should be no problem saving - but the attribute is not saved user.save() user_fetched = UserModel._default_manager.get(pk=user.pk) # the attribute is always true for newly retrieved instance - self.assertEqual(user_fetched.is_active, True) + self.assertIs(user_fetched.is_active, True) class TestCreateSuperUserSignals(TestCase): diff --git a/tests/auth_tests/test_signals.py b/tests/auth_tests/test_signals.py index b559fb53cea..6f1ad0a7b56 100644 --- a/tests/auth_tests/test_signals.py +++ b/tests/auth_tests/test_signals.py @@ -58,7 +58,7 @@ class SignalTestCase(TestCase): # users. self.client.get('/logout/next_page/') self.assertEqual(len(self.logged_out), 1) - self.assertEqual(self.logged_out[0], None) + self.assertIsNone(self.logged_out[0]) def test_logout(self): self.client.login(username='testclient', password='password') diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 6aacc64e67d..56b778c4192 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -85,7 +85,7 @@ class ModelInstanceCreationTests(TestCase): a = Article(headline='Article 5', pub_date=datetime(2005, 7, 31)) a.save() self.assertEqual(a.headline, 'Article 5') - self.assertNotEqual(a.id, None) + self.assertIsNotNone(a.id) def test_leaving_off_a_field_with_default_set_the_default_will_be_saved(self): a = Article(pub_date=datetime(2005, 7, 31)) @@ -358,7 +358,7 @@ class ModelTest(TestCase): with self.assertRaises(TypeError): EmptyQuerySet() self.assertIsInstance(Article.objects.none(), EmptyQuerySet) - self.assertFalse(isinstance('', EmptyQuerySet)) + self.assertNotIsInstance('', EmptyQuerySet) def test_emptyqs_values(self): # test for #15959 diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 1e74df1e568..e25dace6a15 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -522,7 +522,7 @@ class BaseCacheTests(object): cache.add('key2', 'ham', None) self.assertEqual(cache.get('key2'), 'ham') added = cache.add('key1', 'new eggs', None) - self.assertEqual(added, False) + self.assertIs(added, False) self.assertEqual(cache.get('key1'), 'eggs') cache.set_many({'key3': 'sausage', 'key4': 'lobster bisque'}, None) diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py index ade2e17759c..6e4115140ac 100644 --- a/tests/check_framework/tests.py +++ b/tests/check_framework/tests.py @@ -156,7 +156,7 @@ class CheckCommandTests(SimpleTestCase): @override_system_checks([simple_system_check, tagged_system_check]) def test_given_tag(self): call_command('check', tags=['simpletag']) - self.assertEqual(simple_system_check.kwargs, None) + self.assertIsNone(simple_system_check.kwargs) self.assertEqual(tagged_system_check.kwargs, {'app_configs': None}) @override_system_checks([simple_system_check, tagged_system_check]) diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py index 5ed7c9dc3dd..59814a18c7c 100644 --- a/tests/csrf_tests/tests.py +++ b/tests/csrf_tests/tests.py @@ -170,10 +170,10 @@ class CsrfViewMiddlewareTest(SimpleTestCase): resp = token_view(req) resp2 = CsrfViewMiddleware().process_response(req, resp) csrf_cookie = resp2.cookies.get('myname', False) - self.assertNotEqual(csrf_cookie, False) + self.assertIsNot(csrf_cookie, False) self.assertEqual(csrf_cookie['domain'], '.example.com') - self.assertEqual(csrf_cookie['secure'], True) - self.assertEqual(csrf_cookie['httponly'], True) + self.assertIs(csrf_cookie['secure'], True) + self.assertIs(csrf_cookie['httponly'], True) self.assertEqual(csrf_cookie['path'], '/test/') self.assertIn('Cookie', resp2.get('Vary', '')) @@ -195,7 +195,7 @@ class CsrfViewMiddlewareTest(SimpleTestCase): resp2 = CsrfViewMiddleware().process_response(req, resp) csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, False) - self.assertEqual(csrf_cookie, False) + self.assertIs(csrf_cookie, False) # Check the request processing def test_process_request_no_csrf_cookie(self): diff --git a/tests/custom_managers/tests.py b/tests/custom_managers/tests.py index b7a433ef3b7..63729e43f22 100644 --- a/tests/custom_managers/tests.py +++ b/tests/custom_managers/tests.py @@ -70,12 +70,12 @@ class CustomManagerTests(TestCase): manager = getattr(Person, manager_name) queryset = manager.filter() self.assertQuerysetEqual(queryset, ["Bugs Bunny"], six.text_type) - self.assertEqual(queryset._filter_CustomQuerySet, True) + self.assertIs(queryset._filter_CustomQuerySet, True) # Test that specialized querysets inherit from our custom queryset. queryset = manager.values_list('first_name', flat=True).filter() self.assertEqual(list(queryset), [six.text_type("Bugs")]) - self.assertEqual(queryset._filter_CustomQuerySet, True) + self.assertIs(queryset._filter_CustomQuerySet, True) self.assertIsInstance(queryset.values(), CustomQuerySet) self.assertIsInstance(queryset.values().values(), CustomQuerySet) @@ -102,7 +102,7 @@ class CustomManagerTests(TestCase): """ queryset = Person.custom_queryset_custom_manager.filter() self.assertQuerysetEqual(queryset, ["Bugs Bunny"], six.text_type) - self.assertEqual(queryset._filter_CustomManager, True) + self.assertIs(queryset._filter_CustomManager, True) def test_related_manager(self): """ diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index 8fed78a67fe..39d27a136d6 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -223,8 +223,8 @@ class MethodDecoratorTests(SimpleTestCase): def func(): pass - self.assertEqual(getattr(func, 'myattr', False), True) - self.assertEqual(getattr(func, 'myattr2', False), True) + self.assertIs(getattr(func, 'myattr', False), True) + self.assertIs(getattr(func, 'myattr2', False), True) # Decorate using method_decorator() on the method. class TestPlain(object): @@ -254,11 +254,11 @@ class MethodDecoratorTests(SimpleTestCase): pass for Test in (TestPlain, TestMethodAndClass, TestIterable): - self.assertEqual(getattr(Test().method, 'myattr', False), True) - self.assertEqual(getattr(Test().method, 'myattr2', False), True) + self.assertIs(getattr(Test().method, 'myattr', False), True) + self.assertIs(getattr(Test().method, 'myattr2', False), True) - self.assertEqual(getattr(Test.method, 'myattr', False), True) - self.assertEqual(getattr(Test.method, 'myattr2', False), True) + self.assertIs(getattr(Test.method, 'myattr', False), True) + self.assertIs(getattr(Test.method, 'myattr2', False), True) self.assertEqual(Test.method.__doc__, 'A method') self.assertEqual(Test.method.__name__, 'method') @@ -280,7 +280,7 @@ class MethodDecoratorTests(SimpleTestCase): def method(self): return True - self.assertEqual(Test().method(), False) + self.assertIs(Test().method(), False) def test_descriptors(self): @@ -438,13 +438,13 @@ class XFrameOptionsDecoratorsTests(TestCase): return HttpResponse() req = HttpRequest() resp = a_view(req) - self.assertEqual(resp.get('X-Frame-Options', None), None) + self.assertIsNone(resp.get('X-Frame-Options', None)) self.assertTrue(resp.xframe_options_exempt) # Since the real purpose of the exempt decorator is to suppress # the middleware's functionality, let's make sure it actually works... r = XFrameOptionsMiddleware().process_response(req, resp) - self.assertEqual(r.get('X-Frame-Options', None), None) + self.assertIsNone(r.get('X-Frame-Options', None)) class NeverCacheDecoratorTest(TestCase): diff --git a/tests/files/tests.py b/tests/files/tests.py index 2e0230ff5e4..cd15a80f7ec 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -146,7 +146,7 @@ class NoNameFileTestCase(unittest.TestCase): urllib.urlopen() """ def test_noname_file_default_name(self): - self.assertEqual(File(BytesIO(b'A file with no name')).name, None) + self.assertIsNone(File(BytesIO(b'A file with no name')).name) def test_noname_file_get_size(self): self.assertEqual(File(BytesIO(b'A file with no name')).size, 19) @@ -154,7 +154,7 @@ class NoNameFileTestCase(unittest.TestCase): class ContentFileTestCase(unittest.TestCase): def test_content_file_default_name(self): - self.assertEqual(ContentFile(b"content").name, None) + self.assertIsNone(ContentFile(b"content").name) def test_content_file_custom_name(self): """ diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py index 150ea9577cd..51a3ef54c00 100644 --- a/tests/fixtures_regress/tests.py +++ b/tests/fixtures_regress/tests.py @@ -131,8 +131,8 @@ class TestFixtures(TestCase): 'pretty.xml', verbosity=0, ) - self.assertEqual(Stuff.objects.all()[0].name, None) - self.assertEqual(Stuff.objects.all()[0].owner, None) + self.assertIsNone(Stuff.objects.all()[0].name) + self.assertIsNone(Stuff.objects.all()[0].owner) @skipUnlessDBFeature('interprets_empty_strings_as_nulls') def test_pretty_print_xml_empty_strings(self): @@ -147,7 +147,7 @@ class TestFixtures(TestCase): verbosity=0, ) self.assertEqual(Stuff.objects.all()[0].name, '') - self.assertEqual(Stuff.objects.all()[0].owner, None) + self.assertIsNone(Stuff.objects.all()[0].owner) def test_absolute_path(self): """ diff --git a/tests/forms_tests/field_tests/test_booleanfield.py b/tests/forms_tests/field_tests/test_booleanfield.py index 0fa5357ae3f..e267777b943 100644 --- a/tests/forms_tests/field_tests/test_booleanfield.py +++ b/tests/forms_tests/field_tests/test_booleanfield.py @@ -27,18 +27,18 @@ class BooleanFieldTest(SimpleTestCase): def test_booleanfield_clean_2(self): f = BooleanField(required=False) - self.assertEqual(False, f.clean('')) - self.assertEqual(False, f.clean(None)) - self.assertEqual(True, f.clean(True)) - self.assertEqual(False, f.clean(False)) - self.assertEqual(True, f.clean(1)) - self.assertEqual(False, f.clean(0)) - self.assertEqual(True, f.clean('1')) - self.assertEqual(False, f.clean('0')) - self.assertEqual(True, f.clean('Django rocks')) - self.assertEqual(False, f.clean('False')) - self.assertEqual(False, f.clean('false')) - self.assertEqual(False, f.clean('FaLsE')) + self.assertIs(f.clean(''), False) + self.assertIs(f.clean(None), False) + self.assertIs(f.clean(True), True) + self.assertIs(f.clean(False), False) + self.assertIs(f.clean(1), True) + self.assertIs(f.clean(0), False) + self.assertIs(f.clean('1'), True) + self.assertIs(f.clean('0'), False) + self.assertIs(f.clean('Django rocks'), True) + self.assertIs(f.clean('False'), False) + self.assertIs(f.clean('false'), False) + self.assertIs(f.clean('FaLsE'), False) def test_boolean_picklable(self): self.assertIsInstance(pickle.loads(pickle.dumps(BooleanField())), BooleanField) diff --git a/tests/forms_tests/field_tests/test_uuidfield.py b/tests/forms_tests/field_tests/test_uuidfield.py index 05a3f0d8699..fe432e07256 100644 --- a/tests/forms_tests/field_tests/test_uuidfield.py +++ b/tests/forms_tests/field_tests/test_uuidfield.py @@ -16,7 +16,7 @@ class UUIDFieldTest(SimpleTestCase): def test_uuidfield_2(self): field = UUIDField(required=False) value = field.clean('') - self.assertEqual(value, None) + self.assertIsNone(value) def test_uuidfield_3(self): field = UUIDField() diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 4309fb3d865..89d8d6bb67f 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -323,7 +323,7 @@ class FormsTestCase(SimpleTestCase): data = {'first_name': 'John', 'last_name': 'Lennon'} f = OptionalPersonForm(data) self.assertTrue(f.is_valid()) - self.assertEqual(f.cleaned_data['birth_date'], None) + self.assertIsNone(f.cleaned_data['birth_date']) self.assertEqual(f.cleaned_data['first_name'], 'John') self.assertEqual(f.cleaned_data['last_name'], 'Lennon') @@ -1926,10 +1926,10 @@ Password: unbound = UserRegistration() bound = UserRegistration({'password': 'foo'}) - self.assertEqual(bound['username'].value(), None) + self.assertIsNone(bound['username'].value()) self.assertEqual(unbound['username'].value(), 'djangonaut') self.assertEqual(bound['password'].value(), 'foo') - self.assertEqual(unbound['password'].value(), None) + self.assertIsNone(unbound['password'].value()) def test_boundfield_initial_called_once(self): """ @@ -3089,7 +3089,7 @@ Good luck picking a username that doesn't already exist.
raise ValidationError('Non-field error.', code='secret', params={'a': 1, 'b': 2}) form = MyForm({}) - self.assertEqual(form.is_valid(), False) + self.assertIs(form.is_valid(), False) errors = form.errors.as_text() control = [ diff --git a/tests/forms_tests/widget_tests/test_checkboxinput.py b/tests/forms_tests/widget_tests/test_checkboxinput.py index 45d8191f75d..77b03b9ea96 100644 --- a/tests/forms_tests/widget_tests/test_checkboxinput.py +++ b/tests/forms_tests/widget_tests/test_checkboxinput.py @@ -84,4 +84,4 @@ class CheckboxInputTest(WidgetTest): def test_value_from_datadict_string_int(self): value = self.widget.value_from_datadict({'testing': '0'}, {}, 'testing') - self.assertEqual(value, True) + self.assertIs(value, True) diff --git a/tests/forms_tests/widget_tests/test_clearablefileinput.py b/tests/forms_tests/widget_tests/test_clearablefileinput.py index 46bad58f3a8..720f17b035f 100644 --- a/tests/forms_tests/widget_tests/test_clearablefileinput.py +++ b/tests/forms_tests/widget_tests/test_clearablefileinput.py @@ -87,7 +87,7 @@ class ClearableFileInputTest(WidgetTest): files={}, name='myfile', ) - self.assertEqual(value, False) + self.assertIs(value, False) def test_clear_input_checked_returns_false_only_if_not_required(self): """ diff --git a/tests/generic_inline_admin/tests.py b/tests/generic_inline_admin/tests.py index b047cc7a53a..936a76398f0 100644 --- a/tests/generic_inline_admin/tests.py +++ b/tests/generic_inline_admin/tests.py @@ -413,12 +413,12 @@ class GenericInlineModelAdminTest(SimpleTestCase): # Create a formset with default arguments formset = media_inline.get_formset(request) self.assertEqual(formset.max_num, DEFAULT_MAX_NUM) - self.assertEqual(formset.can_order, False) + self.assertIs(formset.can_order, False) # Create a formset with custom keyword arguments formset = media_inline.get_formset(request, max_num=100, can_order=True) self.assertEqual(formset.max_num, 100) - self.assertEqual(formset.can_order, True) + self.assertIs(formset.can_order, True) def test_custom_form_meta_exclude_with_readonly(self): """ diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py index 3b34a4caee1..af7a04c9a67 100644 --- a/tests/generic_views/test_dates.py +++ b/tests/generic_views/test_dates.py @@ -166,7 +166,7 @@ class YearArchiveViewTests(TestDataMixin, TestCase): self.assertTemplateUsed(res, 'generic_views/book_archive_year.html') # Since allow_empty=False, next/prev years must be valid (#7164) - self.assertEqual(res.context['next_year'], None) + self.assertIsNone(res.context['next_year']) self.assertEqual(res.context['previous_year'], datetime.date(2006, 1, 1)) def test_year_view_make_object_list(self): @@ -287,7 +287,7 @@ class MonthArchiveViewTests(TestDataMixin, TestCase): self.assertEqual(res.context['month'], datetime.date(2008, 10, 1)) # Since allow_empty=False, next/prev months must be valid (#7164) - self.assertEqual(res.context['next_month'], None) + self.assertIsNone(res.context['next_month']) self.assertEqual(res.context['previous_month'], datetime.date(2006, 5, 1)) def test_month_view_allow_empty(self): @@ -310,7 +310,7 @@ class MonthArchiveViewTests(TestDataMixin, TestCase): url = datetime.date.today().strftime('/dates/books/%Y/%b/allow_empty/').lower() res = self.client.get(url) self.assertEqual(res.status_code, 200) - self.assertEqual(res.context['next_month'], None) + self.assertIsNone(res.context['next_month']) def test_month_view_allow_future(self): future = (datetime.date.today() + datetime.timedelta(days=60)).replace(day=1) @@ -330,7 +330,7 @@ class MonthArchiveViewTests(TestDataMixin, TestCase): # Since allow_future = True but not allow_empty, next/prev are not # allowed to be empty months (#7164) - self.assertEqual(res.context['next_month'], None) + self.assertIsNone(res.context['next_month']) self.assertEqual(res.context['previous_month'], datetime.date(2008, 10, 1)) # allow_future, but not allow_empty, with a current month. So next @@ -417,7 +417,7 @@ class WeekArchiveViewTests(TestDataMixin, TestCase): self.assertEqual(res.context['week'], datetime.date(2008, 9, 28)) # Since allow_empty=False, next/prev weeks must be valid - self.assertEqual(res.context['next_week'], None) + self.assertIsNone(res.context['next_week']) self.assertEqual(res.context['previous_week'], datetime.date(2006, 4, 30)) def test_week_view_allow_empty(self): @@ -439,7 +439,7 @@ class WeekArchiveViewTests(TestDataMixin, TestCase): url = datetime.date.today().strftime('/dates/books/%Y/week/%U/allow_empty/').lower() res = self.client.get(url) self.assertEqual(res.status_code, 200) - self.assertEqual(res.context['next_week'], None) + self.assertIsNone(res.context['next_week']) def test_week_view_allow_future(self): # January 7th always falls in week 1, given Python's definition of week numbers @@ -457,7 +457,7 @@ class WeekArchiveViewTests(TestDataMixin, TestCase): # Since allow_future = True but not allow_empty, next/prev are not # allowed to be empty weeks - self.assertEqual(res.context['next_week'], None) + self.assertIsNone(res.context['next_week']) self.assertEqual(res.context['previous_week'], datetime.date(2008, 9, 28)) # allow_future, but not allow_empty, with a current week. So next @@ -520,7 +520,7 @@ class DayArchiveViewTests(TestDataMixin, TestCase): self.assertEqual(res.context['day'], datetime.date(2008, 10, 1)) # Since allow_empty=False, next/prev days must be valid. - self.assertEqual(res.context['next_day'], None) + self.assertIsNone(res.context['next_day']) self.assertEqual(res.context['previous_day'], datetime.date(2006, 5, 1)) def test_day_view_allow_empty(self): @@ -542,7 +542,7 @@ class DayArchiveViewTests(TestDataMixin, TestCase): url = datetime.date.today().strftime('/dates/books/%Y/%b/%d/allow_empty/').lower() res = self.client.get(url) self.assertEqual(res.status_code, 200) - self.assertEqual(res.context['next_day'], None) + self.assertIsNone(res.context['next_day']) def test_day_view_allow_future(self): future = (datetime.date.today() + datetime.timedelta(days=60)) @@ -560,7 +560,7 @@ class DayArchiveViewTests(TestDataMixin, TestCase): self.assertEqual(res.context['day'], future) # allow_future but not allow_empty, next/prev must be valid - self.assertEqual(res.context['next_day'], None) + self.assertIsNone(res.context['next_day']) self.assertEqual(res.context['previous_day'], datetime.date(2008, 10, 1)) # allow_future, but not allow_empty, with a current month. diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index c42ed95a86a..a9bf319a05f 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -241,8 +241,8 @@ class GISFunctionsTests(TestCase): State.objects.create(name='invalid', poly=invalid_geom) valid = State.objects.filter(name='valid').annotate(isvalid=functions.IsValid('poly')).first() invalid = State.objects.filter(name='invalid').annotate(isvalid=functions.IsValid('poly')).first() - self.assertEqual(valid.isvalid, True) - self.assertEqual(invalid.isvalid, False) + self.assertIs(valid.isvalid, True) + self.assertIs(invalid.isvalid, False) @skipUnlessDBFeature("has_Area_function") def test_area_with_regular_aggregate(self): @@ -265,7 +265,7 @@ class GISFunctionsTests(TestCase): invalid_geom = fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 1 1, 1 0, 0 0))') State.objects.create(name='invalid', poly=invalid_geom) invalid = State.objects.filter(name='invalid').annotate(repaired=functions.MakeValid('poly')).first() - self.assertEqual(invalid.repaired.valid, True) + self.assertIs(invalid.repaired.valid, True) self.assertEqual(invalid.repaired, fromstr('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')) @skipUnlessDBFeature("has_MemSize_function") diff --git a/tests/gis_tests/geoapp/test_regress.py b/tests/gis_tests/geoapp/test_regress.py index 155126a862f..7aa99966e3e 100644 --- a/tests/gis_tests/geoapp/test_regress.py +++ b/tests/gis_tests/geoapp/test_regress.py @@ -85,5 +85,5 @@ class GeoRegressionTests(TestCase): self.assertIsInstance(val1, bool) self.assertIsInstance(val2, bool) # verify values - self.assertEqual(val1, True) - self.assertEqual(val2, False) + self.assertIs(val1, True) + self.assertIs(val2, False) diff --git a/tests/gis_tests/geoapp/tests.py b/tests/gis_tests/geoapp/tests.py index 2b215f80a98..c88d4f1cf79 100644 --- a/tests/gis_tests/geoapp/tests.py +++ b/tests/gis_tests/geoapp/tests.py @@ -156,7 +156,7 @@ class GeoModelTest(TestCase): def test_createnull(self): "Testing creating a model instance and the geometry being None" c = City() - self.assertEqual(c.point, None) + self.assertIsNone(c.point) def test_geometryfield(self): "Testing the general GeometryField." @@ -397,7 +397,7 @@ class GeoLookupTest(TestCase): # Saving another commonwealth w/a NULL geometry. nmi = State.objects.create(name='Northern Mariana Islands', poly=None) - self.assertEqual(nmi.poly, None) + self.assertIsNone(nmi.poly) # Assigning a geometry and saving -- then UPDATE back to NULL. nmi.poly = 'POLYGON((0 0,1 0,1 1,1 0,0 0))' diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 98eabe8bee9..5a2ae5f919c 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -112,7 +112,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin): # garbage into 3D coordinate if there is none. self.assertEqual(hexewkb_2d, pnt_2d.hexewkb) self.assertEqual(hexewkb_3d, pnt_3d.hexewkb) - self.assertEqual(True, GEOSGeometry(hexewkb_3d).hasz) + self.assertIs(GEOSGeometry(hexewkb_3d).hasz, True) # Same for EWKB. self.assertEqual(six.memoryview(a2b_hex(hexewkb_2d)), pnt_2d.ewkb) @@ -247,14 +247,14 @@ class GEOSTest(SimpleTestCase, TestDataMixin): # Testing the third dimension, and getting the tuple arguments if hasattr(p, 'z'): - self.assertEqual(True, pnt.hasz) + self.assertIs(pnt.hasz, True) self.assertEqual(p.z, pnt.z) self.assertEqual(p.z, pnt.tuple[2], 9) tup_args = (p.x, p.y, p.z) set_tup1 = (2.71, 3.14, 5.23) set_tup2 = (5.23, 2.71, 3.14) else: - self.assertEqual(False, pnt.hasz) + self.assertIs(pnt.hasz, False) self.assertIsNone(pnt.z) tup_args = (p.x, p.y) set_tup1 = (2.71, 3.14) @@ -301,8 +301,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin): for p in mpnt: self.assertEqual(p.geom_type, 'Point') self.assertEqual(p.geom_typeid, 0) - self.assertEqual(p.empty, False) - self.assertEqual(p.valid, True) + self.assertIs(p.empty, False) + self.assertIs(p.valid, True) def test_linestring(self): "Testing LineString objects." @@ -312,8 +312,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin): self.assertEqual(ls.geom_type, 'LineString') self.assertEqual(ls.geom_typeid, 1) self.assertEqual(ls.dims, 1) - self.assertEqual(ls.empty, False) - self.assertEqual(ls.ring, False) + self.assertIs(ls.empty, False) + self.assertIs(ls.ring, False) if hasattr(l, 'centroid'): self.assertEqual(l.centroid, ls.centroid.tuple) if hasattr(l, 'tup'): @@ -367,7 +367,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin): for ls in ml: self.assertEqual(ls.geom_type, 'LineString') self.assertEqual(ls.geom_typeid, 1) - self.assertEqual(ls.empty, False) + self.assertIs(ls.empty, False) with self.assertRaises(IndexError): ml.__getitem__(len(ml)) @@ -382,8 +382,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin): self.assertEqual(lr.geom_typeid, 2) self.assertEqual(lr.dims, 1) self.assertEqual(rr.n_p, len(lr)) - self.assertEqual(True, lr.valid) - self.assertEqual(False, lr.empty) + self.assertIs(lr.valid, True) + self.assertIs(lr.empty, False) # Creating a LinearRing from a tuple, list, and numpy array self.assertEqual(lr, LinearRing(lr.tuple)) @@ -425,8 +425,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin): self.assertEqual(poly.geom_type, 'Polygon') self.assertEqual(poly.geom_typeid, 3) self.assertEqual(poly.dims, 2) - self.assertEqual(poly.empty, False) - self.assertEqual(poly.ring, False) + self.assertIs(poly.empty, False) + self.assertIs(poly.ring, False) self.assertEqual(p.n_i, poly.num_interior_rings) self.assertEqual(p.n_i + 1, len(poly)) # Testing __len__ self.assertEqual(p.n_p, poly.num_points) @@ -519,7 +519,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin): for p in mpoly: self.assertEqual(p.geom_type, 'Polygon') self.assertEqual(p.geom_typeid, 3) - self.assertEqual(p.valid, True) + self.assertIs(p.valid, True) self.assertEqual(mpoly.wkt, MultiPolygon(*tuple(poly.clone() for poly in mpoly)).wkt) def test_memory_hijinks(self): @@ -592,7 +592,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) i1 = fromstr(self.geometries.intersect_geoms[i].wkt) - self.assertEqual(True, a.intersects(b)) + self.assertIs(a.intersects(b), True) i2 = a.intersection(b) self.assertEqual(i1, i2) self.assertEqual(i1, a & b) # __and__ is intersection operator @@ -957,7 +957,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin): geoms.append(LineString(numpy.array([]))) for g in geoms: - self.assertEqual(True, g.empty) + self.assertIs(g.empty, True) # Testing len() and num_geom. if isinstance(g, Polygon): @@ -979,7 +979,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin): lr = g.shell self.assertEqual('LINEARRING EMPTY', lr.wkt) self.assertEqual(0, len(lr)) - self.assertEqual(True, lr.empty) + self.assertIs(lr.empty, True) with self.assertRaises(IndexError): lr.__getitem__(0) else: diff --git a/tests/gis_tests/geos_tests/test_io.py b/tests/gis_tests/geos_tests/test_io.py index 10762c08216..00fe3b67fd2 100644 --- a/tests/gis_tests/geos_tests/test_io.py +++ b/tests/gis_tests/geos_tests/test_io.py @@ -138,7 +138,7 @@ class GEOSIOTest(SimpleTestCase): def test_wkt_writer_precision(self): wkt_w = WKTWriter() - self.assertEqual(wkt_w.precision, None) + self.assertIsNone(wkt_w.precision) self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0.3333333333333333 0.6666666666666666)') wkt_w.precision = 1 @@ -150,7 +150,7 @@ class GEOSIOTest(SimpleTestCase): self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0 1)') wkt_w.precision = None - self.assertEqual(wkt_w.precision, None) + self.assertIsNone(wkt_w.precision) self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0.3333333333333333 0.6666666666666666)') with self.assertRaisesMessage(AttributeError, 'WKT output rounding precision must be '): diff --git a/tests/gis_tests/rasterapp/test_rasterfield.py b/tests/gis_tests/rasterapp/test_rasterfield.py index 82bed69def1..0dbeebd9d8f 100644 --- a/tests/gis_tests/rasterapp/test_rasterfield.py +++ b/tests/gis_tests/rasterapp/test_rasterfield.py @@ -185,11 +185,11 @@ class RasterFieldTest(TransactionTestCase): qs = RasterModel.objects.filter(**combo) # Evaluate normal filter qs. - self.assertTrue(qs.count() in [0, 1]) + self.assertIn(qs.count(), [0, 1]) # Evaluate on conditional Q expressions. qs = RasterModel.objects.filter(Q(**combos[0]) & Q(**combos[1])) - self.assertTrue(qs.count() in [0, 1]) + self.assertIn(qs.count(), [0, 1]) def test_dwithin_gis_lookup_ouptut_with_rasters(self): """ diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index 59ff3f4a70a..f715296fb82 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -59,8 +59,8 @@ class QueryDictTests(unittest.TestCase): q = QueryDict() self.assertEqual(q.getlist('foo'), []) if six.PY2: - self.assertEqual(q.has_key('foo'), False) - self.assertEqual('foo' in q, False) + self.assertIs(q.has_key('foo'), False) + self.assertNotIn('foo', q) self.assertEqual(list(six.iteritems(q)), []) self.assertEqual(list(six.iterlists(q)), []) self.assertEqual(list(six.iterkeys(q)), []) @@ -203,11 +203,11 @@ class QueryDictTests(unittest.TestCase): q.appendlist('foo', ['bar']) if six.PY2: - self.assertEqual(q.has_key('vote'), True) - self.assertEqual('vote' in q, True) + self.assertIs(q.has_key('vote'), True) + self.assertIn('vote', q) if six.PY2: - self.assertEqual(q.has_key('foo'), False) - self.assertEqual('foo' in q, False) + self.assertIs(q.has_key('foo'), False) + self.assertNotIn('foo', q) self.assertEqual(list(six.iteritems(q)), [('vote', 'no')]) self.assertEqual(list(six.iterlists(q)), [('vote', ['yes', 'no'])]) self.assertEqual(list(six.iterkeys(q)), ['vote']) @@ -243,13 +243,13 @@ class QueryDictTests(unittest.TestCase): def test_pickle(self): q = QueryDict() q1 = pickle.loads(pickle.dumps(q, 2)) - self.assertEqual(q == q1, True) + self.assertEqual(q, q1) q = QueryDict(str('a=b&c=d')) q1 = pickle.loads(pickle.dumps(q, 2)) - self.assertEqual(q == q1, True) + self.assertEqual(q, q1) q = QueryDict(str('a=b&c=d&a=1')) q1 = pickle.loads(pickle.dumps(q, 2)) - self.assertEqual(q == q1, True) + self.assertEqual(q, q1) def test_update_from_querydict(self): """Regression test for #8278: QueryDict.update(QueryDict)""" @@ -352,7 +352,7 @@ class HttpResponseTests(unittest.TestCase): Test for bug #14020: Make HttpResponse.get work like dict.get """ r = HttpResponse() - self.assertEqual(r.get('test'), None) + self.assertIsNone(r.get('test')) def test_non_string_content(self): # Bug 16494: HttpResponse should behave consistently with non-strings @@ -439,7 +439,7 @@ class HttpResponseTests(unittest.TestCase): self.assertEqual(r.getvalue(), b'asdf') r = HttpResponse() - self.assertEqual(r.writable(), True) + self.assertIs(r.writable(), True) r.writelines(['foo\n', 'bar\n', 'baz\n']) self.assertEqual(r.content, b'foo\nbar\nbaz\n') diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 5084f2dc1d2..6bff6321d08 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -76,10 +76,10 @@ class TranslationTests(SimpleTestCase): self.assertEqual(get_language(), 'pl') self.assertEqual(get_language(), 'de') with translation.override(None): - self.assertEqual(get_language(), None) + self.assertIsNone(get_language()) with translation.override('pl'): pass - self.assertEqual(get_language(), None) + self.assertIsNone(get_language()) self.assertEqual(get_language(), 'de') finally: deactivate() @@ -92,7 +92,7 @@ class TranslationTests(SimpleTestCase): @translation.override(None) def func_none(): - self.assertEqual(get_language(), None) + self.assertIsNone(get_language()) try: activate('de') @@ -475,9 +475,9 @@ class TranslationTests(SimpleTestCase): self.assertEqual(trans_real.to_language('sr_Lat'), 'sr-lat') def test_language_bidi(self): - self.assertEqual(get_language_bidi(), False) + self.assertIs(get_language_bidi(), False) with translation.override(None): - self.assertEqual(get_language_bidi(), False) + self.assertIs(get_language_bidi(), False) @override_settings(LOCALE_PATHS=[os.path.join(here, 'other', 'locale')]) def test_bad_placeholder_1(self): @@ -1463,13 +1463,13 @@ class MiscTests(SimpleTestCase): g = trans_real.get_language_from_path self.assertEqual(g('/pl/'), 'pl') self.assertEqual(g('/pl'), 'pl') - self.assertEqual(g('/xyz/'), None) + self.assertIsNone(g('/xyz/')) def test_get_language_from_path_null(self): from django.utils.translation.trans_null import get_language_from_path as g - self.assertEqual(g('/pl/'), None) - self.assertEqual(g('/pl'), None) - self.assertEqual(g('/xyz/'), None) + self.assertIsNone(g('/pl/')) + self.assertIsNone(g('/pl')) + self.assertIsNone(g('/xyz/')) @override_settings(LOCALE_PATHS=extended_locale_paths) def test_percent_in_translatable_block(self): @@ -1594,7 +1594,7 @@ class TestLanguageInfo(SimpleTestCase): self.assertEqual(li['code'], 'de') self.assertEqual(li['name_local'], 'Deutsch') self.assertEqual(li['name'], 'German') - self.assertEqual(li['bidi'], False) + self.assertIs(li['bidi'], False) def test_unknown_language_code(self): six.assertRaisesRegex(self, KeyError, r"Unknown language code xx\.", get_language_info, 'xx') @@ -1608,7 +1608,7 @@ class TestLanguageInfo(SimpleTestCase): self.assertEqual(li['code'], 'de') self.assertEqual(li['name_local'], 'Deutsch') self.assertEqual(li['name'], 'German') - self.assertEqual(li['bidi'], False) + self.assertIs(li['bidi'], False) def test_unknown_language_code_and_country_code(self): six.assertRaisesRegex(self, KeyError, r"Unknown language code xx-xx and xx\.", get_language_info, 'xx-xx') diff --git a/tests/inline_formsets/tests.py b/tests/inline_formsets/tests.py index 84faa08894d..6e96f51e6fe 100644 --- a/tests/inline_formsets/tests.py +++ b/tests/inline_formsets/tests.py @@ -44,14 +44,14 @@ class DeletionTests(TestCase): } formset = PoemFormSet(data, instance=poet) # Make sure this form doesn't pass validation. - self.assertEqual(formset.is_valid(), False) + self.assertIs(formset.is_valid(), False) self.assertEqual(Poem.objects.count(), 0) # Then make sure that it *does* pass validation and delete the object, # even though the data isn't actually valid. data['poem_set-0-DELETE'] = 'on' formset = PoemFormSet(data, instance=poet) - self.assertEqual(formset.is_valid(), True) + self.assertIs(formset.is_valid(), True) formset.save() self.assertEqual(Poem.objects.count(), 0) @@ -73,14 +73,14 @@ class DeletionTests(TestCase): } formset = PoemFormSet(data, instance=poet) # Make sure this form doesn't pass validation. - self.assertEqual(formset.is_valid(), False) + self.assertIs(formset.is_valid(), False) self.assertEqual(Poem.objects.count(), 1) # Then make sure that it *does* pass validation and delete the object, # even though the data isn't actually valid. data['poem_set-0-DELETE'] = 'on' formset = PoemFormSet(data, instance=poet) - self.assertEqual(formset.is_valid(), True) + self.assertIs(formset.is_valid(), True) formset.save() self.assertEqual(Poem.objects.count(), 0) @@ -101,7 +101,7 @@ class DeletionTests(TestCase): 'child_set-0-name': 'child', } formset = ChildFormSet(data, instance=school) - self.assertEqual(formset.is_valid(), True) + self.assertIs(formset.is_valid(), True) objects = formset.save(commit=False) for obj in objects: obj.mother = mother diff --git a/tests/logging_tests/tests.py b/tests/logging_tests/tests.py index 1802a0ce475..f6f1db7a6b9 100644 --- a/tests/logging_tests/tests.py +++ b/tests/logging_tests/tests.py @@ -48,10 +48,10 @@ class LoggingFiltersTest(SimpleTestCase): filter_ = RequireDebugFalse() with self.settings(DEBUG=True): - self.assertEqual(filter_.filter("record is not used"), False) + self.assertIs(filter_.filter("record is not used"), False) with self.settings(DEBUG=False): - self.assertEqual(filter_.filter("record is not used"), True) + self.assertIs(filter_.filter("record is not used"), True) def test_require_debug_true_filter(self): """ @@ -60,10 +60,10 @@ class LoggingFiltersTest(SimpleTestCase): filter_ = RequireDebugTrue() with self.settings(DEBUG=True): - self.assertEqual(filter_.filter("record is not used"), True) + self.assertIs(filter_.filter("record is not used"), True) with self.settings(DEBUG=False): - self.assertEqual(filter_.filter("record is not used"), False) + self.assertIs(filter_.filter("record is not used"), False) class SetupDefaultLoggingMixin(object): diff --git a/tests/m2o_recursive/tests.py b/tests/m2o_recursive/tests.py index b21aef95d3e..8e730d48a70 100644 --- a/tests/m2o_recursive/tests.py +++ b/tests/m2o_recursive/tests.py @@ -17,7 +17,7 @@ class ManyToOneRecursiveTests(TestCase): self.assertQuerysetEqual(self.r.child_set.all(), ['