[Python-checkins] python/nondist/sandbox/decimal test_Decimal.py, 1.24, 1.25

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Thu Jul 1 02:44:54 EDT 2004


Update of /cvsroot/python/python/nondist/sandbox/decimal
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18130

Modified Files:
	test_Decimal.py 
Log Message:
Test cleanup:  Use comments and informative test names instead of docstrings.



Index: test_Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/test_Decimal.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** test_Decimal.py	30 Jun 2004 07:19:21 -0000	1.24
--- test_Decimal.py	1 Jul 2004 06:44:52 -0000	1.25
***************
*** 31,35 ****
  import os, sys
  import pickle, copy
- 
  from Decimal import *
  from test.test_support import TestSkipped, run_unittest, run_doctest
--- 31,34 ----
***************
*** 367,380 ****
      '''Unit tests for Explicit Construction cases of Decimal.'''
  
!     def test_empty(self):
!         '''Explicit construction without parameters.'''
          self.assertEqual(Decimal(), Decimal("0"))
  
!     def test_from_None(self):
!         '''Explicit construction passing None as value.'''
          self.assertRaises(TypeError, Decimal, None)
  
!     def test_from_int(self):
!         '''Explicit construction with int or long.'''
  
          #positive
--- 366,376 ----
      '''Unit tests for Explicit Construction cases of Decimal.'''
  
!     def test_explicit_empty(self):
          self.assertEqual(Decimal(), Decimal("0"))
  
!     def test_explicit_from_None(self):
          self.assertRaises(TypeError, Decimal, None)
  
!     def test_explicit_from_int(self):
  
          #positive
***************
*** 394,398 ****
          self.assertEqual(str(d), '0')
  
!     def test_from_string(self):
          '''Explicit construction with string.'''
  
--- 390,394 ----
          self.assertEqual(str(d), '0')
  
!     def test_explicit_from_string(self):
          '''Explicit construction with string.'''
  
***************
*** 412,417 ****
          self.assertEqual(str(Decimal('ugly')), 'NaN')
  
!     def test_from_tuples(self):
!         '''Explicit construction with tuples.'''
  
          #zero
--- 408,412 ----
          self.assertEqual(str(Decimal('ugly')), 'NaN')
  
!     def test_explicit_from_tuples(self):
  
          #zero
***************
*** 444,449 ****
          self.assertRaises(ValueError, Decimal, (1, (4, -3, 4, 9, 1), 2) )
  
!     def test_from_Decimal(self):
!         '''Explicit construction with Decimal.'''
  
          #positive
--- 439,443 ----
          self.assertRaises(ValueError, Decimal, (1, (4, -3, 4, 9, 1), 2) )
  
!     def test_explicit_from_Decimal(self):
  
          #positive
***************
*** 471,476 ****
          self.assertNotEqual(id(d), id(e))
  
!     def test_context_create_decimal(self):
!         '''Explicit construction through context.create_decimal().'''
          nc = copy.copy(getcontext())
          nc.prec = 3
--- 465,470 ----
          self.assertNotEqual(id(d), id(e))
  
!     def test_explicit_context_create_decimal(self):
! 
          nc = copy.copy(getcontext())
          nc.prec = 3
***************
*** 511,543 ****
      '''Unit tests for Implicit Construction cases of Decimal.'''
  
!     def test_from_None(self):
!         '''Implicit construction with None.'''
! 
          self.assertRaises(TypeError, eval, 'Decimal(5) + None', globals())
  
!     def test_from_int(self):
!         '''Implicit construction with int or long.'''
! 
          #normal
          self.assertEqual(str(Decimal(5) + 45), '50')
- 
          #exceeding precision
          self.assertEqual(Decimal(5) + 123456789000, Decimal(123456789000))
  
!     def test_from_string(self):
!         '''Implicit construction with string.'''
! 
!         #just any string
          self.assertRaises(TypeError, eval, 'Decimal(5) + "3"', globals())
  
!     def test_from_float(self):
!         '''Implicit construction with float.'''
! 
!         #just any float
          self.assertRaises(TypeError, eval, 'Decimal(5) + 2.2', globals())
  
!     def test_from_Decimal(self):
!         '''Implicit construction with Decimal.'''
! 
          self.assertEqual(Decimal(5) + Decimal(45), Decimal(50))
  
--- 505,524 ----
      '''Unit tests for Implicit Construction cases of Decimal.'''
  
!     def test_implicit_from_None(self):
          self.assertRaises(TypeError, eval, 'Decimal(5) + None', globals())
  
!     def test_implicit_from_int(self):
          #normal
          self.assertEqual(str(Decimal(5) + 45), '50')
          #exceeding precision
          self.assertEqual(Decimal(5) + 123456789000, Decimal(123456789000))
  
!     def test_implicit_from_string(self):
          self.assertRaises(TypeError, eval, 'Decimal(5) + "3"', globals())
  
!     def test_implicit_from_float(self):
          self.assertRaises(TypeError, eval, 'Decimal(5) + 2.2', globals())
  
!     def test_implicit_from_Decimal(self):
          self.assertEqual(Decimal(5) + Decimal(45), Decimal(50))
  
***************
*** 547,551 ****
  
      def test_addition(self):
-         '''Test addition in all its ways.'''
  
          d1 = Decimal('-11.1')
--- 528,531 ----
***************
*** 575,579 ****
  
      def test_subtraction(self):
-         '''Test subtraction in all its ways.'''
  
          d1 = Decimal('-11.1')
