~testing-cabal/testtools/trunk

« back to all changes in this revision

Viewing changes to testtools/testresult/doubles.py

  • Committer: GitHub
  • Author(s): Free Ekanayaka
  • Date: 2017-04-11 13:13:10 UTC
  • Revision ID: git-v1:01d4a9b59ecb93701838b8df5ee8fbbd3d22b0f4
Add ResourcedToStreamDecorator test result decorator for testresources integration (#243)

This new decorator implements the TestResult protocol extension supported by test resources. For example, tt makes it possible to easily have resource-related events streamed to subunit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
"""Doubles of test result objects, useful for testing unittest code."""
4
4
 
 
5
from collections import namedtuple
 
6
 
 
7
from testtools.tags import TagContext
 
8
 
5
9
__all__ = [
6
10
    'Python26TestResult',
7
11
    'Python27TestResult',
11
15
    ]
12
16
 
13
17
 
14
 
from testtools.tags import TagContext
15
 
 
16
 
 
17
18
class LoggingBase(object):
18
19
    """Basic support for logging of results."""
19
20
 
219
220
               runnable=True, file_name=None, file_bytes=None, eof=False,
220
221
               mime_type=None, route_code=None, timestamp=None):
221
222
        self._events.append(
222
 
            ('status', test_id, test_status, test_tags,
223
 
             runnable, file_name, file_bytes, eof, mime_type, route_code,
224
 
             timestamp))
 
223
            _StatusEvent(
 
224
                'status', test_id, test_status, test_tags, runnable,
 
225
                file_name, file_bytes, eof, mime_type, route_code,
 
226
                timestamp))
 
227
 
 
228
 
 
229
# Convenience for easier access to status fields
 
230
_StatusEvent = namedtuple(
 
231
    "_Event", [
 
232
        "name", "test_id", "test_status", "test_tags", "runnable", "file_name",
 
233
        "file_bytes", "eof", "mime_type", "route_code", "timestamp"])