• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python assertions.assert_raises_and_contains函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:pyarnold,项目名称:Testify,代码行数:7,代码来源:assertions_test.py


示例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)
开发者ID:kfreedland,项目名称:PyStaticConfiguration,代码行数:7,代码来源:validation_test.py


示例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)
开发者ID:pyarnold,项目名称:Testify,代码行数:7,代码来源:assertions_test.py


示例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)
开发者ID:farshidce,项目名称:Testify,代码行数:8,代码来源:assertions_test.py


示例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')
开发者ID:farshidce,项目名称:Testify,代码行数:8,代码来源:assertions_test.py


示例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')
开发者ID:farshidce,项目名称:Testify,代码行数:9,代码来源:assertions_test.py


示例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')
开发者ID:farshidce,项目名称:Testify,代码行数:9,代码来源:assertions_test.py


示例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)
开发者ID:kfreedland,项目名称:PyStaticConfiguration,代码行数:11,代码来源:proxy_test.py


示例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)
开发者ID:pyarnold,项目名称:Testify,代码行数:12,代码来源:assertions_test.py


示例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)
开发者ID:pyarnold,项目名称:Testify,代码行数:16,代码来源:assertions_test.py


示例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)
开发者ID:pyarnold,项目名称:Testify,代码行数:9,代码来源:assertions_test.py


示例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)
开发者ID:pyarnold,项目名称:Testify,代码行数:9,代码来源:assertions_test.py


示例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,
            )
开发者ID:Yelp,项目名称:Testify,代码行数:22,代码来源:assertions_test.py


示例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,
            )
开发者ID:Yelp,项目名称:Testify,代码行数:22,代码来源:assertions_test.py


示例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)
开发者ID:analogue,项目名称:PyStaticConfiguration,代码行数:4,代码来源:proxy_test.py


示例16: test_validate_regex_none

 def test_validate_regex_none(self):
     assert_raises_and_contains(errors.ValidationError, 'None',
         validation.validate_regex, None)
开发者ID:analogue,项目名称:PyStaticConfiguration,代码行数:3,代码来源:validation_test.py


示例17: test_build_list_of_type_float_failed

 def test_build_list_of_type_float_failed(self):
     validator = validation.build_list_type_validator(
         validation.validate_float)
     assert_raises_and_contains(
         errors.ValidationError, 'invalid float: a', validator, ['0.1', 'a'])
开发者ID:analogue,项目名称:PyStaticConfiguration,代码行数:5,代码来源:validation_test.py


示例18: test_build_list_of_type_not_a_list

 def test_build_list_of_type_not_a_list(self):
     validator = validation.build_list_type_validator(
         validation.validate_any)
     assert_raises_and_contains(
         errors.ValidationError, 'invalid iterable', validator, None)
开发者ID:analogue,项目名称:PyStaticConfiguration,代码行数:5,代码来源:validation_test.py


示例19: test__getattr__unknown_method

 def test__getattr__unknown_method(self):
     method_name = 'missing_method'
     assert_raises_and_contains(AttributeError,
         method_name,
         getattr, self.client, method_name)
开发者ID:dnephin,项目名称:python-api-factory,代码行数:5,代码来源:factory_test.py


示例20: test_invalid_log_level

 def test_invalid_log_level(self):
     assert_raises_and_contains(
             errors.ValidationError,
             'UNKNOWN',
             validation.validate_log_level,
             'UNKNOWN')
开发者ID:kfreedland,项目名称:PyStaticConfiguration,代码行数:6,代码来源:validation_test.py



注:本文中的testify.assertions.assert_raises_and_contains函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python assertions.assert_raises_such_that函数代码示例发布时间:2022-05-27
下一篇:
Python assertions.assert_raises函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap