本文整理汇总了Python中testify.assertions.assert_raises_and_contains函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises_and_contains函数的具体用法?Python assert_raises_and_contains怎么用?Python assert_raises_and_contains使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_raises_and_contains函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode_diff2
def test_unicode_diff2(self):
unicode_string = u'Thę quıćk brōwń fōx jumpęd ōvęr thę łąźy dōğ.'
utf8_string = u'Thę quıćk brōwń fōx jumpęd ōvęr thę łąży dōğ.'
def assert_with_unicode_msg():
assertions.assert_equal(unicode_string, utf8_string)
assertions.assert_raises_and_contains(AssertionError, 'łą<ź>y', assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, 'łą<ż>y', assert_with_unicode_msg)
示例2: test_validate_regex_failed
def test_validate_regex_failed(self):
pattern = "((this) regex is broken"
assert_raises_and_contains(
errors.ValidationError,
pattern,
validation.validate_regex,
pattern)
示例3: test_unicode_diff
def test_unicode_diff(self):
ascii_string = 'abc'
unicode_string = u'ü and some more'
def assert_with_unicode_msg():
assert_equal(unicode_string, ascii_string)
assertions.assert_raises_and_contains(AssertionError, 'abc', assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, 'and some more', assert_with_unicode_msg)
示例4: test_callable_is_called_with_all_arguments
def test_callable_is_called_with_all_arguments(self):
class GoodArguments(Exception): pass
arg1, arg2, kwarg = object(), object(), object()
def check_arguments(*args, **kwargs):
assert_equal((arg1, arg2), args)
assert_equal({'kwarg': kwarg}, kwargs)
raise GoodArguments('abc')
assertions.assert_raises_and_contains(GoodArguments, 'abc', check_arguments, arg1, arg2, kwarg=kwarg)
示例5: test_fails_when_exception_is_not_raised
def test_fails_when_exception_is_not_raised(self):
raises_nothing = lambda: None
try:
assertions.assert_raises_and_contains(ValueError, 'abc', raises_nothing)
except AssertionError:
pass
else:
assert_not_reached('AssertionError should have been raised')
示例6: test_fails_when_wrong_exception_is_raised
def test_fails_when_wrong_exception_is_raised(self):
def raises_value_error():
raise ValueError
try:
assertions.assert_raises_and_contains(MyException, 'abc', raises_value_error)
except ValueError:
pass
else:
assert_not_reached('ValueError should have been raised')
示例7: test_fails_when_exception_does_not_contains_all_strings
def test_fails_when_exception_does_not_contains_all_strings(self):
def raises_value_error():
raise ValueError('abc xyz')
try:
assertions.assert_raises_and_contains(ValueError, ['ABC', '123'], raises_value_error)
except AssertionError:
pass
else:
assert_not_reached('AssertionError should have been raised')
示例8: test_get_value_fails_validation
def test_get_value_fails_validation(self):
expected = [self.name, self.config_key]
validator = mock.Mock(side_effect=validation.ValidationError)
_ = proxy.ValueProxy( # flake8: noqa
validator,
self.namespace,
'something.broken')
assert_raises_and_contains(
errors.ConfigurationError,
expected,
lambda: self.value_proxy.value)
示例9: test_utf8_diff
def test_utf8_diff(self):
utf8_string1 = u'münchen'.encode('utf8')
utf8_string2 = u'mënchen'.encode('utf8')
def assert_with_unicode_msg():
assert_equal(utf8_string1, utf8_string2)
for content in (
r"l: 'm\xc3\xbcnchen'",
r"r: 'm\xc3\xabnchen'",
"l: m<ü>nchen",
"r: m<ë>nchen",
):
assertions.assert_raises_and_contains(AssertionError, content, assert_with_unicode_msg)
示例10: test_str_versus_unicode_diff
def test_str_versus_unicode_diff(self):
"""Real-world example from https://github.com/Yelp/Testify/issues/144#issuecomment-14188539
A good assert_equal implementation will clearly show that these have completely different character contents.
"""
unicode_string = u'm\xc3\xbcnchen'
byte_string = 'm\xc3\xbcnchen'
def assert_with_unicode_msg():
assert_equal(unicode_string, byte_string)
for content in (
r"l: u'm\xc3\xbcnchen'",
r"r: 'm\xc3\xbcnchen'",
"l: m<ü>nchen",
"r: m<ü>nchen",
):
assertions.assert_raises_and_contains(AssertionError, content, assert_with_unicode_msg)
示例11: test_bytes_diff
def test_bytes_diff(self):
byte_string1 = 'm\xeenchen'
byte_string2 = 'm\xaanchen'
def assert_with_unicode_msg():
assert_equal(byte_string1, byte_string2)
assertions.assert_raises_and_contains(AssertionError, r"l: 'm\xeenchen'", assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, r"r: 'm\xaanchen'", assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, 'l: m<î>nchen', assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, 'r: m<ª>nchen', assert_with_unicode_msg)
示例12: test_unicode_diff3
def test_unicode_diff3(self):
unicode_string = u'münchen'
utf8_string = unicode_string.encode('utf8')
def assert_with_unicode_msg():
assert_equal(unicode_string, utf8_string)
assertions.assert_raises_and_contains(AssertionError, r"l: u'm\xfcnchen'", assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, r"r: 'm\xc3\xbcnchen'", assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, 'l: münchen', assert_with_unicode_msg)
assertions.assert_raises_and_contains(AssertionError, 'r: münchen', assert_with_unicode_msg)
示例13: test_unicode_diff3
def test_unicode_diff3(self):
unicode_string = u'münchen'
utf8_string = unicode_string.encode('utf8')
def assert_with_unicode_msg():
assert_equal(unicode_string, utf8_string)
for part in (
(
r"l: u'm\xfcnchen'" if six.PY2 else
r"l: 'münchen'"
),
(
r"r: 'm\xc3\xbcnchen'" if six.PY2 else
r"r: b'm\xc3\xbcnchen'"
),
'l: münchen',
'r: münchen',
):
assertions.assert_raises_and_contains(
AssertionError, part, assert_with_unicode_msg,
)
示例14: test_bytes_diff
def test_bytes_diff(self):
byte_string1 = b'm\xeenchen'
byte_string2 = b'm\xaanchen'
def assert_with_unicode_msg():
assert_equal(byte_string1, byte_string2)
for part in (
(
r"l: 'm\xeenchen'" if six.PY2 else
r"l: b'm\xeenchen'"
),
(
r"r: 'm\xaanchen'" if six.PY2 else
r"r: b'm\xaanchen'"
),
'l: m<î>nchen',
'r: m<ª>nchen'
):
assertions.assert_raises_and_contains(
AssertionError, part, assert_with_unicode_msg,
)
示例15: test_extract_value_unset
def test_extract_value_unset(self):
expected = [self.name, self.config_key]
assert_raises_and_contains(errors.ConfigurationError,
expected, lambda: self.value_proxy.value)