/[thuban]/branches/WIP-pyshapelib-bramz/test/support.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/support.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 956 by bh, Wed May 21 17:11:17 2003 UTC revision 1421 by bh, Tue Jul 15 14:46:55 2003 UTC
# Line 21  def thuban_dir(): Line 21  def thuban_dir():
21      thisdir = os.path.dirname(__file__)      thisdir = os.path.dirname(__file__)
22      return os.path.join(thisdir, os.pardir)      return os.path.join(thisdir, os.pardir)
23    
24    def resource_dir():
25        return os.path.join(thuban_dir(), "Resources")
26    
27  def add_thuban_dir_to_path():  def add_thuban_dir_to_path():
28      """Insert the Thuban directory at the beginning of the python path.      """Insert the Thuban directory at the beginning of the python path.
# Line 58  def run_tests(): Line 60  def run_tests():
60          # This has to be in a finally clause because unittest.main()          # This has to be in a finally clause because unittest.main()
61          # ends with a sys.exit to make sure that the process exits with          # ends with a sys.exit to make sure that the process exits with
62          # an appropriate exit code          # an appropriate exit code
63          print_garbage_information()          print_additional_summary()
64    
65    def print_additional_summary():
66        """Print some additional summary information after tests have been run"""
67        print_garbage_information()
68        import xmlsupport
69        xmlsupport.print_summary_message()
70    
71  def print_garbage_information():  def print_garbage_information():
72      """Print information about things that haven't been cleaned up.      """Print information about things that haven't been cleaned up.
# Line 162  class FloatComparisonMixin: Line 170  class FloatComparisonMixin:
170      """      """
171    
172      fp_epsilon = 1e-6      fp_epsilon = 1e-6
173        fp_inf = float('1e1000')   # FIXME: hack for infinite
174            
175      def assertFloatEqual(self, test, value):      def assertFloatEqual(self, test, value, epsilon = None):
176          """Assert equality of test and value with some tolerance.          """Assert equality of test and value with some tolerance.
177    
178          Assert that the absolute difference between test and value is          Assert that the absolute difference between test and value is
179          less than self.fp_epsilon.          less than self.fp_epsilon.
180          """          """
181          self.assert_(self.fp_epsilon > abs(test - value),          if epsilon is None:
182                       "abs(%g - %g) >= %g" % (test, value, self.fp_epsilon))              epsilon = self.fp_epsilon
183            if abs(test) == self.fp_inf:
184                self.assertEqual(test, value)
185            else:
186                self.assert_(epsilon > abs(test - value),
187                         "abs(%g - %g) >= %g" % (test, value, epsilon))
188    
189      def assertFloatSeqEqual(self, test, value, epsilon = None):      def assertFloatSeqEqual(self, test, value, epsilon = None):
190          """Assert equality of the sequences test and value with some tolerance.          """Assert equality of the sequences test and value with some tolerance.
# Line 179  class FloatComparisonMixin: Line 193  class FloatComparisonMixin:
193          value in test and value is less than the optional parameter          value in test and value is less than the optional parameter
194          epsilon. If epsilon is not given use self.fp_epsilon.          epsilon. If epsilon is not given use self.fp_epsilon.
195          """          """
         if epsilon is None:  
             epsilon = self.fp_epsilon  
196          for i in range(len(test)):          for i in range(len(test)):
197              self.assert_(epsilon > abs(test[i] - value[i]),              self.assertFloatEqual(test[i], value[i], epsilon)
                          "abs(%g - %g) >= %g" % (test[i], value[i], epsilon))  
   
198    
199  class SubscriberMixin:  class SubscriberMixin:
200    
# Line 226  class SubscriberMixin: Line 236  class SubscriberMixin:
236          """Check whether the messages received match the list messages"""          """Check whether the messages received match the list messages"""
237          self.assertEquals(messages, self.received_messages)          self.assertEquals(messages, self.received_messages)
238    
 class FloatTestCase(unittest.TestCase):  
     """TestCase with methods for testing floating point values"""  
                                                                                                                                                           
     fp_epsilon = 1e-6  
     fp_inf = float('1e1000')   # FIXME: hack for infinite  
                                                                                                                                                           
     def assertFloatEqual(self, first, second, msg=None):  
         """Fail if one float is greater than the other + fp_epsilon"""  
         if abs(first) == self.fp_inf:  
             self.assertEqual(first, second, msg)  
         else:  
             self.assert_(self.fp_epsilon > abs(first - second), msg)  
   

Legend:
Removed from v.956  
changed lines
  Added in v.1421

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26