summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_fields')
-rw-r--r--tests/model_fields/test_booleanfield.py34
-rw-r--r--tests/model_fields/test_decimalfield.py4
-rw-r--r--tests/model_fields/test_durationfield.py2
-rw-r--r--tests/model_fields/test_imagefield.py44
-rw-r--r--tests/model_fields/test_uuid.py2
-rw-r--r--tests/model_fields/tests.py6
6 files changed, 46 insertions, 46 deletions
diff --git a/tests/model_fields/test_booleanfield.py b/tests/model_fields/test_booleanfield.py
index 9c90bb5709..f61be4e28a 100644
--- a/tests/model_fields/test_booleanfield.py
+++ b/tests/model_fields/test_booleanfield.py
@@ -7,13 +7,13 @@ from .models import BooleanModel, FksToBooleans, NullBooleanModel
class BooleanFieldTests(TestCase):
def _test_get_prep_value(self, f):
- self.assertEqual(f.get_prep_value(True), True)
- self.assertEqual(f.get_prep_value('1'), True)
- self.assertEqual(f.get_prep_value(1), True)
- self.assertEqual(f.get_prep_value(False), False)
- self.assertEqual(f.get_prep_value('0'), False)
- self.assertEqual(f.get_prep_value(0), False)
- self.assertEqual(f.get_prep_value(None), None)
+ self.assertIs(f.get_prep_value(True), True)
+ self.assertIs(f.get_prep_value('1'), True)
+ self.assertIs(f.get_prep_value(1), True)
+ self.assertIs(f.get_prep_value(False), False)
+ self.assertIs(f.get_prep_value('0'), False)
+ self.assertIs(f.get_prep_value(0), False)
+ self.assertIsNone(f.get_prep_value(None))
def _test_to_python(self, f):
self.assertIs(f.to_python(1), True)
@@ -43,19 +43,19 @@ class BooleanFieldTests(TestCase):
def test_return_type(self):
b = BooleanModel.objects.create(bfield=True)
b.refresh_from_db()
- self.assertEqual(b.bfield, True)
+ self.assertIs(b.bfield, True)
b2 = BooleanModel.objects.create(bfield=False)
b2.refresh_from_db()
- self.assertEqual(b2.bfield, False)
+ self.assertIs(b2.bfield, False)
b3 = NullBooleanModel.objects.create(nbfield=True)
b3.refresh_from_db()
- self.assertEqual(b3.nbfield, True)
+ self.assertIs(b3.nbfield, True)
b4 = NullBooleanModel.objects.create(nbfield=False)
b4.refresh_from_db()
- self.assertEqual(b4.nbfield, False)
+ self.assertIs(b4.nbfield, False)
# When an extra clause exists, the boolean conversions are applied with
# an offset (#13293).
@@ -75,16 +75,16 @@ class BooleanFieldTests(TestCase):
# select_related('fk_field_name')
ma = FksToBooleans.objects.select_related('bf').get(pk=m1.id)
- self.assertEqual(ma.bf.bfield, True)
- self.assertEqual(ma.nbf.nbfield, True)
+ self.assertIs(ma.bf.bfield, True)
+ self.assertIs(ma.nbf.nbfield, True)
# select_related()
mb = FksToBooleans.objects.select_related().get(pk=m1.id)
mc = FksToBooleans.objects.select_related().get(pk=m2.id)
- self.assertEqual(mb.bf.bfield, True)
- self.assertEqual(mb.nbf.nbfield, True)
- self.assertEqual(mc.bf.bfield, False)
- self.assertEqual(mc.nbf.nbfield, False)
+ self.assertIs(mb.bf.bfield, True)
+ self.assertIs(mb.nbf.nbfield, True)
+ self.assertIs(mc.bf.bfield, False)
+ self.assertIs(mc.nbf.nbfield, False)
def test_null_default(self):
"""
diff --git a/tests/model_fields/test_decimalfield.py b/tests/model_fields/test_decimalfield.py
index 0414581816..8ba7562618 100644
--- a/tests/model_fields/test_decimalfield.py
+++ b/tests/model_fields/test_decimalfield.py
@@ -25,11 +25,11 @@ class DecimalFieldTests(TestCase):
f = models.DecimalField(max_digits=5, decimal_places=1)
self.assertEqual(f._format(f.to_python(2)), '2.0')
self.assertEqual(f._format(f.to_python('2.6')), '2.6')
- self.assertEqual(f._format(None), None)
+ self.assertIsNone(f._format(None))
def test_get_prep_value(self):
f = models.DecimalField(max_digits=5, decimal_places=1)
- self.assertEqual(f.get_prep_value(None), None)
+ self.assertIsNone(f.get_prep_value(None))
self.assertEqual(f.get_prep_value('2.4'), Decimal('2.4'))
def test_filter_with_strings(self):
diff --git a/tests/model_fields/test_durationfield.py b/tests/model_fields/test_durationfield.py
index 82c5c875bf..d39126a0ab 100644
--- a/tests/model_fields/test_durationfield.py
+++ b/tests/model_fields/test_durationfield.py
@@ -20,7 +20,7 @@ class TestSaveLoad(TestCase):
def test_create_empty(self):
NullDurationModel.objects.create()
loaded = NullDurationModel.objects.get()
- self.assertEqual(loaded.field, None)
+ self.assertIsNone(loaded.field)
def test_fractional_seconds(self):
value = datetime.timedelta(seconds=2.05)
diff --git a/tests/model_fields/test_imagefield.py b/tests/model_fields/test_imagefield.py
index 74926a5363..f9ae83b8b2 100644
--- a/tests/model_fields/test_imagefield.py
+++ b/tests/model_fields/test_imagefield.py
@@ -120,18 +120,18 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase):
p1.mugshot.save("mug", self.file1)
p2 = self.PersonModel(name="Bob")
p2.mugshot.save("mug", self.file2)
- self.assertEqual(p1.mugshot == p2.mugshot, False)
- self.assertEqual(p1.mugshot != p2.mugshot, True)
+ self.assertIs(p1.mugshot == p2.mugshot, False)
+ self.assertIs(p1.mugshot != p2.mugshot, True)
# Test again with an instance fetched from the db.
p1_db = self.PersonModel.objects.get(name="Joe")
- self.assertEqual(p1_db.mugshot == p2.mugshot, False)
- self.assertEqual(p1_db.mugshot != p2.mugshot, True)
+ self.assertIs(p1_db.mugshot == p2.mugshot, False)
+ self.assertIs(p1_db.mugshot != p2.mugshot, True)
# Instance from db should match the local instance.
- self.assertEqual(p1_db.mugshot == p1.mugshot, True)
+ self.assertIs(p1_db.mugshot == p1.mugshot, True)
self.assertEqual(hash(p1_db.mugshot), hash(p1.mugshot))
- self.assertEqual(p1_db.mugshot != p1.mugshot, False)
+ self.assertIs(p1_db.mugshot != p1.mugshot, False)
def test_instantiate_missing(self):
"""
@@ -165,11 +165,11 @@ class ImageFieldTests(ImageFieldTestMixin, TestCase):
# Get a "clean" model instance
p = self.PersonModel.objects.get(name="Joan")
# It won't have an opened file.
- self.assertEqual(p.mugshot.closed, True)
+ self.assertIs(p.mugshot.closed, True)
# After asking for the size, the file should still be closed.
p.mugshot.size
- self.assertEqual(p.mugshot.closed, True)
+ self.assertIs(p.mugshot.closed, True)
def test_pickle(self):
"""
@@ -213,7 +213,7 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
# attr_class, a TestImageFieldFile, with name == None, which will
# cause it to evaluate as False.
self.assertIsInstance(p.mugshot, TestImageFieldFile)
- self.assertEqual(bool(p.mugshot), False)
+ self.assertFalse(p.mugshot)
# Test setting a fresh created model instance.
p = self.PersonModel(name='Joe')
@@ -235,7 +235,7 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
"""
p = self.PersonModel()
self.assertIsInstance(p.mugshot, TestImageFieldFile)
- self.assertEqual(bool(p.mugshot), False)
+ self.assertFalse(p.mugshot)
def test_assignment_to_None(self):
"""
@@ -284,23 +284,23 @@ class ImageFieldTwoDimensionsTests(ImageFieldTestMixin, TestCase):
# Bug 11084: Dimensions should not get recalculated if file is
# coming from the database. We test this by checking if the file
# was opened.
- self.assertEqual(p.mugshot.was_opened, False)
+ self.assertIs(p.mugshot.was_opened, False)
self.check_dimensions(p, 4, 8)
# After checking dimensions on the image field, the file will have
# opened.
- self.assertEqual(p.mugshot.was_opened, True)
+ self.assertIs(p.mugshot.was_opened, True)
# Dimensions should now be cached, and if we reset was_opened and
# check dimensions again, the file should not have opened.
p.mugshot.was_opened = False
self.check_dimensions(p, 4, 8)
- self.assertEqual(p.mugshot.was_opened, False)
+ self.assertIs(p.mugshot.was_opened, False)
# If we assign a new image to the instance, the dimensions should
# update.
p.mugshot = self.file2
self.check_dimensions(p, 8, 4)
# Dimensions were recalculated, and hence file should have opened.
- self.assertEqual(p.mugshot.was_opened, True)
+ self.assertIs(p.mugshot.was_opened, True)
@skipIf(Image is None, "Pillow is required to test ImageField")
@@ -419,22 +419,22 @@ class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
# Bug 11084: Dimensions should not get recalculated if file is
# coming from the database. We test this by checking if the file
# was opened.
- self.assertEqual(p.mugshot.was_opened, False)
- self.assertEqual(p.headshot.was_opened, False)
+ self.assertIs(p.mugshot.was_opened, False)
+ self.assertIs(p.headshot.was_opened, False)
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
# After checking dimensions on the image fields, the files will
# have been opened.
- self.assertEqual(p.mugshot.was_opened, True)
- self.assertEqual(p.headshot.was_opened, True)
+ self.assertIs(p.mugshot.was_opened, True)
+ self.assertIs(p.headshot.was_opened, True)
# Dimensions should now be cached, and if we reset was_opened and
# check dimensions again, the file should not have opened.
p.mugshot.was_opened = False
p.headshot.was_opened = False
self.check_dimensions(p, 4, 8, 'mugshot')
self.check_dimensions(p, 8, 4, 'headshot')
- self.assertEqual(p.mugshot.was_opened, False)
- self.assertEqual(p.headshot.was_opened, False)
+ self.assertIs(p.mugshot.was_opened, False)
+ self.assertIs(p.headshot.was_opened, False)
# If we assign a new image to the instance, the dimensions should
# update.
@@ -443,5 +443,5 @@ class TwoImageFieldTests(ImageFieldTestMixin, TestCase):
self.check_dimensions(p, 8, 4, 'mugshot')
self.check_dimensions(p, 4, 8, 'headshot')
# Dimensions were recalculated, and hence file should have opened.
- self.assertEqual(p.mugshot.was_opened, True)
- self.assertEqual(p.headshot.was_opened, True)
+ self.assertIs(p.mugshot.was_opened, True)
+ self.assertIs(p.headshot.was_opened, True)
diff --git a/tests/model_fields/test_uuid.py b/tests/model_fields/test_uuid.py
index 050075444e..1c173e526d 100644
--- a/tests/model_fields/test_uuid.py
+++ b/tests/model_fields/test_uuid.py
@@ -37,7 +37,7 @@ class TestSaveLoad(TestCase):
def test_null_handling(self):
NullableUUIDModel.objects.create(field=None)
loaded = NullableUUIDModel.objects.get()
- self.assertEqual(loaded.field, None)
+ self.assertIsNone(loaded.field)
def test_pk_validated(self):
with self.assertRaisesMessage(TypeError, 'is not a valid UUID'):
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index 7b2e8f3aa7..85e2825165 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -70,7 +70,7 @@ class ChoicesTests(SimpleTestCase):
self.assertEqual(Whiz(c=1).get_c_display(), 'First') # A nested value
self.assertEqual(Whiz(c=0).get_c_display(), 'Other') # A top level value
self.assertEqual(Whiz(c=9).get_c_display(), 9) # Invalid value
- self.assertEqual(Whiz(c=None).get_c_display(), None) # Blank value
+ self.assertIsNone(Whiz(c=None).get_c_display()) # Blank value
self.assertEqual(Whiz(c='').get_c_display(), '') # Empty value
def test_iterator_choices(self):
@@ -79,7 +79,7 @@ class ChoicesTests(SimpleTestCase):
"""
self.assertEqual(WhizIter(c=1).c, 1) # A nested value
self.assertEqual(WhizIter(c=9).c, 9) # Invalid value
- self.assertEqual(WhizIter(c=None).c, None) # Blank value
+ self.assertIsNone(WhizIter(c=None).c) # Blank value
self.assertEqual(WhizIter(c='').c, '') # Empty value
def test_empty_iterator_choices(self):
@@ -88,5 +88,5 @@ class ChoicesTests(SimpleTestCase):
"""
self.assertEqual(WhizIterEmpty(c="a").c, "a") # A nested value
self.assertEqual(WhizIterEmpty(c="b").c, "b") # Invalid value
- self.assertEqual(WhizIterEmpty(c=None).c, None) # Blank value
+ self.assertIsNone(WhizIterEmpty(c=None).c) # Blank value
self.assertEqual(WhizIterEmpty(c='').c, '') # Empty value