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""" |
48 |
""" |
""" |
49 |
global _initthuban_done |
global _initthuban_done |
50 |
if not _initthuban_done: |
if not _initthuban_done: |
51 |
|
# Thuban uses gettext to translate some strings. Some of these |
52 |
|
# strings are tested for equality in some test cases. So we |
53 |
|
# unset any LANG environment setting to make sure only the |
54 |
|
# untranslated messages are used. |
55 |
|
try: |
56 |
|
del os.environ["LANG"] |
57 |
|
except KeyError: |
58 |
|
pass |
59 |
add_thuban_dir_to_path() |
add_thuban_dir_to_path() |
60 |
import thubaninit |
import thubaninit |
61 |
_initthuban_done = 1 |
_initthuban_done = 1 |
110 |
self.stream.writeln() |
self.stream.writeln() |
111 |
self.stream.writeln("Skipped tests:") |
self.stream.writeln("Skipped tests:") |
112 |
for reason, tests in self.skipped_tests.items(): |
for reason, tests in self.skipped_tests.items(): |
113 |
self.stream.writeln("%s:" % reason) |
self.stream.writeln(" %s:" % reason) |
114 |
for test in tests: |
for test in tests: |
115 |
self.stream.writeln(" " + test.id()) |
self.stream.writeln(" " + test.id()) |
116 |
unittest._TextTestResult.printErrors(self) |
unittest._TextTestResult.printErrors(self) |
117 |
|
|
118 |
|
def getDescription(self, test): |
119 |
|
return test.id() |
120 |
|
|
121 |
|
|
122 |
class ThubanTestRunner(unittest.TextTestRunner): |
class ThubanTestRunner(unittest.TextTestRunner): |
123 |
|
|
134 |
|
|
135 |
def runTests(self): |
def runTests(self): |
136 |
"""Extend inherited method so that we use a ThubanTestRunner""" |
"""Extend inherited method so that we use a ThubanTestRunner""" |
|
print "ThubanTestProgram.runTests" |
|
137 |
self.testRunner = ThubanTestRunner(verbosity = self.verbosity) |
self.testRunner = ThubanTestRunner(verbosity = self.verbosity) |
138 |
unittest.TestProgram.runTests(self) |
unittest.TestProgram.runTests(self) |
139 |
|
|
140 |
|
|
141 |
def run_tests(): |
def execute_as_testsuite(callable, *args, **kw): |
142 |
"""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 |
143 |
|
|
144 |
After calling unittest.main, run the garbage collector and print |
Return watever callable returns. |
145 |
uncollected objects. Also print any un-unsubscribed messages. |
|
146 |
|
This is a helper function for run_tests and runtests.py. Call |
147 |
|
callable in a try-finally block and run some cleanup and print some |
148 |
|
additional information in the finally block. |
149 |
|
|
150 |
|
The additionaly information include: |
151 |
|
|
152 |
|
- A list of uncollected objects (after an explicit garbage |
153 |
|
collector call) |
154 |
|
|
155 |
|
- any unsubscribed messages |
156 |
""" |
""" |
157 |
try: |
try: |
158 |
ThubanTestProgram() |
return callable(*args, **kw) |
159 |
finally: |
finally: |
160 |
# This has to be in a finally clause because unittest.main() |
# This has to be in a finally clause because unittest.main() |
161 |
# 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 |
162 |
# an appropriate exit code |
# an appropriate exit code |
163 |
|
|
164 |
|
# Shutdown the postgis server if it's running |
165 |
|
try: |
166 |
|
postgissupport.shutdown_test_server() |
167 |
|
except: |
168 |
|
traceback.print_exc() |
169 |
|
|
170 |
|
# Print additional information |
171 |
print_additional_summary() |
print_additional_summary() |
172 |
|
|
173 |
|
def run_tests(): |
174 |
|
"""Frontend for unittest.main that prints some additional debug information |
175 |
|
|
176 |
|
After calling unittest.main, run the garbage collector and print |
177 |
|
uncollected objects. Also print any un-unsubscribed messages. |
178 |
|
""" |
179 |
|
execute_as_testsuite(ThubanTestProgram) |
180 |
|
|
181 |
|
|
182 |
def print_additional_summary(): |
def print_additional_summary(): |
183 |
"""Print some additional summary information after tests have been run""" |
"""Print some additional summary information after tests have been run""" |
184 |
print_garbage_information() |
print_garbage_information() |
191 |
Run the garbage collector and print uncollected objects. Also print |
Run the garbage collector and print uncollected objects. Also print |
192 |
any un-unsubscribed messages. |
any un-unsubscribed messages. |
193 |
""" |
""" |
194 |
|
# this function may be called indirectly from test cases that test |
195 |
|
# test support modules which do not use anything from thuban itself, |
196 |
|
# so we call initthuban so that we can import the connector module |
197 |
|
initthuban() |
198 |
import gc, Thuban.Lib.connector |
import gc, Thuban.Lib.connector |
199 |
gc.collect() |
gc.collect() |
200 |
if gc.garbage: |
if gc.garbage: |
293 |
|
|
294 |
fp_epsilon = 1e-6 |
fp_epsilon = 1e-6 |
295 |
fp_inf = float('1e1000') # FIXME: hack for infinite |
fp_inf = float('1e1000') # FIXME: hack for infinite |
296 |
|
|
297 |
def assertFloatEqual(self, test, value, epsilon = None): |
def assertFloatEqual(self, test, value, epsilon = None): |
298 |
"""Assert equality of test and value with some tolerance. |
"""Assert equality of test and value with some tolerance. |
299 |
|
|
315 |
value in test and value is less than the optional parameter |
value in test and value is less than the optional parameter |
316 |
epsilon. If epsilon is not given use self.fp_epsilon. |
epsilon. If epsilon is not given use self.fp_epsilon. |
317 |
""" |
""" |
318 |
|
self.assertEquals(len(test), len(value)) |
319 |
for i in range(len(test)): |
for i in range(len(test)): |
320 |
self.assertFloatEqual(test[i], value[i], epsilon) |
self.assertFloatEqual(test[i], value[i], epsilon) |
321 |
|
|
322 |
|
def assertPointListEquals(self, test, value): |
323 |
|
"""Assert equality of two lists of lists of tuples of float |
324 |
|
|
325 |
|
This assertion is usually used to compare the geometry of shapes |
326 |
|
as returned by a Shape object's Points() method, hence the name. |
327 |
|
""" |
328 |
|
for i in range(len(test)): |
329 |
|
self.assertEquals(len(test[i]), len(value[i])) |
330 |
|
for j in range(len(test[i])): |
331 |
|
self.assertFloatSeqEqual(test[i][j], value[i][j]) |
332 |
|
|
333 |
|
|
334 |
class SubscriberMixin: |
class SubscriberMixin: |
335 |
|
|
336 |
"""Mixin class for tests for messages sent through the Connector |
"""Mixin class for tests for messages sent through the Connector |