Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

root/branches/crazycache/dejavu/test/tools.py

Revision 96 (checked in by fumanchu, 6 years ago)

Lots of changes to the test suite. Partially fixes #23.

  • Property svn:eol-style set to native
Line 
1 import os
2 import sys
3 import textwrap
4 import time
5 import unittest
6
7 import warnings
8
9 def show_warn(message, category, filename, lineno, file=None):
10     """Hook to write a warning to a file; replace if you like."""
11     if file is None:
12         file = sys.stderr
13         try:
14             message = "%s: %s" % (category.__name__, message)
15             for line in textwrap.wrap(message):
16                 file.write("\n    ")
17                 file.write(line)
18             file.write("\n")
19         except IOError:
20             pass # the file (probably stderr) is invalid - this warning gets lost.
21     else:
22         try:
23             file.write(formatwarning(message, category, filename, lineno))
24         except IOError:
25             pass # the file (probably stderr) is invalid - this warning gets lost.
26
27 warnings.showwarning = show_warn
28
29
30 def prefer_parent_path():
31     # Place this __file__'s grandparent (../../) at the start of sys.path,
32     # so that all imports are from this __file__'s package.
33     localDir = os.path.dirname(__file__)
34     curpath = os.path.normpath(os.path.join(os.getcwd(), localDir))
35     grandparent = os.path.normpath(os.path.join(curpath, '../../'))
36     if grandparent not in sys.path:
37         sys.path.insert(0, grandparent)
38
39
40 class TerseTestResult(unittest._TextTestResult):
41    
42     def printErrors(self):
43         # Overridden to avoid unnecessary empty line
44         if self.errors or self.failures:
45             if self.dots or self.showAll:
46                 self.stream.writeln()
47             self.printErrorList('ERROR', self.errors)
48             self.printErrorList('FAIL', self.failures)
49
50
51 class TerseTestRunner(unittest.TextTestRunner):
52     """A test runner class that displays results in textual form."""
53    
54     def _makeResult(self):
55         return TerseTestResult(self.stream, self.descriptions, self.verbosity)
56    
57     def run(self, test):
58         "Run the given test case or test suite."
59         # Overridden to remove unnecessary empty lines and separators
60         result = self._makeResult()
61         startTime = time.time()
62         test(result)
63         timeTaken = float(time.time() - startTime)
64         result.printErrors()
65         if not result.wasSuccessful():
66             self.stream.write("FAILED (")
67             failed, errored = map(len, (result.failures, result.errors))
68             if failed:
69                 self.stream.write("failures=%d" % failed)
70             if errored:
71                 if failed: self.stream.write(", ")
72                 self.stream.write("errors=%d" % errored)
73             self.stream.writeln(")")
74         return result
75
76 djvTestRunner = TerseTestRunner(verbosity=2)
77
Note: See TracBrowser for help on using the browser.