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/db_functions/math/test_round.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/db_functions') 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): -- cgit v1.3