本文整理汇总了Python中testtools.compat._u函数的典型用法代码示例。如果您正苦于以下问题:Python _u函数的具体用法?Python _u怎么用?Python _u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_u函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_success_or_xfail
def check_success_or_xfail(self, as_success, error_message=None):
if as_success:
self.assertEqual([
('startTest', self.test),
('addSuccess', self.test),
('stopTest', self.test),
], self.client._events)
else:
details = {}
if error_message is not None:
details['traceback'] = Content(
ContentType("text", "x-traceback", {'charset': 'utf8'}),
lambda:[_b(error_message)])
if isinstance(self.client, ExtendedTestResult):
value = details
else:
if error_message is not None:
value = subunit.RemoteError(_u("Text attachment: traceback\n"
"------------\n") + _u(error_message) +
_u("------------\n"))
else:
value = subunit.RemoteError()
self.assertEqual([
('startTest', self.test),
('addExpectedFailure', self.test, value),
('stopTest', self.test),
], self.client._events)
示例2: test_describe_non_ascii_unicode
def test_describe_non_ascii_unicode(self):
string = _u("A\xA7")
suffix = _u("B\xA7")
mismatch = DoesNotEndWith(string, suffix)
self.assertEqual("%s does not end with %s." % (
text_repr(string), text_repr(suffix)),
mismatch.describe())
示例3: test_four_tests_in_a_row_with_plan
def test_four_tests_in_a_row_with_plan(self):
# A file
# 1..4
# ok 1 - first test in a script with no plan at all
# not ok 2 - second
# ok 3 - third
# not ok 4 - fourth
# results in four tests numbered and named
self.tap.write(_u('1..4\n'))
self.tap.write(_u('ok 1 - first test in a script with a plan\n'))
self.tap.write(_u('not ok 2 - second\n'))
self.tap.write(_u('ok 3 - third\n'))
self.tap.write(_u('not ok 4 - fourth\n'))
self.tap.seek(0)
result = subunit.TAP2SubUnit(self.tap, self.subunit)
self.assertEqual(0, result)
self.check_events([
('status', 'test 1 - first test in a script with a plan',
'success', None, False, None, None, True, None, None, None),
('status', 'test 2 - second', 'fail', None, False, None, None,
True, None, None, None),
('status', 'test 3 - third', 'success', None, False, None, None,
True, None, None, None),
('status', 'test 4 - fourth', 'fail', None, False, None, None,
True, None, None, None)])
示例4: test_eq
def test_eq(self):
error = subunit.RemoteError(_u("Something went wrong"))
another_error = subunit.RemoteError(_u("Something went wrong"))
different_error = subunit.RemoteError(_u("boo!"))
self.assertEqual(error, another_error)
self.assertNotEqual(error, different_error)
self.assertNotEqual(different_error, another_error)
示例5: test_supports_syntax_error
def test_supports_syntax_error(self):
self._assert_exception_format(
SyntaxError,
SyntaxError("Some Syntax Message", ("/path/to/file", 12, 2, "This is the line of code")),
[
_u(' File "/path/to/file", line 12\n'),
_u(" This is the line of code\n"),
_u(" ^\n"),
_u("SyntaxError: Some Syntax Message\n"),
],
)
示例6: test_individual_functions_called
def test_individual_functions_called(self):
self.patch(testtools.compat, "_format_stack_list", lambda stack_list: [_u("format stack list called\n")])
self.patch(
testtools.compat, "_format_exception_only", lambda etype, evalue: [_u("format exception only called\n")]
)
result = _format_exc_info(None, None, None)
expected = [
_u("Traceback (most recent call last):\n"),
_u("format stack list called\n"),
_u("format exception only called\n"),
]
self.assertThat(expected, Equals(result))
示例7: test_assertThat_verbose_unicode
def test_assertThat_verbose_unicode(self):
# When assertThat is given matchees or matchers that contain non-ASCII
# unicode strings, we can still provide a meaningful error.
matchee = _u("\xa7")
matcher = Equals(_u("a"))
expected = (
"Match failed. Matchee: %s\n"
"Matcher: %s\n"
"Difference: %s\n\n" % (repr(matchee).replace("\\xa7", matchee), matcher, matcher.match(matchee).describe())
)
e = self.assertRaises(self.failureException, self.assertThat, matchee, matcher, verbose=True)
self.assertEqual(expected, self.get_error_string(e))
示例8: _format_error
def _format_error(self, label, test, error_text, test_tags=None):
test_tags = test_tags or ()
tags = _u(' ').join(test_tags)
if tags:
tags = _u('tags: %s\n') % tags
return _u('').join([
self.sep1,
_u('%s: %s\n') % (label, test.id()),
tags,
self.sep2,
error_text,
])
示例9: test_syntax_error_line_utf_8
def test_syntax_error_line_utf_8(self):
"""Syntax error on a utf-8 line shows the line decoded"""
text, raw = self._get_sample_text("utf-8")
textoutput = self._setup_external_case("import bad")
self._write_module("bad", "utf-8", _u("\ufeff^ = 0 # %s\n") % text)
textoutput = self._run_external_case()
self.assertIn(self._as_output(_u(
'bad.py", line 1\n'
' ^ = 0 # %s\n'
+ ' ' * self._error_on_character +
' ^\n'
'SyntaxError: ') %
text), textoutput)
示例10: __init__
def __init__(self, ui, get_id, stream, previous_run=None, filter_tags=None):
"""Construct a CLITestResult writing to stream.
:param filter_tags: Tags that should be used to filter tests out. When
a tag in this set is present on a test outcome, the test is not
counted towards the test run count. If the test errors, then it is
still counted and the error is still shown.
"""
super(CLITestResult, self).__init__(ui, get_id, previous_run)
self.stream = unicode_output_stream(stream)
self.sep1 = _u('=' * 70 + '\n')
self.sep2 = _u('-' * 70 + '\n')
self.filter_tags = filter_tags or frozenset()
self.filterable_states = set(['success', 'uxsuccess', 'xfail', 'skip'])
示例11: test_bail_out_errors
def test_bail_out_errors(self):
# A file with line in it
# Bail out! COMMENT
# is treated as an error
self.tap.write(_u("ok 1 foo\n"))
self.tap.write(_u("Bail out! Lifejacket engaged\n"))
self.tap.seek(0)
result = subunit.TAP2SubUnit(self.tap, self.subunit)
self.assertEqual(0, result)
self.check_events([
('status', 'test 1 foo', 'success', None, False, None, None, True,
None, None, None),
('status', 'Bail out! Lifejacket engaged', 'fail', None, False,
None, None, True, None, None, None)])
示例12: __init__
def __init__(self, parser):
self.parser = parser
self._test_sym = (_b("test"), _b("testing"))
self._colon_sym = _b(":")
self._error_sym = (_b("error"),)
self._failure_sym = (_b("failure"),)
self._progress_sym = (_b("progress"),)
self._skip_sym = _b("skip")
self._success_sym = (_b("success"), _b("successful"))
self._tags_sym = (_b("tags"),)
self._time_sym = (_b("time"),)
self._xfail_sym = (_b("xfail"),)
self._uxsuccess_sym = (_b("uxsuccess"),)
self._start_simple = _u(" [")
self._start_multipart = _u(" [ multipart")
示例13: test_stream_content_reset
def test_stream_content_reset(self):
detail_name = 'test'
fixture = StringStream(detail_name)
with fixture:
stream = fixture.stream
content = fixture.getDetails()[detail_name]
stream.write(_u("testing 1 2 3"))
with fixture:
# The old content object returns the old usage
self.assertEqual(_u("testing 1 2 3"), content.as_text())
content = fixture.getDetails()[detail_name]
# A new fixture returns the new output:
stream = fixture.stream
stream.write(_u("1 2 3 testing"))
self.assertEqual(_u("1 2 3 testing"), content.as_text())
示例14: _handleTime
def _handleTime(self, offset, line):
# Accept it, but do not do anything with it yet.
try:
event_time = iso8601.parse_date(line[offset:-1])
except TypeError:
raise TypeError(_u("Failed to parse %r, got %r") % (line, sys.exec_info[1]))
self.client.time(event_time)
示例15: test_useFixture_details_captured
def test_useFixture_details_captured(self):
class DetailsFixture(fixtures.Fixture):
def setUp(self):
fixtures.Fixture.setUp(self)
self.addCleanup(delattr, self, "content")
self.content = [_b("content available until cleanUp")]
self.addDetail("content", content.Content(content_type.UTF8_TEXT, self.get_content))
def get_content(self):
return self.content
fixture = DetailsFixture()
class SimpleTest(TestCase):
def test_foo(self):
self.useFixture(fixture)
# Add a colliding detail (both should show up)
self.addDetail("content", content.Content(content_type.UTF8_TEXT, lambda: [_b("foo")]))
result = ExtendedTestResult()
SimpleTest("test_foo").run(result)
self.assertEqual("addSuccess", result._events[-2][0])
details = result._events[-2][2]
self.assertEqual(["content", "content-1"], sorted(details.keys()))
self.assertEqual("foo", _u("").join(details["content"].iter_text()))
self.assertEqual("content available until cleanUp", "".join(details["content-1"].iter_text()))