From 7552de7866dcd270a0f353b007b4aceaa7f3ff3e Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Mon, 21 Oct 2019 09:55:05 +0100 Subject: Used more specific unittest assertions in tests. * assertIsNone()/assertIsNotNone() instead of comparing to None. * assertLess() for < comparisons. * assertIs() for 'is' expressions. * assertIsInstance() for isinstance() expressions. * rounding of assertAlmostEqual() for round() expressions. * assertIs(..., True/False) instead of comparing to True/False. * assertIs()/assertIsNot() for ==/!= comparisons. * assertNotEqual() for == comparisons. * assertTrue()/assertFalse() instead of comparing to True/False. --- tests/schema/tests.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/schema') diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 9a2195d1d5..b4d95c431c 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -468,7 +468,7 @@ class SchemaTests(TransactionTestCase): # Ensure the field is right afterwards columns = self.column_classes(Author) self.assertEqual(columns['age'][0], "IntegerField") - self.assertEqual(columns['age'][1][6], True) + self.assertTrue(columns['age'][1][6]) def test_add_field_remove_field(self): """ @@ -620,7 +620,7 @@ class SchemaTests(TransactionTestCase): # Ensure the field is right afterwards columns = self.column_classes(Author) self.assertEqual(columns['name'][0], "TextField") - self.assertEqual(columns['name'][1][6], True) + self.assertTrue(columns['name'][1][6]) # Change nullability again new_field2 = TextField(null=False) new_field2.set_attributes_from_name("name") @@ -2100,25 +2100,25 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.create_model(Tag) # Ensure there's no index on the year/slug columns first - self.assertEqual( - False, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tag").values() if c['columns'] == ["slug", "title"] ), + False, ) # Alter the model to add an index with connection.schema_editor() as editor: editor.alter_index_together(Tag, [], [("slug", "title")]) # Ensure there is now an index - self.assertEqual( - True, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tag").values() if c['columns'] == ["slug", "title"] ), + True, ) # Alter it back new_field2 = SlugField(unique=True) @@ -2126,13 +2126,13 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_index_together(Tag, [("slug", "title")], []) # Ensure there's no index - self.assertEqual( - False, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tag").values() if c['columns'] == ["slug", "title"] ), + False, ) def test_index_together_with_fk(self): @@ -2161,13 +2161,13 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.create_model(TagIndexed) # Ensure there is an index - self.assertEqual( - True, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tagindexed").values() if c['columns'] == ["slug", "title"] ), + True, ) @skipUnlessDBFeature('allows_multiple_constraints_on_same_fields') -- cgit v1.3