/[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 324 by bh, Fri Sep 20 13:55:42 2002 UTC revision 904 by jonathan, Wed May 14 11:16:38 2003 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002 by Intevation GmbH  # Copyright (c) 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 46  def initthuban(): Line 46  def initthuban():
46          import thubaninit          import thubaninit
47          _initthuban_done = 1          _initthuban_done = 1
48    
49  def run_suite(suite):  def run_tests():
50      """Run the test suite suite and return the result"""      """Frontend for unittest.main that prints some additional debug information
51      runner = unittest.TextTestRunner(verbosity = 2)  
52      return runner.run(suite)      After calling unittest.main, run the garbage collector and print
53        uncollected objects. Also print any un-unsubscribed messages.
54        """
55        try:
56            unittest.main()
57        finally:
58            # This has to be in a finally clause because unittest.main()
59            # ends with a sys.exit to make sure that the process exits with
60            # an appropriate exit code
61            print_garbage_information()
62    
63    def print_garbage_information():
64        """Print information about things that haven't been cleaned up.
65    
66        Run the garbage collector and print uncollected objects. Also print
67        any un-unsubscribed messages.
68        """
69        import gc, Thuban.Lib.connector
70        gc.collect()
71        if gc.garbage:
72            print
73            print "There are %d uncollected objects:" % len(gc.garbage)
74            print gc.garbage
75        Thuban.Lib.connector._the_connector.print_connections()
76    
77    
78  def create_temp_dir():  def create_temp_dir():
# Line 102  class FloatComparisonMixin: Line 125  class FloatComparisonMixin:
125          Assert that the absolute difference between test and value is          Assert that the absolute difference between test and value is
126          less than self.fp_epsilon.          less than self.fp_epsilon.
127          """          """
128          return self.assert_(self.fp_epsilon > abs(test - value))          self.assert_(self.fp_epsilon > abs(test - value),
129                         "abs(%g - %g) >= %g" % (test, value, self.fp_epsilon))
130    
131      def assertFloatSeqEqual(self, test, value, epsilon = None):      def assertFloatSeqEqual(self, test, value, epsilon = None):
132          """Assert equality of the sequences test and value with some tolerance.          """Assert equality of the sequences test and value with some tolerance.
# Line 114  class FloatComparisonMixin: Line 138  class FloatComparisonMixin:
138          if epsilon is None:          if epsilon is None:
139              epsilon = self.fp_epsilon              epsilon = self.fp_epsilon
140          for i in range(len(test)):          for i in range(len(test)):
141              return self.assert_(epsilon > abs(test[i] - value[i]))              self.assert_(epsilon > abs(test[i] - value[i]),
142                             "abs(%g - %g) >= %g" % (test[i], value[i], epsilon))
143    
144    
145  class SubscriberMixin:  class SubscriberMixin:
# Line 156  class SubscriberMixin: Line 181  class SubscriberMixin:
181      def check_messages(self, messages):      def check_messages(self, messages):
182          """Check whether the messages received match the list messages"""          """Check whether the messages received match the list messages"""
183          self.assertEquals(messages, self.received_messages)          self.assertEquals(messages, self.received_messages)
184    
185    class FloatTestCase(unittest.TestCase):
186        """TestCase with methods for testing floating point values"""
187                                                                                                                                                            
188        fp_epsilon = 1e-6
189        fp_inf = float('1e1000')   # FIXME: hack for infinite
190                                                                                                                                                            
191        def assertFloatEqual(self, first, second, msg=None):
192            """Fail if one float is greater than the other + fp_epsilon"""
193            if abs(first) == self.fp_inf:
194                self.assertEqual(first, second, msg)
195            else:
196                self.assert_(self.fp_epsilon > abs(first - second), msg)
197    

Legend:
Removed from v.324  
changed lines
  Added in v.904

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26