From c37eb3c870db46f64578e9974f576dd2d8c40f8a Mon Sep 17 00:00:00 2001 From: Alasdair Nicol Date: Mon, 27 Apr 2015 15:59:16 +0100 Subject: [PATCH] [1.8.x] Fixed #24714 -- Used more specific assertions than assertEqual in tests. Backport of eaeea6f94701547ce1b50dbcf5cf71460e9e4c91 from master --- tests/delete/tests.py | 14 ++++---- tests/forms_tests/tests/test_fields.py | 48 ++++++++++++------------- tests/forms_tests/tests/test_forms.py | 12 +++---- tests/forms_tests/tests/tests.py | 2 +- tests/generic_views/test_edit.py | 2 +- tests/gis_tests/gdal_tests/test_ds.py | 6 ++-- tests/gis_tests/gdal_tests/test_srs.py | 2 +- tests/gis_tests/geos_tests/test_geos.py | 25 ++++++------- tests/gis_tests/relatedapp/tests.py | 2 +- tests/gis_tests/test_geoip.py | 8 ++--- tests/gis_tests/test_spatialrefsys.py | 6 ++-- tests/i18n/tests.py | 24 ++++++------- tests/model_fields/tests.py | 2 +- tests/multiple_database/tests.py | 2 +- tests/postgres_tests/test_ranges.py | 2 +- tests/validation/test_validators.py | 2 +- tests/validation/tests.py | 6 ++-- 17 files changed, 83 insertions(+), 82 deletions(-) diff --git a/tests/delete/tests.py b/tests/delete/tests.py index 24d5aeabea1..6c7c8004830 100644 --- a/tests/delete/tests.py +++ b/tests/delete/tests.py @@ -37,7 +37,7 @@ class OnDeleteTests(TestCase): a = create_a('setnull') a.setnull.delete() a = A.objects.get(pk=a.pk) - self.assertEqual(None, a.setnull) + self.assertIsNone(a.setnull) def test_setdefault(self): a = create_a('setdefault') @@ -49,7 +49,7 @@ class OnDeleteTests(TestCase): a = create_a('setdefault_none') a.setdefault_none.delete() a = A.objects.get(pk=a.pk) - self.assertEqual(None, a.setdefault_none) + self.assertIsNone(a.setdefault_none) def test_cascade(self): a = create_a('cascade') @@ -119,7 +119,7 @@ class OnDeleteTests(TestCase): self.assertFalse(R.objects.filter(pk=a.child_setnull_id).exists()) a = A.objects.get(pk=a.pk) - self.assertEqual(None, a.child_setnull) + self.assertIsNone(a.child_setnull) def test_setnull_from_parent(self): a = create_a('child_setnull') @@ -127,13 +127,13 @@ class OnDeleteTests(TestCase): self.assertFalse(RChild.objects.filter(pk=a.child_setnull_id).exists()) a = A.objects.get(pk=a.pk) - self.assertEqual(None, a.child_setnull) + self.assertIsNone(a.child_setnull) def test_o2o_setnull(self): a = create_a('o2o_setnull') a.o2o_setnull.delete() a = A.objects.get(pk=a.pk) - self.assertEqual(None, a.o2o_setnull) + self.assertIsNone(a.o2o_setnull) class DeletionTests(TestCase): @@ -197,11 +197,11 @@ class DeletionTests(TestCase): a.cascade.delete() for obj in deleted: - self.assertEqual(None, obj.pk) + self.assertIsNone(obj.pk) for pk_list in related_setnull_sets: for a in A.objects.filter(id__in=pk_list): - self.assertEqual(None, a.setnull) + self.assertIsNone(a.setnull) models.signals.pre_delete.disconnect(pre_delete) diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 90318e701a4..1d09b1a8b33 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -186,9 +186,9 @@ class FieldsTests(SimpleTestCase): def test_integerfield_2(self): f = IntegerField(required=False) - self.assertEqual(None, f.clean('')) + self.assertIsNone(f.clean('')) self.assertEqual('None', repr(f.clean(''))) - self.assertEqual(None, f.clean(None)) + self.assertIsNone(f.clean(None)) self.assertEqual('None', repr(f.clean(None))) self.assertEqual(1, f.clean('1')) self.assertIsInstance(f.clean('1'), int) @@ -285,8 +285,8 @@ class FieldsTests(SimpleTestCase): def test_floatfield_2(self): f = FloatField(required=False) - self.assertEqual(None, f.clean('')) - self.assertEqual(None, f.clean(None)) + self.assertIsNone(f.clean('')) + self.assertIsNone(f.clean(None)) self.assertEqual(1.0, f.clean('1')) self.assertEqual(f.max_value, None) self.assertEqual(f.min_value, None) @@ -363,8 +363,8 @@ class FieldsTests(SimpleTestCase): def test_decimalfield_2(self): f = DecimalField(max_digits=4, decimal_places=2, required=False) - self.assertEqual(None, f.clean('')) - self.assertEqual(None, f.clean(None)) + self.assertIsNone(f.clean('')) + self.assertIsNone(f.clean(None)) self.assertEqual(f.clean('1'), Decimal("1")) self.assertEqual(f.max_digits, 4) self.assertEqual(f.decimal_places, 2) @@ -460,9 +460,9 @@ class FieldsTests(SimpleTestCase): def test_datefield_2(self): f = DateField(required=False) - self.assertEqual(None, f.clean(None)) + self.assertIsNone(f.clean(None)) self.assertEqual('None', repr(f.clean(None))) - self.assertEqual(None, f.clean('')) + self.assertIsNone(f.clean('')) self.assertEqual('None', repr(f.clean(''))) def test_datefield_3(self): @@ -581,9 +581,9 @@ class FieldsTests(SimpleTestCase): def test_datetimefield_3(self): f = DateTimeField(required=False) - self.assertEqual(None, f.clean(None)) + self.assertIsNone(f.clean(None)) self.assertEqual('None', repr(f.clean(None))) - self.assertEqual(None, f.clean('')) + self.assertIsNone(f.clean('')) self.assertEqual('None', repr(f.clean(''))) def test_datetimefield_4(self): @@ -1048,7 +1048,7 @@ class FieldsTests(SimpleTestCase): def test_typedchoicefield_6(self): f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int, required=False, empty_value=None) - self.assertEqual(None, f.clean('')) + self.assertIsNone(f.clean('')) def test_typedchoicefield_has_changed(self): # has_changed should not trigger required validation @@ -1076,15 +1076,15 @@ class FieldsTests(SimpleTestCase): def test_nullbooleanfield_1(self): f = NullBooleanField() - self.assertEqual(None, f.clean('')) + self.assertIsNone(f.clean('')) self.assertEqual(True, f.clean(True)) self.assertEqual(False, f.clean(False)) - self.assertEqual(None, f.clean(None)) + self.assertIsNone(f.clean(None)) self.assertEqual(False, f.clean('0')) self.assertEqual(True, f.clean('1')) - self.assertEqual(None, f.clean('2')) - self.assertEqual(None, f.clean('3')) - self.assertEqual(None, f.clean('hello')) + self.assertIsNone(f.clean('2')) + self.assertIsNone(f.clean('3')) + self.assertIsNone(f.clean('hello')) self.assertEqual(True, f.clean('true')) self.assertEqual(False, f.clean('false')) @@ -1101,7 +1101,7 @@ class FieldsTests(SimpleTestCase): hidden_nullbool1 = NullBooleanField(widget=HiddenInput, initial=True) hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False) f = HiddenNullBooleanForm({'hidden_nullbool1': 'True', 'hidden_nullbool2': 'False'}) - self.assertEqual(None, f.full_clean()) + self.assertIsNone(f.full_clean()) self.assertEqual(True, f.cleaned_data['hidden_nullbool1']) self.assertEqual(False, f.cleaned_data['hidden_nullbool2']) @@ -1115,10 +1115,10 @@ class FieldsTests(SimpleTestCase): nullbool1 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) nullbool2 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES)) f = MySQLNullBooleanForm({'nullbool0': '1', 'nullbool1': '0', 'nullbool2': ''}) - self.assertEqual(None, f.full_clean()) + self.assertIsNone(f.full_clean()) self.assertEqual(True, f.cleaned_data['nullbool0']) self.assertEqual(False, f.cleaned_data['nullbool1']) - self.assertEqual(None, f.cleaned_data['nullbool2']) + self.assertIsNone(f.cleaned_data['nullbool2']) def test_nullbooleanfield_changed(self): f = NullBooleanField() @@ -1221,7 +1221,7 @@ class FieldsTests(SimpleTestCase): def test_typedmultiplechoicefield_7(self): # If you want cleaning an empty value to return a different type, tell the field f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int, required=False, empty_value=None) - self.assertEqual(None, f.clean([])) + self.assertIsNone(f.clean([])) def test_typedmultiplechoicefield_has_changed(self): # has_changed should not trigger required validation @@ -1377,10 +1377,10 @@ class FieldsTests(SimpleTestCase): f = SplitDateTimeField(required=False) self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)])) self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean(['2006-01-10', '07:30'])) - self.assertEqual(None, f.clean(None)) - self.assertEqual(None, f.clean('')) - self.assertEqual(None, f.clean([''])) - self.assertEqual(None, f.clean(['', ''])) + self.assertIsNone(f.clean(None)) + self.assertIsNone(f.clean('')) + self.assertIsNone(f.clean([''])) + self.assertIsNone(f.clean(['', ''])) self.assertRaisesMessage(ValidationError, "'Enter a list of values.'", f.clean, 'hello') six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there']) self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', 'there']) diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index e1b378436a5..778343cf40f 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -2068,9 +2068,9 @@ class FormsTestCase(TestCase): # Empty values for fields will NOT raise a `required` error on an # optional `MultiValueField` f = PhoneField(required=False) - self.assertEqual(None, f.clean('')) - self.assertEqual(None, f.clean(None)) - self.assertEqual(None, f.clean([])) + self.assertIsNone(f.clean('')) + self.assertIsNone(f.clean(None)) + self.assertIsNone(f.clean([])) self.assertEqual('+61. ext. (label: )', f.clean(['+61'])) self.assertEqual('+61.287654321 ext. 123 (label: )', f.clean(['+61', '287654321', '123'])) self.assertEqual('+61.287654321 ext. 123 (label: Home)', f.clean(['+61', '287654321', '123', 'Home'])) @@ -2095,9 +2095,9 @@ class FormsTestCase(TestCase): # For an optional `MultiValueField` with `require_all_fields=False`, we # don't get any `required` error but we still get `incomplete` errors. f = PhoneField(required=False, require_all_fields=False) - self.assertEqual(None, f.clean('')) - self.assertEqual(None, f.clean(None)) - self.assertEqual(None, f.clean([])) + self.assertIsNone(f.clean('')) + self.assertIsNone(f.clean(None)) + self.assertIsNone(f.clean([])) self.assertRaisesMessage(ValidationError, "'Enter a complete value.'", f.clean, ['+61']) self.assertEqual('+61.287654321 ext. 123 (label: )', f.clean(['+61', '287654321', '123'])) six.assertRaisesRegex(self, ValidationError, diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index 8e8aa82cdd6..6dafee1fb87 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -334,7 +334,7 @@ class EmptyLabelTestCase(TestCase): def test_get_display_value_on_none(self): m = ChoiceModel.objects.create(name='test', choice='', choice_integer=None) - self.assertEqual(None, m.choice_integer) + self.assertIsNone(m.choice_integer) self.assertEqual('No Preference', m.get_choice_integer_display()) def test_html_rendering_of_prepopulated_models(self): diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py index 91d0d20ff7b..4bf3957a489 100644 --- a/tests/generic_views/test_edit.py +++ b/tests/generic_views/test_edit.py @@ -35,7 +35,7 @@ class FormMixinTests(TestCase): request = get_request default_kwargs = TestFormMixin().get_form_kwargs() - self.assertEqual(None, default_kwargs.get('prefix')) + self.assertIsNone(default_kwargs.get('prefix')) set_mixin = TestFormMixin() set_mixin.prefix = test_string diff --git a/tests/gis_tests/gdal_tests/test_ds.py b/tests/gis_tests/gdal_tests/test_ds.py index c9cb17fc9cf..0de4c282b9a 100644 --- a/tests/gis_tests/gdal_tests/test_ds.py +++ b/tests/gis_tests/gdal_tests/test_ds.py @@ -118,7 +118,7 @@ class DataSourceTest(unittest.TestCase): # Now checking the field names. flds = layer.fields for f in flds: - self.assertEqual(True, f in source.fields) + self.assertIn(f, source.fields) # Negative FIDs are not allowed. self.assertRaises(OGRIndexError, layer.__getitem__, -1) @@ -199,7 +199,7 @@ class DataSourceTest(unittest.TestCase): # Testing Feature.__iter__ for fld in feat: - self.assertEqual(True, fld.name in source.fields.keys()) + self.assertIn(fld.name, source.fields.keys()) def test05_geometries(self): "Testing Geometries from Data Source Features." @@ -229,7 +229,7 @@ class DataSourceTest(unittest.TestCase): lyr = ds[0] # When not set, it should be None. - self.assertEqual(None, lyr.spatial_filter) + self.assertIsNone(lyr.spatial_filter) # Must be set a/an OGRGeometry or 4-tuple. self.assertRaises(TypeError, lyr._set_spatial_filter, 'foo') diff --git a/tests/gis_tests/gdal_tests/test_srs.py b/tests/gis_tests/gdal_tests/test_srs.py index 1d011d88ab4..98e43127862 100644 --- a/tests/gis_tests/gdal_tests/test_srs.py +++ b/tests/gis_tests/gdal_tests/test_srs.py @@ -255,4 +255,4 @@ class SpatialRefTest(unittest.TestCase): self.assertEqual('WGS_1984', s1['DATUM']) self.assertEqual('EPSG', s1['AUTHORITY']) self.assertEqual(4326, int(s1['AUTHORITY', 1])) - self.assertEqual(None, s1['FOOBAR']) + self.assertIsNone(s1['FOOBAR']) diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 53de275492c..29a0d11a480 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -228,8 +228,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertEqual(pnt.geom_typeid, 0) self.assertEqual(p.x, pnt.x) self.assertEqual(p.y, pnt.y) - self.assertEqual(True, pnt == fromstr(p.wkt)) - self.assertEqual(False, pnt == prev) + self.assertEqual(pnt, fromstr(p.wkt)) + self.assertEqual(False, pnt == prev) # Use assertEqual to test __eq__ # Making sure that the point's X, Y components are what we expect self.assertAlmostEqual(p.x, pnt.tuple[0], 9) @@ -245,7 +245,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin): set_tup2 = (5.23, 2.71, 3.14) else: self.assertEqual(False, pnt.hasz) - self.assertEqual(None, pnt.z) + self.assertIsNone(pnt.z) tup_args = (p.x, p.y) set_tup1 = (2.71, 3.14) set_tup2 = (3.14, 2.71) @@ -256,8 +256,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin): # Now testing the different constructors pnt2 = Point(tup_args) # e.g., Point((1, 2)) pnt3 = Point(*tup_args) # e.g., Point(1, 2) - self.assertEqual(True, pnt == pnt2) - self.assertEqual(True, pnt == pnt3) + self.assertEqual(pnt, pnt2) + self.assertEqual(pnt, pnt3) # Now testing setting the x and y pnt.y = 3.14 @@ -306,8 +306,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin): if hasattr(l, 'tup'): self.assertEqual(l.tup, ls.tuple) - self.assertEqual(True, ls == fromstr(l.wkt)) - self.assertEqual(False, ls == prev) + self.assertEqual(ls, fromstr(l.wkt)) + self.assertEqual(False, ls == prev) # Use assertEqual to test __eq__ self.assertRaises(GEOSIndexError, ls.__getitem__, len(ls)) prev = ls @@ -331,8 +331,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertAlmostEqual(l.centroid[0], ml.centroid.x, 9) self.assertAlmostEqual(l.centroid[1], ml.centroid.y, 9) - self.assertEqual(True, ml == fromstr(l.wkt)) - self.assertEqual(False, ml == prev) + self.assertEqual(ml, fromstr(l.wkt)) + self.assertEqual(False, ml == prev) # Use assertEqual to test __eq__ prev = ml for ls in ml: @@ -395,9 +395,10 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertAlmostEqual(p.centroid[1], poly.centroid.tuple[1], 9) # Testing the geometry equivalence - self.assertEqual(True, poly == fromstr(p.wkt)) - self.assertEqual(False, poly == prev) # Should not be equal to previous geometry - self.assertEqual(True, poly != prev) + self.assertEqual(poly, fromstr(p.wkt)) + # Should not be equal to previous geometry + self.assertEqual(False, poly == prev) # Use assertEqual to test __eq__ + self.assertNotEqual(poly, prev) # Use assertNotEqual to test __ne__ # Testing the exterior ring ring = poly.exterior_ring diff --git a/tests/gis_tests/relatedapp/tests.py b/tests/gis_tests/relatedapp/tests.py index 623b32cab9d..5513def0f1c 100644 --- a/tests/gis_tests/relatedapp/tests.py +++ b/tests/gis_tests/relatedapp/tests.py @@ -291,7 +291,7 @@ class RelatedGeoModelTest(TestCase): Book.objects.create(title='Without Author') b = Book.objects.select_related('author').get(title='Without Author') # Should be `None`, and not a 'dummy' model. - self.assertEqual(None, b.author) + self.assertIsNone(b.author) @skipUnlessDBFeature("supports_collect_aggr") @ignore_warnings(category=RemovedInDjango20Warning) diff --git a/tests/gis_tests/test_geoip.py b/tests/gis_tests/test_geoip.py index 91a84d42af9..3262b8c3c5d 100644 --- a/tests/gis_tests/test_geoip.py +++ b/tests/gis_tests/test_geoip.py @@ -35,16 +35,16 @@ class GeoIPTest(unittest.TestCase): g3 = GeoIP.open(path, 0) # MaxMind Python API syntax. for g in (g1, g2, g3): - self.assertEqual(True, bool(g._country)) - self.assertEqual(True, bool(g._city)) + self.assertTrue(g._country) + self.assertTrue(g._city) # Only passing in the location of one database. city = os.path.join(path, 'GeoLiteCity.dat') cntry = os.path.join(path, 'GeoIP.dat') g4 = GeoIP(city, country='') - self.assertEqual(None, g4._country) + self.assertIsNone(g4._country) g5 = GeoIP(cntry, city='') - self.assertEqual(None, g5._city) + self.assertIsNone(g5._city) # Improper parameters. bad_params = (23, 'foo', 15.23) diff --git a/tests/gis_tests/test_spatialrefsys.py b/tests/gis_tests/test_spatialrefsys.py index 66e30f3de1c..e0c593ff4a1 100644 --- a/tests/gis_tests/test_spatialrefsys.py +++ b/tests/gis_tests/test_spatialrefsys.py @@ -56,7 +56,7 @@ class SpatialRefSysTest(unittest.TestCase): # the testing with the 'startswith' flag. auth_name, oracle_flag = sd['auth_name'] if postgis or (oracle and oracle_flag): - self.assertEqual(True, srs.auth_name.startswith(auth_name)) + self.assertTrue(srs.auth_name.startswith(auth_name)) self.assertEqual(sd['auth_srid'], srs.auth_srid) @@ -71,14 +71,14 @@ class SpatialRefSysTest(unittest.TestCase): """ for sd in test_srs: sr = SpatialRefSys.objects.get(srid=sd['srid']) - self.assertEqual(True, sr.spheroid.startswith(sd['spheroid'])) + self.assertTrue(sr.spheroid.startswith(sd['spheroid'])) self.assertEqual(sd['geographic'], sr.geographic) self.assertEqual(sd['projected'], sr.projected) if not (spatialite and not sd['spatialite']): # Can't get 'NAD83 / Texas South Central' from PROJ.4 string # on SpatiaLite - self.assertEqual(True, sr.name.startswith(sd['name'])) + self.assertTrue(sr.name.startswith(sd['name'])) # Testing the SpatialReference object directly. if postgis or spatialite: diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index ce4405789e5..dd84aa815ff 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -130,13 +130,13 @@ class TranslationTests(TestCase): # It should be possible to compare *_lazy objects. s1 = ugettext_lazy('Add %(name)s') - self.assertEqual(True, s == s1) + self.assertEqual(s, s1) s2 = gettext_lazy('Add %(name)s') s3 = gettext_lazy('Add %(name)s') - self.assertEqual(True, s2 == s3) - self.assertEqual(True, s == s2) + self.assertEqual(s2, s3) + self.assertEqual(s, s2) s4 = ugettext_lazy('Some other string') - self.assertEqual(False, s == s4) + self.assertNotEqual(s, s4) @skipUnless(six.PY2, "No more bytestring translations on PY3") def test_lazy_and_bytestrings(self): @@ -543,7 +543,7 @@ class FormattingTests(TestCase): 'time_field': '20:50', 'integer_field': '1.234', }) - self.assertEqual(False, form.is_valid()) + self.assertFalse(form.is_valid()) self.assertEqual(['Introdu\xefu un n\xfamero.'], form.errors['float_field']) self.assertEqual(['Introdu\xefu un n\xfamero.'], form.errors['decimal_field']) self.assertEqual(['Introdu\xefu una data v\xe0lida.'], form.errors['date_field']) @@ -555,7 +555,7 @@ class FormattingTests(TestCase): 'date_field_day': '31', 'date_field_year': '2009' }) - self.assertEqual(True, form2.is_valid()) + self.assertTrue(form2.is_valid()) self.assertEqual(datetime.date(2009, 12, 31), form2.cleaned_data['date_field']) self.assertHTMLEqual( '\n\n', @@ -630,7 +630,7 @@ class FormattingTests(TestCase): 'time_field': '20:50', 'integer_field': '1.234', }) - self.assertEqual(True, form3.is_valid()) + self.assertTrue(form3.is_valid()) self.assertEqual(decimal.Decimal('66666.666'), form3.cleaned_data['decimal_field']) self.assertEqual(99999.999, form3.cleaned_data['float_field']) self.assertEqual(datetime.date(2009, 12, 31), form3.cleaned_data['date_field']) @@ -660,7 +660,7 @@ class FormattingTests(TestCase): 'time_field': '20:50', 'integer_field': '1234', }) - self.assertEqual(True, form4.is_valid()) + self.assertTrue(form4.is_valid()) self.assertEqual(decimal.Decimal('66666.666'), form4.cleaned_data['decimal_field']) self.assertEqual(99999.999, form4.cleaned_data['float_field']) self.assertEqual(datetime.date(2009, 12, 31), form4.cleaned_data['date_field']) @@ -673,7 +673,7 @@ class FormattingTests(TestCase): 'date_field_day': '31', 'date_field_year': '2009' }) - self.assertEqual(True, form5.is_valid()) + self.assertTrue(form5.is_valid()) self.assertEqual(datetime.date(2009, 12, 31), form5.cleaned_data['date_field']) self.assertHTMLEqual( '\n\n', @@ -732,7 +732,7 @@ class FormattingTests(TestCase): 'time_field': '20:50', 'integer_field': '1234', }) - self.assertEqual(True, form5.is_valid()) + self.assertTrue(form5.is_valid()) self.assertEqual(decimal.Decimal('66666.666'), form5.cleaned_data['decimal_field']) self.assertEqual(99999.999, form5.cleaned_data['float_field']) self.assertEqual(datetime.date(2009, 12, 31), form5.cleaned_data['date_field']) @@ -745,7 +745,7 @@ class FormattingTests(TestCase): 'date_field_day': '31', 'date_field_year': '2009' }) - self.assertEqual(True, form6.is_valid()) + self.assertTrue(form6.is_valid()) self.assertEqual(datetime.date(2009, 12, 31), form6.cleaned_data['date_field']) self.assertHTMLEqual( '\n\n', @@ -774,7 +774,7 @@ class FormattingTests(TestCase): 'cents_paid': decimal.Decimal('59.47'), 'products_delivered': 12000, }) - self.assertEqual(True, form6.is_valid()) + self.assertTrue(form6.is_valid()) self.assertHTMLEqual( form6.as_ul(), '
  • \n
  • \n
  • \n
  • ' diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index f2409ed919b..e04c518a935 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -478,7 +478,7 @@ class ValidationTest(test.TestCase): def test_nullable_integerfield_cleans_none_on_null_and_blank_true(self): f = models.IntegerField(null=True, blank=True) - self.assertEqual(None, f.clean(None, None)) + self.assertIsNone(f.clean(None, None)) def test_integerfield_raises_error_on_empty_input(self): f = models.IntegerField(null=False) diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 9755155bb1a..f5ce93fd8d8 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -536,7 +536,7 @@ class QueryTestCase(TestCase): "ForeignKey.validate() uses the correct database" mickey = Person.objects.using('other').create(name="Mickey") pluto = Pet.objects.using('other').create(name="Pluto", owner=mickey) - self.assertEqual(None, pluto.full_clean()) + self.assertIsNone(pluto.full_clean()) def test_o2o_separation(self): "OneToOne fields are constrained to a single database" diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py index d11f09d1a36..32994c69525 100644 --- a/tests/postgres_tests/test_ranges.py +++ b/tests/postgres_tests/test_ranges.py @@ -83,7 +83,7 @@ class TestSaveLoad(TestCase): instance = RangesModel(ints=None) instance.save() loaded = RangesModel.objects.get() - self.assertEqual(None, loaded.ints) + self.assertIsNone(loaded.ints) @skipUnlessPG92 diff --git a/tests/validation/test_validators.py b/tests/validation/test_validators.py index c3875d46012..d06605eeca0 100644 --- a/tests/validation/test_validators.py +++ b/tests/validation/test_validators.py @@ -7,7 +7,7 @@ from .models import ModelToValidate class TestModelsWithValidators(ValidationTestCase): def test_custom_validator_passes_for_correct_value(self): mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=42) - self.assertEqual(None, mtv.full_clean()) + self.assertIsNone(mtv.full_clean()) def test_custom_validator_raises_error_for_incorrect_value(self): mtv = ModelToValidate(number=10, name='Some Name', f_with_custom_validator=12) diff --git a/tests/validation/tests.py b/tests/validation/tests.py index defd66edecf..693d6b6c233 100644 --- a/tests/validation/tests.py +++ b/tests/validation/tests.py @@ -19,7 +19,7 @@ class BaseModelValidationTests(ValidationTestCase): def test_with_correct_value_model_validates(self): mtv = ModelToValidate(number=10, name='Some Name') - self.assertEqual(None, mtv.full_clean()) + self.assertIsNone(mtv.full_clean()) def test_custom_validate_method(self): mtv = ModelToValidate(number=11) @@ -37,7 +37,7 @@ class BaseModelValidationTests(ValidationTestCase): def test_correct_FK_value_validates(self): parent = ModelToValidate.objects.create(number=10, name='Some Name') mtv = ModelToValidate(number=10, name='Some Name', parent_id=parent.pk) - self.assertEqual(None, mtv.full_clean()) + self.assertIsNone(mtv.full_clean()) def test_limited_FK_raises_error(self): # The limit_choices_to on the parent field says that a parent object's @@ -52,7 +52,7 @@ class BaseModelValidationTests(ValidationTestCase): def test_correct_email_value_passes(self): mtv = ModelToValidate(number=10, name='Some Name', email='valid@email.com') - self.assertEqual(None, mtv.full_clean()) + self.assertIsNone(mtv.full_clean()) def test_wrong_url_value_raises_error(self): mtv = ModelToValidate(number=10, name='Some Name', url='not a url')