summaryrefslogtreecommitdiff
path: root/python/subunit/content.py
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-10-05 05:53:44 +1100
committerRobert Collins <robertc@robertcollins.net>2009-10-05 05:53:44 +1100
commit1bb81bd80c26f41555f676d9f6b164be9c061e61 (patch)
tree150e8a9d01cbf78f8cd880ce1bbbe1078ed8f9c5 /python/subunit/content.py
parent869d2a4f792a4d5d2c9f7f55d95ba216f0fbe4f1 (diff)
downloadsubunit-git-1bb81bd80c26f41555f676d9f6b164be9c061e61.tar.gz
Create TracebackContent for adapting exc_info tuples.
Diffstat (limited to 'python/subunit/content.py')
-rw-r--r--python/subunit/content.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/python/subunit/content.py b/python/subunit/content.py
index 517862a..cd3ad60 100644
--- a/python/subunit/content.py
+++ b/python/subunit/content.py
@@ -16,6 +16,12 @@
"""Content - a MIME-like Content object."""
+from unittest import TestResult
+
+import subunit
+from subunit.content_type import ContentType
+
+
class Content(object):
"""A MIME-like Content object.
@@ -39,3 +45,23 @@ class Content(object):
def iter_bytes(self):
"""Iterate over bytestrings of the serialised content."""
return self._get_bytes()
+
+
+class TracebackContent(Content):
+ """Content object for tracebacks.
+
+ This adapts an exc_info tuple to the Content interface.
+ text/x-traceback;language=python is used for the mime type, in order to
+ provide room for other languages to format their tracebacks differently.
+ """
+
+ def __init__(self, err):
+ """Create a TracebackContent for err."""
+ if err is None:
+ raise ValueError("err may not be None")
+ content_type = ContentType('text', 'x-traceback',
+ {"language": "python"})
+ self._result = TestResult()
+ super(TracebackContent, self).__init__(content_type,
+ lambda:self._result._exc_info_to_string(err,
+ subunit.RemotedTestCase('')))