root/mail-onna-stick/trunk/bin/run-timed-unit-tests

Revision 310, 2.2 kB (checked in by t, 11 years ago)

changed avoid_slow.

  • Property svn:executable set to *
Line 
1 #! /usr/bin/env python
2 import _mypath
3 import sys, os
4 from cStringIO import StringIO
5
6 import mostest, unittest
7 import time, coverage_lib
8
9 ###
10
11 class _ExtendedTextTestResult(unittest._TextTestResult):
12     """
13     Replace the standard _TextTestResult display with one that can
14     do additional recording, timing, etc.
15     """
16    
17     def startTest(self, test):
18         unittest.TestResult.startTest(self, test)
19      
20         if self.showAll:
21             self.stream.write(self.getDescription(test))
22             self.stream.write(' ...  ')
23
24             self.start_time = time.time()
25
26     def addSuccess(self, test):
27         t = time.time()
28        
29         unittest.TestResult.addSuccess(self, test)
30        
31         if self.showAll:
32             timeTaken = float(t - self.start_time)
33             self.stream.writeln('ok (%.1f seconds)' % (timeTaken,))
34         elif self.dots:
35             self.stream.write('.')
36
37     def addError(self, test, err):
38         unittest.TestResult.addError(self, test, err)
39
40     def addFailure(self, test, err):
41         unittest.TestResult.addFailure(self, test, err)
42
43 class MyTextTestRunner(unittest.TextTestRunner):
44     def _makeResult(self):
45         return _ExtendedTextTestResult(self.stream,
46                                        self.descriptions,
47                                        self.verbosity)
48
49 ####
50
51 cwd = os.getcwd()
52
53 if len(sys.argv) == 2:
54     suite = mostest.collector(sys.argv[1], record_coverage=True,
55                               avoid_slow=False)
56 else:
57     suite = mostest.collector(record_coverage=True, avoid_slow=False)
58
59 t = MyTextTestRunner(verbosity=2)
60
61 result = t.run(suite)
62
63 assert result.wasSuccessful()
64
65 ###
66
67 mostest.stop_coverage()
68
69 # print coverage
70 t.stream.writeln('CWD is %s' % (os.getcwd(),))
71 os.chdir(cwd)
72 t.stream.write(mostest.report())
73
74 # save coverage
75 t.stream.writeln('saving coverage.\n')
76 coverage_lib.the_coverage.save(open('.coverage-timed', 'w'))
77
78 # report coverage
79 t.stream.writeln("\n(...reporting coverage to the billboard server...)\n")
80 try:
81     import mosweb, twill
82     twill.set_output(StringIO())
83     twill.commands.debug('http', '0')
84     mosweb.test_pages.TestPages().post_coverage('timed_unit_tests', 'summary')
85     twill.set_output(None)
86 except Exception, e:
87     t.stream.writeln(str(e))
88     raise
Note: See TracBrowser for help on using the browser.