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""" |
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) |
128 |
unittest.TestProgram.runTests(self) |
unittest.TestProgram.runTests(self) |
129 |
|
|
130 |
|
|
131 |
def run_tests(): |
def execute_as_testsuite(callable, *args, **kw): |
132 |
"""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 |
133 |
|
|
134 |
After calling unittest.main, run the garbage collector and print |
Return watever callable returns. |
135 |
uncollected objects. Also print any un-unsubscribed messages. |
|
136 |
|
This is a helper function for run_tests and runtests.py. Call |
137 |
|
callable in a try-finally block and run some cleanup and print some |
138 |
|
additional information in the finally block. |
139 |
|
|
140 |
|
The additionaly information include: |
141 |
|
|
142 |
|
- A list of uncollected objects (after an explicit garbage |
143 |
|
collector call) |
144 |
|
|
145 |
|
- any unsubscribed messages |
146 |
""" |
""" |
147 |
try: |
try: |
148 |
ThubanTestProgram() |
return callable(*args, **kw) |
149 |
finally: |
finally: |
150 |
# This has to be in a finally clause because unittest.main() |
# This has to be in a finally clause because unittest.main() |
151 |
# 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 |
152 |
# an appropriate exit code |
# an appropriate exit code |
153 |
|
|
154 |
|
# Shutdown the postgis server if it's running |
155 |
|
try: |
156 |
|
postgissupport.shutdown_test_server() |
157 |
|
except: |
158 |
|
traceback.print_exc() |
159 |
|
|
160 |
|
# Print additional information |
161 |
print_additional_summary() |
print_additional_summary() |
162 |
|
|
163 |
|
def run_tests(): |
164 |
|
"""Frontend for unittest.main that prints some additional debug information |
165 |
|
|
166 |
|
After calling unittest.main, run the garbage collector and print |
167 |
|
uncollected objects. Also print any un-unsubscribed messages. |
168 |
|
""" |
169 |
|
execute_as_testsuite(ThubanTestProgram) |
170 |
|
|
171 |
|
|
172 |
def print_additional_summary(): |
def print_additional_summary(): |
173 |
"""Print some additional summary information after tests have been run""" |
"""Print some additional summary information after tests have been run""" |
174 |
print_garbage_information() |
print_garbage_information() |
279 |
|
|
280 |
fp_epsilon = 1e-6 |
fp_epsilon = 1e-6 |
281 |
fp_inf = float('1e1000') # FIXME: hack for infinite |
fp_inf = float('1e1000') # FIXME: hack for infinite |
282 |
|
|
283 |
def assertFloatEqual(self, test, value, epsilon = None): |
def assertFloatEqual(self, test, value, epsilon = None): |
284 |
"""Assert equality of test and value with some tolerance. |
"""Assert equality of test and value with some tolerance. |
285 |
|
|
304 |
for i in range(len(test)): |
for i in range(len(test)): |
305 |
self.assertFloatEqual(test[i], value[i], epsilon) |
self.assertFloatEqual(test[i], value[i], epsilon) |
306 |
|
|
307 |
|
def assertPointListEquals(self, test, value): |
308 |
|
"""Assert equality of two lists of lists of tuples of float |
309 |
|
|
310 |
|
This assertion is usually used to compare the geometry of shapes |
311 |
|
as returned by a Shape object's Points() method, hence the name. |
312 |
|
""" |
313 |
|
for i in range(len(test)): |
314 |
|
self.assertEquals(len(test[i]), len(value[i])) |
315 |
|
for j in range(len(test[i])): |
316 |
|
self.assertFloatSeqEqual(test[i][j], value[i][j]) |
317 |
|
|
318 |
|
|
319 |
class SubscriberMixin: |
class SubscriberMixin: |
320 |
|
|
321 |
"""Mixin class for tests for messages sent through the Connector |
"""Mixin class for tests for messages sent through the Connector |