Bitten cov annotator w/ fixed doctest
17 March 2008
17:24
as Python
| 1 | |
|---|---|
| 2 | class TestCoverageAnnotator(Component): |
| 3 | """ |
| 4 | >>> from genshi.builder import tag |
| 5 | >>> from trac.test import Mock, MockPerm |
| 6 | >>> from trac.mimeview import Context |
| 7 | >>> from bitten.model import Build, Report |
| 8 | >>> from bitten.report.tests.coverage import env_stub_with_tables |
| 9 | >>> env = env_stub_with_tables() |
| 10 | |
| 11 | >>> Build(env, rev=123, config='trunk', rev_time=12345, platform='any').insert() |
| 12 | >>> rpt = Report(env, build=1, step='test', category='coverage') |
| 13 | >>> rpt.items.append({'file': 'foo.py', 'line_hits': '5 - 0'}) |
| 14 | >>> rpt.insert() |
| 15 | |
| 16 | >>> ann = TestCoverageAnnotator(env) |
| 17 | >>> req = Mock(href=Mock(), perm=MockPerm()) |
| 18 | >>> context = Context.from_request(req, 'source', 'foo.py', 123) |
| 19 | >>> data = ann.get_annotation_data(context) |
| 20 | >>> print data |
| 21 | [5, None, 0] |
| 22 | |
| 23 | >>> def annotate_row(lineno, line): |
| 24 | ... row = tag.tr() |
| 25 | ... ann.annotate_row(context, row, lineno, line, data) |
| 26 | ... return str(row) |
| 27 | |
| 28 | >>> annotate_row(1, 'x = 1') |
| 29 | '<tr><th style="background-color: #0f0">5</th></tr>' |
| 30 | >>> annotate_row(2, '') |
| 31 | '<tr><th></th></tr>' |
| 32 | >>> annotate_row(3, 'y = x') |
| 33 | '<tr><th style="background-color: #f00">0</th></tr>' |
| 34 | """ |
| 35 | implements(IHTMLPreviewAnnotator) |
| 36 | |
| 37 | # IHTMLPreviewAnnotator methods |
| 38 | |
| 39 | def get_annotation_type(self): |
| 40 | pass |
| 41 | |
| 42 | def get_annotation_data(self, context): |
| 43 | pass |
| 44 | |
| 45 | def annotate_row(self, context, row, lineno, line, data): |
| 46 | pass |
Comments
-
mgood says:
17 March 2008
17:25def env_stub_with_tables(): env = EnvironmentStub() db = env.get_db_cnx() cursor = db.cursor() connector, _ = DatabaseManager(env)._get_connector() for table in schema: for stmt in connector.to_sql(table): cursor.execute(stmt) return env
