From c51bf80d56cbcdbec1b243b8db086f35b4598947 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Fri, 16 Apr 2021 23:19:25 +0200 Subject: [PATCH] Used more specific unittest assertions in tests. --- tests/annotations/tests.py | 2 +- tests/auth_tests/test_forms.py | 2 +- tests/backends/tests.py | 2 +- tests/model_inheritance/test_abstract_inheritance.py | 6 +++--- tests/test_runner/test_discover_runner.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 2aa1765125e..c0fe308a073 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -241,7 +241,7 @@ class NonAggregateAnnotationTestCase(TestCase): ), rating_count=Count('rating'), ).first() - self.assertEqual(book.isnull_pubdate, False) + self.assertIs(book.isnull_pubdate, False) self.assertEqual(book.rating_count, 1) @skipUnlessDBFeature('supports_boolean_expr_in_select_clause') diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 76b0eb7f3cd..e208305fc65 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -1035,7 +1035,7 @@ class ReadOnlyPasswordHashTest(SimpleTestCase): hash_field = ReadOnlyPasswordHashField() bound_field = TestForm()['hash_field'] - self.assertEqual(bound_field.field.widget.id_for_label('id'), None) + self.assertIsNone(bound_field.field.widget.id_for_label('id')) self.assertEqual(bound_field.label_tag(), '') diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 1536e930651..2291a76c75e 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -501,7 +501,7 @@ class BackendTestCase(TransactionTestCase): params, kwargs = mocked_logger.debug.call_args self.assertIn('; alias=%s', params[0]) self.assertEqual(params[2], sql) - self.assertEqual(params[3], None) + self.assertIsNone(params[3]) self.assertEqual(params[4], connection.alias) self.assertEqual( list(kwargs['extra']), diff --git a/tests/model_inheritance/test_abstract_inheritance.py b/tests/model_inheritance/test_abstract_inheritance.py index f2dab05b8be..a78111b5e38 100644 --- a/tests/model_inheritance/test_abstract_inheritance.py +++ b/tests/model_inheritance/test_abstract_inheritance.py @@ -57,7 +57,7 @@ class AbstractInheritanceTests(SimpleTestCase): self.assertEqual(Child.check(), []) inherited_field = Child._meta.get_field('name') - self.assertTrue(isinstance(inherited_field, models.CharField)) + self.assertIsInstance(inherited_field, models.CharField) self.assertEqual(inherited_field.max_length, 255) def test_diamond_shaped_multiple_inheritance_is_depth_first(self): @@ -93,7 +93,7 @@ class AbstractInheritanceTests(SimpleTestCase): self.assertEqual(Child.check(), []) inherited_field = Child._meta.get_field('name') - self.assertTrue(isinstance(inherited_field, models.CharField)) + self.assertIsInstance(inherited_field, models.CharField) self.assertEqual(inherited_field.max_length, 255) def test_target_field_may_be_pushed_down(self): @@ -124,7 +124,7 @@ class AbstractInheritanceTests(SimpleTestCase): self.assertEqual(Child.check(), []) inherited_field = Child._meta.get_field('name') - self.assertTrue(isinstance(inherited_field, models.IntegerField)) + self.assertIsInstance(inherited_field, models.IntegerField) def test_multiple_inheritance_cannot_shadow_concrete_inherited_field(self): class ConcreteParent(models.Model): diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index 9fb6d9f09d9..4f7aed059f1 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -405,7 +405,7 @@ class DiscoverRunnerTests(SimpleTestCase): with runner.time_keeper.timed('test'): pass runner.time_keeper.print_results() - self.assertTrue(isinstance(runner.time_keeper, NullTimeKeeper)) + self.assertIsInstance(runner.time_keeper, NullTimeKeeper) self.assertNotIn('test', stderr.getvalue()) def test_timings_captured(self): @@ -414,7 +414,7 @@ class DiscoverRunnerTests(SimpleTestCase): with runner.time_keeper.timed('test'): pass runner.time_keeper.print_results() - self.assertTrue(isinstance(runner.time_keeper, TimeKeeper)) + self.assertIsInstance(runner.time_keeper, TimeKeeper) self.assertIn('test', stderr.getvalue()) def test_log(self):