当前位置: 首页>>代码示例>>Python>>正文


Python assertions.assert_raises函数代码示例

本文整理汇总了Python中testify.assertions.assert_raises函数的典型用法代码示例。如果您正苦于以下问题:Python assert_raises函数的具体用法?Python assert_raises怎么用?Python assert_raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了assert_raises函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_invalid_line

 def test_invalid_line(self):
     self.tmpfile.write('justkey\n')
     self.tmpfile.flush()
     assert_raises(
             errors.ConfigurationError,
             loader.PropertiesConfiguration,
             self.tmpfile.name)
开发者ID:kfreedland,项目名称:PyStaticConfiguration,代码行数:7,代码来源:loader_test.py

示例2: test_fails_when_exception_is_not_raised

 def test_fails_when_exception_is_not_raised(self):
     raises_nothing = lambda: None
     try:
         assertions.assert_raises(ValueError, raises_nothing)
     except AssertionError:
         pass
     else:
         assert_not_reached('AssertionError should have been raised')
开发者ID:sumeet,项目名称:Testify,代码行数:8,代码来源:assertions_test.py

示例3: 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
     assertions.assert_raises(GoodArguments, check_arguments, arg1, arg2, kwarg=kwarg)
开发者ID:farshidce,项目名称:Testify,代码行数:8,代码来源:assertions_test.py

示例4: test_read_config_failed

 def test_read_config_failed(self):
     self.namespace.get.return_value = proxy.UndefToken
     assert_raises(
             errors.ConfigurationError,
             readers._read_config,
             'some_key',
             self.namespace,
             None)
开发者ID:kfreedland,项目名称:PyStaticConfiguration,代码行数:8,代码来源:readers_test.py

示例5: test_xml_configuration_safe_value_tag

 def test_xml_configuration_safe_value_tag(self):
     content = """
         <config>
             <sometag value="snazz">E</sometag>
         </config>
     """
     self.write_content_to_file(content)
     assert_raises(errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
开发者ID:Roguelazer,项目名称:PyStaticConfiguration,代码行数:8,代码来源:loader_test.py

示例6: test_build_loader_optional

    def test_build_loader_optional(self):
        err_msg = "Failed to do"
        loader_func = mock.Mock()
        loader_func.side_effect = ValueError(err_msg)
        config_loader = loader.build_loader(loader_func)

        config_loader(optional=True)
        assert_raises(ValueError, config_loader)
开发者ID:kfreedland,项目名称:PyStaticConfiguration,代码行数:8,代码来源:loader_test.py

示例7: 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(MyException, raises_value_error)
     except ValueError:
         pass
     else:
         assert_not_reached('ValueError should have been raised')
开发者ID:sumeet,项目名称:Testify,代码行数:9,代码来源:assertions_test.py

示例8: test_xml_configuration_safe_override

 def test_xml_configuration_safe_override(self):
     content = """
         <config>
             <sometag foo="bar">
                 <foo>E</foo>
             </sometag>
         </config>
     """
     self.write_content_to_file(content)
     assert_raises(errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
开发者ID:Roguelazer,项目名称:PyStaticConfiguration,代码行数:10,代码来源:loader_test.py

示例9: test_no_vars

    def test_no_vars(self):
        """
        To allocate a .__dict__ attribute of this object means that we're
        allocating a second, mutable dictionary as part of our frozendict.
        This would be a waste of memory as well as yielding pretty nonsensical
        semantics wrt immutability.
        """
        fd = fdict(a=1)
        with T.assert_raises(TypeError):
            vars(fd)

        with T.assert_raises(AttributeError):
            fd.__dict__
开发者ID:bukzor,项目名称:scratch,代码行数:13,代码来源:frozendict_test.py

示例10: test_fails_when_no_exception_is_raised

 def test_fails_when_no_exception_is_raised(self):
     """Tests that the assertion fails when no exception is raised."""
     def exists(e):
         return True
     with assertions.assert_raises(AssertionError):
         with assertions.assert_raises_such_that(Exception, exists):
             pass
开发者ID:Yelp,项目名称:Testify,代码行数:7,代码来源:assertions_test.py

示例11: test_unexpected_exception_passes_through

    def test_unexpected_exception_passes_through(self):
        class DifferentException(Exception):
            pass

        with assertions.assert_raises(DifferentException):
            with assertions.assert_raises_exactly(self.MyException, "first", "second"):
                raise DifferentException("first", "second")
开发者ID:Yelp,项目名称:Testify,代码行数:7,代码来源:assertions_test.py

示例12: test_fails_with_different_class

    def test_fails_with_different_class(self):
        class SpecialException(self.MyException):
            pass

        with assertions.assert_raises(AssertionError):
            with assertions.assert_raises_exactly(self.MyException, "first", "second"):
                raise SpecialException("first", "second")
开发者ID:Yelp,项目名称:Testify,代码行数:7,代码来源:assertions_test.py

示例13: test_fails_when_exception_test_fails

 def test_fails_when_exception_test_fails(self):
     """Tests that when an exception of the right type that fails the
     passed in exception test is raised, the assertion fails."""
     has_two_args = lambda e: assertions.assert_length(e.args, 2)
     with assertions.assert_raises(AssertionError):
         with assertions.assert_raises_such_that(Exception, has_two_args):
             raise Exception("only one argument")
开发者ID:farshidce,项目名称:Testify,代码行数:7,代码来源:assertions_test.py

示例14: test_parse_test_runner_command_line_args_no_test_path

 def test_parse_test_runner_command_line_args_no_test_path(self):
     """Make sure that if no options and no arguments are passed,
     parse_test_runner_command_line_args DOES complain about a missing test
     path.
     """
     with assert_raises(OptionParserErrorException):
         test_program.parse_test_runner_command_line_args([], [])
开发者ID:chunkyg,项目名称:Testify,代码行数:7,代码来源:test_program_test.py

示例15: test_fails_when_incorrect_warning_with_callable

 def test_fails_when_incorrect_warning_with_callable(self):
     """
     Test that assert_warns fails when we pass a specific warning and
     a different warning class is thrown.
     """
     with assertions.assert_raises(AssertionError):
         assertions.assert_warns(DeprecationWarning, self._create_user_warning)
开发者ID:pyarnold,项目名称:Testify,代码行数:7,代码来源:assertions_test.py


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