[Python-checkins] python/nondist/sandbox/decimal test_Decimal.py, 1.16, 1.17

facundobatista at users.sourceforge.net facundobatista at users.sourceforge.net
Sat Jun 19 21:56:07 EDT 2004


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

Modified Files:
	test_Decimal.py 
Log Message:
Changes because of the attributes and methods name changes.

Index: test_Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/test_Decimal.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** test_Decimal.py	5 Apr 2004 22:08:41 -0000	1.16
--- test_Decimal.py	20 Jun 2004 01:56:04 -0000	1.17
***************
*** 15,18 ****
--- 15,21 ----
  """
  
+ # 0.1.8  2003.06.19  fb: Adjusted threading test case. Taken out the immutability
+ #                    test. Added tearDown method to DecimalTest class. Some fixes 
+ #                    because of the name changes.
  # 0.1.7  2003.04.05  fb: Adjusted several test cases. Eliminated interaction
  #                    with float in comparations and min/max test cases.
***************
*** 87,90 ****
--- 90,103 ----
                  'up' : ROUND_UP}
  
+ # Name adapter to be able to change the Decimal and Context
+ # interface without changing the test files from Cowlishaw 
+ nameAdapter = {'toeng':'to_eng_string',
+                'tosci':'to_sci_string',
+                'samequantum':'same_quantum',
+                'tointegral':'to_integral',
+                'remaindernear':'remainder_near',
+                'divideint':'divide_int',
+               }
+ 
  class DecimalTest(unittest.TestCase):
      """Class which tests the Decimal class against the test cases.
***************
*** 107,110 ****
--- 120,131 ----
                        'minexponent' : self.change_min_exponent,
                        'clamp' : self.change_clamp}
+ 
+     def tearDown(self):
+         """Cleaning up enviroment."""
+         # leaving context in original state
+         for key in DefaultContext.trap_enablers.keys():
+             DefaultContext.trap_enablers[key] = 0
+         return
+ 
      def eval_file(self, file):
          global skip_expected
***************
*** 177,180 ****
--- 198,202 ----
              val = val.replace('SingleQuote', "'").replace('DoubleQuote', '"')
              return val
+         funct = nameAdapter.get(funct, funct)
          fname = funct
          funct = getattr(self.context, funct)
***************
*** 200,204 ****
                  conglomerate = ''
              v = FixQuotes(val)
!             if fname in ('tosci', 'toeng'):
                  if EXTENDEDERRORTEST:
                      for error in theirexceptions:
--- 222,226 ----
                  conglomerate = ''
              v = FixQuotes(val)
!             if fname in ('to_sci_string', 'to_eng_string'):
                  if EXTENDEDERRORTEST:
                      for error in theirexceptions:
***************
*** 226,230 ****
          ans = FixQuotes(ans)
          
!         if EXTENDEDERRORTEST and fname not in ('tosci', 'toeng'):
              for error in theirexceptions:
                  self.context.trap_enablers[error] = 1
--- 248,252 ----
          ans = FixQuotes(ans)
          
!         if EXTENDEDERRORTEST and fname not in ('to_sci_string', 'to_eng_string'):
              for error in theirexceptions:
                  self.context.trap_enablers[error] = 1
***************
*** 241,245 ****
          try:
              result = str(funct(*vals))
!             if fname == 'samequantum':
                  result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
          except ExceptionList, error:
--- 263,267 ----
          try:
              result = str(funct(*vals))
!             if fname == 'same_quantum':
                  result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
          except ExceptionList, error:
***************
*** 935,940 ****
      d3 = Decimal(3)
      cls.assertEqual(d1/d3, Decimal('0.333333333'))
!     cls.event.wait()
      cls.assertEqual(d1/d3, Decimal('0.333333333'))
      return
  
--- 957,963 ----
      d3 = Decimal(3)
      cls.assertEqual(d1/d3, Decimal('0.333333333'))
!     cls.synchro.wait()
      cls.assertEqual(d1/d3, Decimal('0.333333333'))
+     cls.finish1.set()
      return
  
***************
*** 946,950 ****
      thiscontext.prec = 18
      cls.assertEqual(d1/d3, Decimal('0.333333333333333333'))
!     cls.event.set()
      return
  
--- 969,974 ----
      thiscontext.prec = 18
      cls.assertEqual(d1/d3, Decimal('0.333333333333333333'))
!     cls.synchro.set()
!     cls.finish2.set()
      return
  
***************
*** 960,964 ****
          '''Test the "threading isolation" of a Context.'''
          
!         self.event = threading.Event()
  
          th1 = threading.Thread(target=thfunc1, args=(self,))
--- 984,990 ----
          '''Test the "threading isolation" of a Context.'''
          
!         self.synchro = threading.Event()
!         self.finish1 = threading.Event()
!         self.finish2 = threading.Event()
  
          th1 = threading.Thread(target=thfunc1, args=(self,))
***************
*** 967,970 ****
--- 993,999 ----
          th1.start()
          th2.start()
+ 
+         self.finish1.wait()
+         self.finish1.wait()
          return
  
***************
*** 1039,1045 ****
          self.assertEqual(hash(Decimal(23)), hash(23))
  
-         #the same hash that a float
-         self.assertEqual(hash(Decimal('23.72')), hash(23.72))
-         
      def test_minmax_methods(self):
          '''Test min and max between Decimal and others.'''
--- 1068,1071 ----
***************
*** 1118,1145 ****
          d = Decimal( (1, (4, 3, 4, 9, 1, 3, 5, 3, 4), -25) )
          self.assertEqual(d, eval(repr(d)))
! 
!     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 TypeError:
!             pass
!         else:
!             self.fail('Did not raised an error!')
! 
!         #some new attribute
!         try:
!             d.newone = None
!         except TypeError:
!             pass
!         else:
!             self.fail('Did not raised an error!')
! 
  
  
--- 1144,1174 ----
          d = Decimal( (1, (4, 3, 4, 9, 1, 3, 5, 3, 4), -25) )
          self.assertEqual(d, eval(repr(d)))
! ##
! ##  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!')
! ##
  
  




More information about the Python-checkins mailing list