Also improve docs and line wrapping. Fixes D44#3.
Details
Details
Tests pass.
Diff Detail
Diff Detail
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| Lint Skipped |
| Unit Tests Skipped |
| Path | |||
|---|---|---|---|
| M | libtaskotron/check.py (12 lines) |
| Commit | Tree | Parents | Author | Summary | Date |
|---|---|---|---|---|---|
| eb5fc5fa0dd6 | 75f9fa23ee97 | 2f2c7cd957c1 | Kamil Páral | e.message can be empty sometimes, print the whole error instead (Show More…) | Apr 10 2014, 9:42 AM |
| Show All 9 Lines | |||||
| 10 | import tap | 10 | import tap | ||
| 11 | 11 | | |||
| 12 | from . import python_utils | 12 | from . import python_utils | ||
| 13 | from . import exceptions as exc | 13 | from . import exceptions as exc | ||
| 14 | from .logger import log | 14 | from .logger import log | ||
| 15 | 15 | | |||
| 16 | from pytap13 import TAP13 | 16 | from pytap13 import TAP13 | ||
| 17 | 17 | | |||
| 18 | # a list of reserved keywords for TAP output, which can't be overridden in | ||||
| 19 | # keyvals | ||||
| 18 | RESERVED_KEYS = ('item', 'type', 'outcome', 'summary', 'details') | 20 | RESERVED_KEYS = ('item', 'type', 'outcome', 'summary', 'details') | ||
| 19 | 21 | | |||
| 20 | class CheckDetail(object): | 22 | class CheckDetail(object): | ||
| 21 | '''Class encompassing everything related to the outcome of a check run. | 23 | '''Class encompassing everything related to the outcome of a check run. | ||
| 22 | It contains convenience methods for tracking, evaluating and reporting | 24 | It contains convenience methods for tracking, evaluating and reporting | ||
| 23 | check results. | 25 | check results. | ||
| 24 | 26 | | |||
| 25 | For some checks, it's trivial to parse its output at the end of its | 27 | For some checks, it's trivial to parse its output at the end of its | ||
| ▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Line(s) | 277 | for detail in check_details: | |||
| 295 | data['details'] = {} | 297 | data['details'] = {} | ||
| 296 | if detail.output: | 298 | if detail.output: | ||
| 297 | data['details']['output'] = '\n'.join(detail.output) | 299 | data['details']['output'] = '\n'.join(detail.output) | ||
| 298 | if not data['details']: | 300 | if not data['details']: | ||
| 299 | del data['details'] | 301 | del data['details'] | ||
| 300 | 302 | | |||
| 301 | for key, value in detail.keyvals.iteritems(): | 303 | for key, value in detail.keyvals.iteritems(): | ||
| 302 | if key in RESERVED_KEYS: | 304 | if key in RESERVED_KEYS: | ||
| 303 | log.warn("Reserved key %r in keyvals. Ignoring for export purposes.", key) | 305 | log.warn("Reserved key '%r' found in keyvals. Ignoring for " | ||
| 306 | "export purposes.", key) | ||||
| 304 | continue | 307 | continue | ||
| 305 | 308 | | |||
| 306 | data[key] = value | 309 | data[key] = value | ||
| 307 | 310 | | |||
| 308 | # generate | 311 | # generate | ||
| 309 | output = tapgen.format_TAP_msg(result=tap_outcome, name=name, data=data) | 312 | output = tapgen.format_TAP_msg(result=tap_outcome, name=name, data=data) | ||
| 310 | tapout.append(output) | 313 | tapout.append(output) | ||
| 311 | 314 | | |||
| 312 | return '\n'.join(tapout) | 315 | return '\n'.join(tapout) | ||
| 313 | 316 | | |||
| 314 | def import_TAP(source): | 317 | def import_TAP(source): | ||
| 315 | '''Parses the source, and returns list of CheckDetails''' | 318 | '''Parses the source (string in TAP format), and returns list of | ||
| 319 | CheckDetails. | ||||
| 320 | @throw TaskotronValueError if TAP syntax is incorrect | ||||
| 321 | ''' | ||||
| 316 | 322 | | |||
| 317 | tap = TAP13() | 323 | tap = TAP13() | ||
| 318 | try: | 324 | try: | ||
| 319 | tap.parse(source) | 325 | tap.parse(source) | ||
| 320 | except ValueError as e: | 326 | except ValueError as e: | ||
| 321 | raise exc.TaskotronValueError('Failed parsing of the TAP output: %s' % e.message) | 327 | raise exc.TaskotronValueError('Failed to parse TAP contents: %s' % e) | ||
| 322 | 328 | | |||
| 323 | check_details = [] | 329 | check_details = [] | ||
| 324 | for test in tap.tests: | 330 | for test in tap.tests: | ||
| 325 | y = test.yaml | 331 | y = test.yaml | ||
| 326 | item = y.get('item', None) | 332 | item = y.get('item', None) | ||
| 327 | report_type = y.get('type', None) | 333 | report_type = y.get('type', None) | ||
| 328 | outcome = 'PASSED' if test.result == 'ok' else 'FAILED' | 334 | outcome = 'PASSED' if test.result == 'ok' else 'FAILED' | ||
| 329 | outcome = y.get('outcome', outcome) | 335 | outcome = y.get('outcome', outcome) | ||
| Show All 15 Lines | |||||