Add a convenience function for string content.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import codecs
|
||||
|
||||
from testtools.compat import _b
|
||||
from testtools.content_type import ContentType
|
||||
from testtools.content_type import ContentType, UTF8_TEXT
|
||||
from testtools.testresult import TestResult
|
||||
|
||||
|
||||
@@ -89,3 +89,11 @@ class TracebackContent(Content):
|
||||
value = self._result._exc_info_to_unicode(err, test)
|
||||
super(TracebackContent, self).__init__(
|
||||
content_type, lambda: [value.encode("utf8")])
|
||||
|
||||
|
||||
def text_content(text):
|
||||
"""Create a `Content` object from some text.
|
||||
|
||||
This is useful for adding details which are short strings.
|
||||
"""
|
||||
return Content(UTF8_TEXT, lambda: [text.encode('utf8')])
|
||||
|
||||
@@ -179,6 +179,7 @@ class AsynchronousDeferredRunTest(RunTest):
|
||||
# present.
|
||||
for debug_info in unhandled:
|
||||
f = debug_info.failResult
|
||||
|
||||
self._got_user_exception(
|
||||
(f.type, f.value, f.tb), 'unhandled-error-in-deferred')
|
||||
junk = spinner.clear_junk()
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import unittest
|
||||
from testtools import TestCase
|
||||
from testtools.compat import _u
|
||||
from testtools.content import Content, TracebackContent
|
||||
from testtools.content_type import ContentType
|
||||
from testtools.content import Content, TracebackContent, text_content
|
||||
from testtools.content_type import ContentType, UTF8_TEXT
|
||||
from testtools.tests.helpers import an_exc_info
|
||||
|
||||
|
||||
@@ -68,6 +68,14 @@ class TestTracebackContent(TestCase):
|
||||
self.assertEqual(expected, ''.join(list(content.iter_text())))
|
||||
|
||||
|
||||
class TestBytesContent(TestCase):
|
||||
|
||||
def test_bytes(self):
|
||||
data = _u("some data")
|
||||
expected = Content(UTF8_TEXT, lambda: [data.encode('utf8')])
|
||||
self.assertEqual(expected, text_content(data))
|
||||
|
||||
|
||||
def test_suite():
|
||||
from unittest import TestLoader
|
||||
return TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
Reference in New Issue
Block a user