[Python-checkins] r79678 - python/trunk/Lib/test/test_decimal.py

ezio.melotti python-checkins at python.org
Sat Apr 3 16:51:00 CEST 2010


Author: ezio.melotti
Date: Sat Apr  3 16:51:00 2010
New Revision: 79678

Log:
Use more specific assert* methods in test_decimal.

Modified:
   python/trunk/Lib/test/test_decimal.py

Modified: python/trunk/Lib/test/test_decimal.py
==============================================================================
--- python/trunk/Lib/test/test_decimal.py	(original)
+++ python/trunk/Lib/test/test_decimal.py	Sat Apr  3 16:51:00 2010
@@ -1235,22 +1235,22 @@
         dc = Decimal('45')
 
         #two Decimals
-        self.assertTrue(dc > da)
-        self.assertTrue(dc >= da)
-        self.assertTrue(da < dc)
-        self.assertTrue(da <= dc)
-        self.assertTrue(da == db)
-        self.assertTrue(da != dc)
-        self.assertTrue(da <= db)
-        self.assertTrue(da >= db)
+        self.assertGreater(dc, da)
+        self.assertGreaterEqual(dc, da)
+        self.assertLess(da, dc)
+        self.assertLessEqual(da, dc)
+        self.assertEqual(da, db)
+        self.assertNotEqual(da, dc)
+        self.assertLessEqual(da, db)
+        self.assertGreaterEqual(da, db)
         self.assertEqual(cmp(dc,da), 1)
         self.assertEqual(cmp(da,dc), -1)
         self.assertEqual(cmp(da,db), 0)
 
         #a Decimal and an int
-        self.assertTrue(dc > 23)
-        self.assertTrue(23 < dc)
-        self.assertTrue(dc == 45)
+        self.assertGreater(dc, 23)
+        self.assertLess(23, dc)
+        self.assertEqual(dc, 45)
         self.assertEqual(cmp(dc,23), 1)
         self.assertEqual(cmp(23,dc), -1)
         self.assertEqual(cmp(dc,45), 0)
@@ -1276,19 +1276,19 @@
     def test_decimal_float_comparison(self):
         da = Decimal('0.25')
         db = Decimal('3.0')
-        self.assert_(da < 3.0)
-        self.assert_(da <= 3.0)
-        self.assert_(db > 0.25)
-        self.assert_(db >= 0.25)
-        self.assert_(da != 1.5)
-        self.assert_(da == 0.25)
-        self.assert_(3.0 > da)
-        self.assert_(3.0 >= da)
-        self.assert_(0.25 < db)
-        self.assert_(0.25 <= db)
-        self.assert_(0.25 != db)
-        self.assert_(3.0 == db)
-        self.assert_(0.1 != Decimal('0.1'))
+        self.assertLess(da, 3.0)
+        self.assertLessEqual(da, 3.0)
+        self.assertGreater(db, 0.25)
+        self.assertGreaterEqual(db, 0.25)
+        self.assertNotEqual(da, 1.5)
+        self.assertEqual(da, 0.25)
+        self.assertGreater(3.0, da)
+        self.assertGreaterEqual(3.0, da)
+        self.assertLess(0.25, db)
+        self.assertLessEqual(0.25, db)
+        self.assertNotEqual(0.25, db)
+        self.assertEqual(3.0, db)
+        self.assertNotEqual(0.1, Decimal('0.1'))
 
     def test_copy_and_deepcopy_methods(self):
         d = Decimal('43.24')
@@ -1376,16 +1376,16 @@
         l2 = 28
 
         #between Decimals
-        self.assertTrue(min(d1,d2) is d1)
-        self.assertTrue(min(d2,d1) is d1)
-        self.assertTrue(max(d1,d2) is d2)
-        self.assertTrue(max(d2,d1) is d2)
+        self.assertIs(min(d1,d2), d1)
+        self.assertIs(min(d2,d1), d1)
+        self.assertIs(max(d1,d2), d2)
+        self.assertIs(max(d2,d1), d2)
 
         #between Decimal and long
-        self.assertTrue(min(d1,l2) is d1)
-        self.assertTrue(min(l2,d1) is d1)
-        self.assertTrue(max(l1,d2) is d2)
-        self.assertTrue(max(d2,l1) is d2)
+        self.assertIs(min(d1,l2), d1)
+        self.assertIs(min(l2,d1), d1)
+        self.assertIs(max(l1,d2), d2)
+        self.assertIs(max(d2,l1), d2)
 
     def test_as_nonzero(self):
         #as false
@@ -1571,10 +1571,10 @@
         d1 = MyDecimal(1)
         d2 = MyDecimal(2)
         d = d1 + d2
-        self.assertTrue(type(d) is Decimal)
+        self.assertIs(type(d), Decimal)
 
         d = d1.max(d2)
-        self.assertTrue(type(d) is Decimal)
+        self.assertIs(type(d), Decimal)
 
     def test_implicit_context(self):
         # Check results when context given implicitly.  (Issue 2478)
@@ -1634,9 +1634,9 @@
 
     def test_abc(self):
         self.assertTrue(issubclass(Decimal, numbers.Number))
-        self.assertTrue(not issubclass(Decimal, numbers.Real))
+        self.assertFalse(issubclass(Decimal, numbers.Real))
         self.assertIsInstance(Decimal(0), numbers.Number)
-        self.assertTrue(not isinstance(Decimal(0), numbers.Real))
+        self.assertNotIsInstance(Decimal(0), numbers.Real)
 
     def test_pickle(self):
         d = Decimal('-3.141590000')
@@ -2187,9 +2187,9 @@
         with localcontext() as enter_ctx:
             set_ctx = getcontext()
         final_ctx = getcontext()
-        self.assertTrue(orig_ctx is final_ctx, 'did not restore context correctly')
-        self.assertTrue(orig_ctx is not set_ctx, 'did not copy the context')
-        self.assertTrue(set_ctx is enter_ctx, '__enter__ returned wrong context')
+        self.assertIs(orig_ctx, final_ctx, 'did not restore context correctly')
+        self.assertIsNot(orig_ctx, set_ctx, 'did not copy the context')
+        self.assertIs(set_ctx, enter_ctx, '__enter__ returned wrong context')
 
     def test_localcontextarg(self):
         # Use a copy of the supplied context in the block
@@ -2198,10 +2198,10 @@
         with localcontext(new_ctx) as enter_ctx:
             set_ctx = getcontext()
         final_ctx = getcontext()
-        self.assertTrue(orig_ctx is final_ctx, 'did not restore context correctly')
-        self.assertTrue(set_ctx.prec == new_ctx.prec, 'did not set correct context')
-        self.assertTrue(new_ctx is not set_ctx, 'did not copy the context')
-        self.assertTrue(set_ctx is enter_ctx, '__enter__ returned wrong context')
+        self.assertIs(orig_ctx, final_ctx, 'did not restore context correctly')
+        self.assertEqual(set_ctx.prec, new_ctx.prec, 'did not set correct context')
+        self.assertIsNot(new_ctx, set_ctx, 'did not copy the context')
+        self.assertIs(set_ctx, enter_ctx, '__enter__ returned wrong context')
 
 class ContextFlags(unittest.TestCase):
     def test_flags_irrelevant(self):


More information about the Python-checkins mailing list