--- 555,558 ----
***************
*** 603,607 ****
  
      def test_multiplication(self):
-         '''Test multiplication in all its ways.'''
  
          d1 = Decimal('-5')
--- 582,585 ----
***************
*** 631,635 ****
  
      def test_division(self):
-         '''Test division in all its ways.'''
  
          d1 = Decimal('-5')
--- 609,612 ----
***************
*** 715,719 ****
  
      def test_module(self):
-         '''Test module in all its ways.'''
  
          d1 = Decimal('5')
--- 692,695 ----
***************
*** 743,747 ****
  
      def test_floor_div_module(self):
-         '''Test floor division with module in all its ways.'''
  
          d1 = Decimal('5')
--- 719,722 ----
***************
*** 770,783 ****
  
      def test_unary_operators(self):
!         '''Testing -, +, abs.'''
! 
!         #test '+'
!         self.assertEqual(+Decimal(45), Decimal(+45))
! 
!         #test '-'
!         self.assertEqual(-Decimal(45), Decimal(-45))
! 
!         #test abs
!         self.assertEqual(abs(Decimal(45)), abs(Decimal(-45)))
  
  
--- 745,751 ----
  
      def test_unary_operators(self):
!         self.assertEqual(+Decimal(45), Decimal(+45))           #  +
!         self.assertEqual(-Decimal(45), Decimal(-45))           #  -
!         self.assertEqual(abs(Decimal(45)), abs(Decimal(-45)))  # abs
  
  
***************
*** 813,817 ****
  
      def test_threading(self):
!         '''Test the "threading isolation" of a Context.'''
  
          self.synchro = threading.Event()
--- 781,785 ----
  
      def test_threading(self):
!         #Test the "threading isolation" of a Context.
  
          self.synchro = threading.Event()
***************
*** 874,880 ****
          else: self.fail('Did not raised an error!')
  
!     def test_copy_methods(self):
!         '''Test copy and deepcopy.'''
! 
          d = Decimal('43.24')
          c = copy.copy(d)
--- 842,846 ----
          else: self.fail('Did not raised an error!')
  
!     def test_copy_and_deepcopy_methods(self):
          d = Decimal('43.24')
          c = copy.copy(d)
***************
*** 884,897 ****
  
      def test_hash_method(self):
-         '''Test hash.'''
- 
          #just that it's hashable
          hash(Decimal(23))
- 
          #the same hash that to an int
          self.assertEqual(hash(Decimal(23)), hash(23))
  
!     def test_minmax_methods(self):
!         '''Test min and max between Decimal and others.'''
  
          d1 = Decimal('15.32')
--- 850,859 ----
  
      def test_hash_method(self):
          #just that it's hashable
          hash(Decimal(23))
          #the same hash that to an int
          self.assertEqual(hash(Decimal(23)), hash(23))
  
!     def test_min_and_max_methods(self):
  
          d1 = Decimal('15.32')
***************
*** 912,937 ****
          self.failUnless(max(d2,l1) is d2)
  
!     def test_as_boolean(self):
!         '''Test that it can be used as boolean.'''
! 
          #as false
          self.failIf(Decimal(0))
- 
          #as true
          self.failUnless(Decimal('0.372'))
  
      def test_tostring_methods(self):
!         '''Test str and repr methods.'''
  
          d = Decimal('15.32')
! 
!         #str
!         self.assertEqual(str(d), '15.32')
! 
!         #repr
!         self.assertEqual(repr(d), 'Decimal("15.32")')
  
      def test_tonum_methods(self):
!         '''Test float, int and long methods.'''
  
          d1 = Decimal('66')
--- 874,892 ----
          self.failUnless(max(d2,l1) is d2)
  
!     def test_as_nonzero(self):
          #as false
          self.failIf(Decimal(0))
          #as true
          self.failUnless(Decimal('0.372'))
  
      def test_tostring_methods(self):
!         #Test str and repr methods.
  
          d = Decimal('15.32')
!         self.assertEqual(str(d), '15.32')               # str
!         self.assertEqual(repr(d), 'Decimal("15.32")')   # repr
  
      def test_tonum_methods(self):
!         #Test float, int and long methods.
  
          d1 = Decimal('66')
***************
*** 950,955 ****
          self.assertEqual(float(d2), 15.32)
  
!     def test_round_trip(self):
!         '''Testing that d == eval(repr(d)) with d as Decimal.'''
  
          #with zero
--- 905,909 ----
          self.assertEqual(float(d2), 15.32)
  
!     def test_eval_round_trip(self):
  
          #with zero
***************
*** 970,974 ****
  
      def test_as_tuple(self):
-         '''Test as_tuple to show the internals.'''
  
          #with zero
--- 924,927 ----
***************
*** 989,993 ****
  
      def test_immutability_onpurpose(self):
!         '''Try to change internal objects and see if immutable.'''
  
          d = Decimal(42)
--- 942,946 ----
  
      def test_immutability_onpurpose(self):
!         #Try to change internal objects and see if immutable.
  
          d = Decimal(42)
***************
*** 1017,1021 ****
  
      def test_immutability_operations(self):
!         '''Do operations and check that it didn't change change internal objects.'''
  
          d1 = Decimal('-25e55')
--- 970,974 ----
  
      def test_immutability_operations(self):
!         # Do operations and check that it didn't change change internal objects.
  
          d1 = Decimal('-25e55')




More information about the Python-checkins mailing list