diff options
author | Nick Pope <nick.pope@flightdataservices.com> | 2019-10-21 09:55:05 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-29 12:37:30 +0100 |
commit | 7552de7866dcd270a0f353b007b4aceaa7f3ff3e (patch) | |
tree | 2e84292833853d9659671ed304cb32d5acef5f90 /tests/db_functions | |
parent | a6cb8ec3895a72bfb7f8e62d4b05dd5de6b738af (diff) | |
download | django-7552de7866dcd270a0f353b007b4aceaa7f3ff3e.tar.gz |
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.
Diffstat (limited to 'tests/db_functions')
-rw-r--r-- | tests/db_functions/math/test_round.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/tests/db_functions/math/test_round.py b/tests/db_functions/math/test_round.py index a3770f1f52..50345d4b5c 100644 --- a/tests/db_functions/math/test_round.py +++ b/tests/db_functions/math/test_round.py @@ -20,16 +20,16 @@ class RoundTests(TestCase): obj = DecimalModel.objects.annotate(n1_round=Round('n1'), n2_round=Round('n2')).first() self.assertIsInstance(obj.n1_round, Decimal) self.assertIsInstance(obj.n2_round, Decimal) - self.assertAlmostEqual(obj.n1_round, round(obj.n1)) - self.assertAlmostEqual(obj.n2_round, round(obj.n2)) + self.assertAlmostEqual(obj.n1_round, obj.n1, places=0) + self.assertAlmostEqual(obj.n2_round, obj.n2, places=0) def test_float(self): FloatModel.objects.create(f1=-27.55, f2=0.55) obj = FloatModel.objects.annotate(f1_round=Round('f1'), f2_round=Round('f2')).first() self.assertIsInstance(obj.f1_round, float) self.assertIsInstance(obj.f2_round, float) - self.assertAlmostEqual(obj.f1_round, round(obj.f1)) - self.assertAlmostEqual(obj.f2_round, round(obj.f2)) + self.assertAlmostEqual(obj.f1_round, obj.f1, places=0) + self.assertAlmostEqual(obj.f2_round, obj.f2, places=0) def test_integer(self): IntegerModel.objects.create(small=-20, normal=15, big=-1) @@ -41,9 +41,9 @@ class RoundTests(TestCase): self.assertIsInstance(obj.small_round, int) self.assertIsInstance(obj.normal_round, int) self.assertIsInstance(obj.big_round, int) - self.assertEqual(obj.small_round, round(obj.small)) - self.assertEqual(obj.normal_round, round(obj.normal)) - self.assertEqual(obj.big_round, round(obj.big)) + self.assertAlmostEqual(obj.small_round, obj.small, places=0) + self.assertAlmostEqual(obj.normal_round, obj.normal, places=0) + self.assertAlmostEqual(obj.big_round, obj.big, places=0) def test_transform(self): with register_lookup(DecimalField, Round): |