Content - a MIME-like Content object.
Class Content A MIME-like Content object.
Class StackLinesContent Content object for stack lines.
Class TracebackContent Content object for tracebacks.
Function StacktraceContent Content object for stack traces.
Function json_content Create a JSON Content object from JSON-encodeable data.
Function text_content Create a Content object from some text.
Function maybe_wrap Merge metadata for func into wrapper if functools is present.
Function content_from_file Create a Content object from a file on disk.
Function content_from_stream Create a Content object from a file-like stream.
Function content_from_reader Create a Content object that will obtain the content from reader.
Function attach_file Attach a file to this test as a detail.
Function _iter_chunks Read 'stream' in chunks of 'chunk_size'.
def _iter_chunks(stream, chunk_size, seek_offset=None, seek_whence=0):
Read 'stream' in chunks of 'chunk_size'.
ParametersstreamA file-like object to read from.
chunk_sizeThe size of each read from 'stream'.
seek_offsetIf non-None, seek before iterating.
seek_whencePass through to the seek call, if seeking.
def StacktraceContent(prefix_content='', postfix_content=''):

Content object for stack traces.

This function will create and return a 'Content' object that contains a stack trace.

The mime type is set to 'text/x-traceback;language=python', so other languages can format their stack traces differently.

Parametersprefix_contentA unicode string to add before the stack lines.
postfix_contentA unicode string to add after the stack lines.
def json_content(json_data):
Create a JSON Content object from JSON-encodeable data.
def text_content(text):

Create a Content object from some text.

This is useful for adding details which are short strings.

def maybe_wrap(wrapper, func):
Merge metadata for func into wrapper if functools is present.
def content_from_file(path, content_type=None, chunk_size=DEFAULT_CHUNK_SIZE, buffer_now=False, seek_offset=None, seek_whence=0):

Create a Content object from a file on disk.

Note that unless buffer_now is explicitly passed in as True, the file will only be read from when iter_bytes is called.

ParameterspathThe path to the file to be used as content.
content_typeThe type of content. If not specified, defaults to UTF8-encoded text/plain.
chunk_sizeThe size of chunks to read from the file. Defaults to DEFAULT_CHUNK_SIZE.
buffer_nowIf True, read the file from disk now and keep it in memory. Otherwise, only read when the content is serialized.
seek_offsetIf non-None, seek within the stream before reading it.
seek_whenceIf supplied, pass to stream.seek() when seeking.
def content_from_stream(stream, content_type=None, chunk_size=DEFAULT_CHUNK_SIZE, buffer_now=False, seek_offset=None, seek_whence=0):

Create a Content object from a file-like stream.

Note that unless buffer_now is explicitly passed in as True, the stream will only be read from when iter_bytes is called.

ParametersstreamA file-like object to read the content from. The stream is not closed by this function or the 'Content' object it returns.
content_typeThe type of content. If not specified, defaults to UTF8-encoded text/plain.
chunk_sizeThe size of chunks to read from the file. Defaults to DEFAULT_CHUNK_SIZE.
buffer_nowIf True, reads from the stream right now. Otherwise, only reads when the content is serialized. Defaults to False.
seek_offsetIf non-None, seek within the stream before reading it.
seek_whenceIf supplied, pass to stream.seek() when seeking.
def content_from_reader(reader, content_type, buffer_now):
Create a Content object that will obtain the content from reader.
ParametersreaderA callback to read the content. Should return an iterable of bytestrings.
content_typeThe content type to create.
buffer_nowIf True the reader is evaluated immediately and buffered.
def attach_file(detailed, path, name=None, content_type=None, chunk_size=DEFAULT_CHUNK_SIZE, buffer_now=True):

Attach a file to this test as a detail.

This is a convenience method wrapping around addDetail.

Note that by default the contents of the file will be read immediately. If buffer_now is False, then the file must exist when the test result is called with the results of this test, after the test has been torn down.

ParametersdetailedAn object with details
pathThe path to the file to attach.
nameThe name to give to the detail for the attached file.
content_typeThe content type of the file. If not provided, defaults to UTF8-encoded text/plain.
chunk_sizeThe size of chunks to read from the file. Defaults to something sensible.
buffer_now

If False the file content is read when the content object is evaluated rather than when attach_file is called. Note that this may be after any cleanups that obj_with_details has, so if the file is a temporary file disabling buffer_now may cause the file to be read after it is deleted. To handle those cases, using attach_file as a cleanup is recommended because it guarantees a sequence for when the attach_file call is made:

detailed.addCleanup(attach_file, 'foo.txt', detailed)
API Documentation for testtools, generated by pydoctor at 2015-07-01 16:11:28.