/[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 1555 by bh, Thu Aug 7 15:41:05 2003 UTC revision 1673 by bh, Thu Aug 28 13:04:44 2003 UTC
# Line 15  __version__ = "$Revision$" Line 15  __version__ = "$Revision$"
15    
16  import os, sys  import os, sys
17  import unittest  import unittest
18    import traceback
19    
20    import postgissupport
21    
22    
23  def thuban_dir():  def thuban_dir():
24      """Return the directory containing the Thuban package"""      """Return the directory containing the Thuban package"""
# Line 98  class ThubanTestResult(unittest._TextTes Line 102  class ThubanTestResult(unittest._TextTes
102                  self.stream.writeln()                  self.stream.writeln()
103              self.stream.writeln("Skipped tests:")              self.stream.writeln("Skipped tests:")
104              for reason, tests in self.skipped_tests.items():              for reason, tests in self.skipped_tests.items():
105                  self.stream.writeln("%s:" % reason)                  self.stream.writeln("  %s:" % reason)
106                  for test in tests:                  for test in tests:
107                      self.stream.writeln("    " + test.id())                      self.stream.writeln("    " + test.id())
108          unittest._TextTestResult.printErrors(self)          unittest._TextTestResult.printErrors(self)
# Line 119  class ThubanTestProgram(unittest.TestPro Line 123  class ThubanTestProgram(unittest.TestPro
123    
124      def runTests(self):      def runTests(self):
125          """Extend inherited method so that we use a ThubanTestRunner"""          """Extend inherited method so that we use a ThubanTestRunner"""
         print "ThubanTestProgram.runTests"  
126          self.testRunner = ThubanTestRunner(verbosity = self.verbosity)          self.testRunner = ThubanTestRunner(verbosity = self.verbosity)
127          unittest.TestProgram.runTests(self)          unittest.TestProgram.runTests(self)
128    
129    
130  def run_tests():  def execute_as_testsuite(callable, *args, **kw):
131      """Frontend for unittest.main that prints some additional debug information      """Call callable  with args as if it were the entry point to the test suite
132    
133      After calling unittest.main, run the garbage collector and print      Return watever callable returns.
134      uncollected objects. Also print any un-unsubscribed messages.  
135        This is a helper function for run_tests and runtests.py. Call
136        callable in a try-finally block and run some cleanup and print some
137        additional information in the finally block.
138    
139        The additionaly information include:
140    
141         - A list of uncollected objects (after an explicit garbage
142           collector call)
143    
144         - any unsubscribed messages
145      """      """
146      try:      try:
147          ThubanTestProgram()          return callable(*args, **kw)
148      finally:      finally:
149          # This has to be in a finally clause because unittest.main()          # This has to be in a finally clause because unittest.main()
150          # 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
151          # an appropriate exit code          # an appropriate exit code
152    
153            # Shutdown the postgis server if it's running
154            try:
155                postgissupport.shutdown_test_server()
156            except:
157                traceback.print_exc()
158    
159            # Print additional information
160          print_additional_summary()          print_additional_summary()
161    
162    def run_tests():
163        """Frontend for unittest.main that prints some additional debug information
164    
165        After calling unittest.main, run the garbage collector and print
166        uncollected objects. Also print any un-unsubscribed messages.
167        """
168        execute_as_testsuite(ThubanTestProgram)
169    
170    
171  def print_additional_summary():  def print_additional_summary():
172      """Print some additional summary information after tests have been run"""      """Print some additional summary information after tests have been run"""
173      print_garbage_information()      print_garbage_information()
# Line 150  def print_garbage_information(): Line 180  def print_garbage_information():
180      Run the garbage collector and print uncollected objects. Also print      Run the garbage collector and print uncollected objects. Also print
181      any un-unsubscribed messages.      any un-unsubscribed messages.
182      """      """
183        # this function may be called indirectly from test cases that test
184        # test support modules which do not use anything from thuban itself,
185        # so we call initthuban so that we can import the connector module
186        initthuban()
187      import gc, Thuban.Lib.connector      import gc, Thuban.Lib.connector
188      gc.collect()      gc.collect()
189      if gc.garbage:      if gc.garbage:
# Line 248  class FloatComparisonMixin: Line 282  class FloatComparisonMixin:
282    
283      fp_epsilon = 1e-6      fp_epsilon = 1e-6
284      fp_inf = float('1e1000')   # FIXME: hack for infinite      fp_inf = float('1e1000')   # FIXME: hack for infinite
285        
286      def assertFloatEqual(self, test, value, epsilon = None):      def assertFloatEqual(self, test, value, epsilon = None):
287          """Assert equality of test and value with some tolerance.          """Assert equality of test and value with some tolerance.
288    
# Line 273  class FloatComparisonMixin: Line 307  class FloatComparisonMixin:
307          for i in range(len(test)):          for i in range(len(test)):
308              self.assertFloatEqual(test[i], value[i], epsilon)              self.assertFloatEqual(test[i], value[i], epsilon)
309    
310        def assertPointListEquals(self, test, value):
311            """Assert equality of two lists of lists of tuples of float
312    
313            This assertion is usually used to compare the geometry of shapes
314            as returned by a Shape object's Points() method, hence the name.
315            """
316            for i in range(len(test)):
317                self.assertEquals(len(test[i]), len(value[i]))
318                for j in range(len(test[i])):
319                    self.assertFloatSeqEqual(test[i][j], value[i][j])
320    
321    
322  class SubscriberMixin:  class SubscriberMixin:
323    
324      """Mixin class for tests for messages sent through the Connector      """Mixin class for tests for messages sent through the Connector

Legend:
Removed from v.1555  
changed lines
  Added in v.1673

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26