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