[Python-checkins] python/dist/src/Lib/test test_decimal.py,1.1,1.2

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat Jul 3 06:02:30 EDT 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11112/test

Modified Files:
	test_decimal.py 
Log Message:
Work through several open todos:
* Added test for pickling contexts
* Renamed ExceptionList to Signals (to match wording in the spec)
* Simplified Context constructor by allowing flags=None to automatically
  generate a zeroed-out flags dictionary.
* inlined _convertString() which was used only once
* _rounding_decision is private, so excluded its contants from __all__.
* added an XXX comment with concerns about subclassing signals results in
  a deviation from the spec (maybe important, maybe not).
* Taught the test_suite to determine its own directory (modeled after code
  in regrtest.py).  Enables it to be run when the current directory is not
  the test directory.
* Added a clear_flags() method to the Context API to make it easier to do
  a common operation with flags.
* Fixed the trap_enablers defaults in BasicDefaultContext to match the spec.



Index: test_decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_decimal.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_decimal.py	1 Jul 2004 11:01:32 -0000	1.1
--- test_decimal.py	3 Jul 2004 10:02:28 -0000	1.2
***************
*** 36,40 ****
  
  TESTDATADIR = 'decimaltestdata'
! dir = os.curdir + os.sep + TESTDATADIR + os.sep
  
  skip_expected = not os.path.isdir(dir)
--- 36,45 ----
  
  TESTDATADIR = 'decimaltestdata'
! if __name__ == '__main__':
!     file = sys.argv[0]
! else:
!     file = __file__
! testdir = os.path.dirname(file) or os.curdir
! dir = testdir + os.sep + TESTDATADIR + os.sep
  
  skip_expected = not os.path.isdir(dir)
***************
*** 191,195 ****
          theirexceptions = [ErrorNames[x.lower()] for x in exceptions]
  
!         for exception in ExceptionList:
              self.context.trap_enablers[exception] = 1 #Catch these bugs...
          for exception in theirexceptions:
--- 196,200 ----
          theirexceptions = [ErrorNames[x.lower()] for x in exceptions]
  
!         for exception in Signals:
              self.context.trap_enablers[exception] = 1 #Catch these bugs...
          for exception in theirexceptions:
***************
*** 213,217 ****
                          except error:
                              pass
!                         except ExceptionList, e:
                              self.fail("Raised %s in %s when %s disabled" % \
                                        (e, s, error))
--- 218,222 ----
                          except error:
                              pass
!                         except Signals, e:
                              self.fail("Raised %s in %s when %s disabled" % \
                                        (e, s, error))
***************
*** 233,237 ****
                  except error:
                      pass
!                 except ExceptionList, e:
                      self.fail("Raised %s in %s when %s disabled" % \
                                (e, s, error))
--- 238,242 ----
                  except error:
                      pass
!                 except Signals, e:
                      self.fail("Raised %s in %s when %s disabled" % \
                                (e, s, error))
***************
*** 243,247 ****
              if fname == 'same_quantum':
                  result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
!         except ExceptionList, error:
              self.fail("Raised %s in %s" % (error, s))
          except: #Catch any error long enough to state the test case.
--- 248,252 ----
              if fname == 'same_quantum':
                  result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
!         except Signals, error:
              self.fail("Raised %s in %s" % (error, s))
          except: #Catch any error long enough to state the test case.
***************
*** 264,268 ****
      def getexceptions(self):
          L = []
!         for exception in ExceptionList:
              if self.context.flags[exception]:
                  L.append(exception)
--- 269,273 ----
      def getexceptions(self):
          L = []
!         for exception in Signals:
              if self.context.flags[exception]:
                  L.append(exception)
***************
*** 270,274 ****
  
      def resetflags(self):
!         for exception in ExceptionList:
              self.context.flags[exception] = 0
  
--- 275,279 ----
  
      def resetflags(self):
!         for exception in Signals:
              self.context.flags[exception] = 0
  
***************
*** 1047,1050 ****
--- 1052,1065 ----
          self.assertEqual(d, e)
  
+ class ContextAPItests(unittest.TestCase):
+ 
+     def test_pickle(self):
+         c = Context()
+         e = pickle.loads(pickle.dumps(c))
+         for k in vars(c):
+             v1 = vars(c)[k]
+             v2 = vars(e)[k]
+             self.assertEqual(v1, v2)
+ 
  def test_main(arith=False, verbose=None):
      """ Execute the tests.
***************
*** 1060,1063 ****
--- 1075,1079 ----
          DecimalUsabilityTest,
          DecimalPythonAPItests,
+         ContextAPItests,
      ]
  




More information about the Python-checkins mailing list