/[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 1421 by bh, Tue Jul 15 14:46:55 2003 UTC revision 1555 by bh, Thu Aug 7 15:41:05 2003 UTC
# Line 48  def initthuban(): Line 48  def initthuban():
48          import thubaninit          import thubaninit
49          _initthuban_done = 1          _initthuban_done = 1
50    
51    
52    #
53    # Special test runner and result that support skipping tests
54    #
55    
56    class SkipTest(Exception):
57        """Exception to raise in tests that are skipped for some reason
58    
59        For instance, since gdal support is optional, test cases that
60        require gdal raise this exception to indicate that they are skipped.
61        Skipped is different from failure or error in that it is expected
62        under certain circumstances.
63        """
64    
65    class ThubanTestResult(unittest._TextTestResult):
66    
67        def __init__(self, stream, descriptions, verbosity):
68            unittest._TextTestResult.__init__(self, stream, descriptions,
69                                              verbosity)
70            self.skipped_tests = {}
71    
72        def add_skipped_test(self, test, exc):
73            reason = str(exc)
74            self.skipped_tests.setdefault(reason, []).append(test)
75    
76        def count_skipped(self):
77            sum = 0
78            for tests in self.skipped_tests.values():
79                sum += len(tests)
80            return sum
81    
82        def addError(self, test, err):
83            """Extend inherited method to handle SkipTest exceptions specially
84            """
85            #print "addError", test, err
86            if isinstance(err[1], SkipTest):
87                self.add_skipped_test(test, err[1])
88                if self.showAll:
89                    self.stream.writeln("skipped")
90                elif self.dots:
91                    self.stream.write('S')
92            else:
93                unittest._TextTestResult.addError(self, test, err)
94    
95        def printErrors(self):
96            if self.skipped_tests:
97                if self.dots or self.showAll:
98                    self.stream.writeln()
99                self.stream.writeln("Skipped tests:")
100                for reason, tests in self.skipped_tests.items():
101                    self.stream.writeln("%s:" % reason)
102                    for test in tests:
103                        self.stream.writeln("    " + test.id())
104            unittest._TextTestResult.printErrors(self)
105    
106    
107    class ThubanTestRunner(unittest.TextTestRunner):
108    
109        def _makeResult(self):
110            return ThubanTestResult(self.stream, self.descriptions, self.verbosity)
111    
112        def run(self, test):
113            result = unittest.TextTestRunner.run(self, test)
114            self.stream.writeln("skipped = %d" % result.count_skipped())
115            return result
116    
117    
118    class ThubanTestProgram(unittest.TestProgram):
119    
120        def runTests(self):
121            """Extend inherited method so that we use a ThubanTestRunner"""
122            print "ThubanTestProgram.runTests"
123            self.testRunner = ThubanTestRunner(verbosity = self.verbosity)
124            unittest.TestProgram.runTests(self)
125    
126    
127  def run_tests():  def run_tests():
128      """Frontend for unittest.main that prints some additional debug information      """Frontend for unittest.main that prints some additional debug information
129    
# Line 55  def run_tests(): Line 131  def run_tests():
131      uncollected objects. Also print any un-unsubscribed messages.      uncollected objects. Also print any un-unsubscribed messages.
132      """      """
133      try:      try:
134          unittest.main()          ThubanTestProgram()
135      finally:      finally:
136          # This has to be in a finally clause because unittest.main()          # This has to be in a finally clause because unittest.main()
137          # 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
# Line 82  def print_garbage_information(): Line 158  def print_garbage_information():
158          print gc.garbage          print gc.garbage
159      Thuban.Lib.connector._the_connector.print_connections()      Thuban.Lib.connector._the_connector.print_connections()
160    
161    #
162    
163  def create_temp_dir():  def create_temp_dir():
164      """Create a temporary directory and return its name.      """Create a temporary directory and return its name.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26