Mercurial > lcfOS
annotate doc/unittesttable.py @ 370:f86e79246602
Remove null stdio
author | Windel Bouwman |
---|---|
date | Fri, 21 Mar 2014 11:57:32 +0100 |
parents | 0bb16d2a5699 |
children |
rev | line source |
---|---|
328
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
1 from docutils import nodes |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
2 from sphinx.util.compat import Directive |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
3 import unittest |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
4 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
5 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
6 class RecordingTestResult(unittest.TestResult): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
7 def __init__(self): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
8 super().__init__() |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
9 self.successfull_tests = [] |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
10 self.failed_tests = [] |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
11 self.skipped_tests = [] |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
12 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
13 def addSuccess(self, tst): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
14 super().addSuccess(tst) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
15 self.successfull_tests.append(tst) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
16 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
17 def addFailure(self, tst, err): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
18 super().addFailure(tst, err) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
19 self.failed_tests.append(tst) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
20 def addError(self, tst, err): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
21 super().addError(tst, err) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
22 self.failed_tests.append(tst) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
23 def addSkip(self, tst, reason): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
24 super().addSkip(tst, reason) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
25 self.skipped_tests.append(tst) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
26 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
27 def makeTable(rows): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
28 # Buildup table: |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
29 table = nodes.table() |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
30 group = nodes.tgroup() |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
31 group += nodes.colspec('', colwidth=100) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
32 group += nodes.colspec('', colwidth=50) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
33 table += group |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
34 tbody = nodes.tbody('') |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
35 group += tbody |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
36 for c1, c2 in rows: |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
37 row = nodes.row('') |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
38 row += nodes.entry('', nodes.paragraph('', c1)) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
39 row += nodes.entry('', nodes.paragraph('', c2)) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
40 tbody += row |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
41 return table |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
42 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
43 class TestResults(Directive): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
44 required_arguments = 1 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
45 optional_arguments = 0 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
46 option_spec = {} |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
47 has_content = False |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
48 node_class = None |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
49 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
50 def run(self): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
51 # Run unit test: |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
52 tl = unittest.TestLoader() |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
53 result = RecordingTestResult() |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
54 tests = tl.discover('../test') |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
55 tests.run(result) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
56 para = nodes.paragraph() |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
57 para += nodes.Text('Unit test results:') |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
58 res = [] |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
59 for s in result.successfull_tests: |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
60 res.append((str(s), 'OK')) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
61 for s in result.skipped_tests: |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
62 res.append((str(s), 'SKIP')) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
63 for s in result.failed_tests: |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
64 res.append((str(s), 'FAIL')) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
65 table = makeTable(res) |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
66 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
67 return [para, table] |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
68 |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
69 def setup(app): |
0bb16d2a5699
Added cool sphinx plugin for creation of unittest result table
Windel Bouwman
parents:
diff
changeset
|
70 app.add_directive('testresults', TestResults) |