[Python-checkins] python/nondist/sandbox/decimal test_Decimal.py, 1.18, 1.19

facundobatista at users.sourceforge.net facundobatista at users.sourceforge.net
Thu Jun 24 21:30:51 EDT 2004


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

Modified Files:
	test_Decimal.py 
Log Message:
Tests to check near-immutable Decimal.

Index: test_Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/test_Decimal.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** test_Decimal.py	21 Jun 2004 21:52:52 -0000	1.18
--- test_Decimal.py	25 Jun 2004 01:30:49 -0000	1.19
***************
*** 15,18 ****
--- 15,19 ----
  """
  
+ # 0.2.1  2004.06.23  fb: Added immutability test for operations.
  # 0.2.0  2004.06.21  fb: Using the new test cases from Cowlishaw. Deprecated trim
  #                    test case and use of result in inexact test case. Added
***************
*** 1190,1220 ****
          self.assertEqual(d.as_tuple(), (0, (0,), 'F') )
  
! ##
! ##  As is impossible to make a real immutable instance in Python,
! ##  I'm delaying this feature to some future.  Facundo Batista 19-Jun-2004        
! ##
! ##    def test_immutability(self):
! ##        '''Try to change internal objects and see if immutable.'''
! ##
! ##        d = Decimal(42)
! ##
! ##        #the used attributes
! ##        try:
! ##            d._exp = 20
! ##            d._int = 3
! ##            d._sign = 1
! ##        except AttributeError:
! ##            pass
! ##        else:
! ##            self.fail('Did not raised an error!')
! ##
! ##        #some new attribute
! ##        try:
! ##            d.newone = None
! ##        except AttributeError:
! ##            pass
! ##        else:
! ##            self.fail('Did not raised an error!')
! ##
  
  
--- 1191,1292 ----
          self.assertEqual(d.as_tuple(), (0, (0,), 'F') )
  
!     def test_immutability_onpurpose(self):
!         '''Try to change internal objects and see if immutable.'''
! 
!         d = Decimal(42)
! 
!         #you can get the attributes...
!         d.exp
!         d.int
!         d.sign
! 
!         #...but not change them!
!         try:
!             d.exp = 20
!             d.int = 3
!             d.sign = 1
!         except AttributeError:
!             pass
!         else:
!             self.fail('Did not raised an error!')
! 
!         #some new attribute
!         try:
!             d.newone = None
!         except AttributeError:
!             pass
!         else:
!             self.fail('Did not raised an error!')
! 
!     def test_immutability_operations(self):
!         '''Do operations and check that it didn't change change internal objects.'''
! 
!         d1 = Decimal('-25e55')
!         b1 = Decimal('-25e55')
!         d2 = Decimal('33e-33')
!         b2 = Decimal('33e-33')
! 
!         def checkSameDec(operation, useOther=False):
!             if useOther:
!                 eval("d1." + operation + "(d2)")
!                 self.assertEqual(d1._sign, b1._sign)
!                 self.assertEqual(d1._int, b1._int)
!                 self.assertEqual(d1._exp, b1._exp)
!                 self.assertEqual(d2._sign, b2._sign)
!                 self.assertEqual(d2._int, b2._int)
!                 self.assertEqual(d2._exp, b2._exp)
!             else:
!                 eval("d1." + operation + "()")
!                 self.assertEqual(d1._sign, b1._sign)
!                 self.assertEqual(d1._int, b1._int)
!                 self.assertEqual(d1._exp, b1._exp)
!             return
! 
!         Decimal(d1)
!         self.assertEqual(d1._sign, b1._sign)
!         self.assertEqual(d1._int, b1._int)
!         self.assertEqual(d1._exp, b1._exp)
!         
!         checkSameDec("__abs__")
!         checkSameDec("__add__", True)
!         checkSameDec("__div__", True)
!         checkSameDec("__divmod__", True)
!         checkSameDec("__cmp__", True)
!         checkSameDec("__float__")
!         checkSameDec("__floordiv__", True)
!         checkSameDec("__hash__")
!         checkSameDec("__int__")
!         checkSameDec("__long__")
!         checkSameDec("__mod__", True)
!         checkSameDec("__mul__", True)
!         checkSameDec("__neg__")
!         checkSameDec("__nonzero__")
!         checkSameDec("__pos__")
!         checkSameDec("__pow__", True)
!         checkSameDec("__radd__", True)
!         checkSameDec("__rdiv__", True)
!         checkSameDec("__rdivmod__", True)
!         checkSameDec("__repr__")
!         checkSameDec("__rfloordiv__", True)
!         checkSameDec("__rmod__", True)
!         checkSameDec("__rmul__", True)
!         checkSameDec("__rpow__", True)
!         checkSameDec("__rsub__", True)
!         checkSameDec("__str__")
!         checkSameDec("__sub__", True)
!         checkSameDec("__truediv__", True)
!         checkSameDec("adjusted")
!         checkSameDec("as_tuple")
!         checkSameDec("compare", True)
!         checkSameDec("max", True)
!         checkSameDec("min", True)
!         checkSameDec("normalize")
!         checkSameDec("quantize", True)
!         checkSameDec("remainder_near", True)
!         checkSameDec("same_quantum", True)
!         checkSameDec("sqrt")
!         checkSameDec("to_eng_string")
!         checkSameDec("to_integral")
! 
  
  




More information about the Python-checkins mailing list