* Fixed unit tests which were failing under pypy due to a change in the way
pypy formats tracebacks. (Thomi Richards)
+* Make `testtools.content.text_content` error if anything other than text
+ is given as content. (Thomi Richards)
+
1.1.0
~~~~~
_b,
_format_exception_only,
_format_stack_list,
- _isbytes,
_TB_HEADER,
_u,
+ istext,
str_is_unicode,
)
from testtools.content_type import ContentType, JSON, UTF8_TEXT
This is useful for adding details which are short strings.
"""
- if _isbytes(text):
- raise TypeError('text_content must be given a string, not bytes.')
+ if not istext(text):
+ raise TypeError(
+ "text_content must be given text, not '%s'." % type(text).__name__
+ )
return Content(UTF8_TEXT, lambda: [text.encode('utf8')])
data = _b("Some Bytes")
self.assertRaises(TypeError, text_content, data)
+ def test_text_content_raises_TypeError_when_passed_non_text(self):
+ bad_values = (None, list(), dict(), 42, 1.23)
+ for value in bad_values:
+ self.assertThat(
+ lambda: text_content(value),
+ raises(
+ TypeError("text_content must be given text, not '%s'." %
+ type(value).__name__)
+ ),
+ )
+
def test_json_content(self):
data = {'foo': 'bar'}
expected = Content(JSON, lambda: [_b('{"foo": "bar"}')])