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

Python testfixtures.should_raise函数代码示例

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

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



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

示例1: test_args

 def test_args(self):
     def to_test(*args):
         raise ValueError('%s'%repr(args))
     should_raise(
         to_test,
         ValueError('(1,)')
         )(1)
开发者ID:cart0113,项目名称:testfixtures,代码行数:7,代码来源:test_should_raise.py


示例2: test_kw

 def test_kw(self):
     def to_test(**kw):
         raise ValueError('%r'%kw)
     should_raise(
         to_test,
         ValueError("{'x': 1}")
         )(x=1)
开发者ID:cart0113,项目名称:testfixtures,代码行数:7,代码来源:test_should_raise.py


示例3: test_class_class

 def test_class_class(self):
     class Test:
         def __init__(self, x):
             # The TypeError is raised due to the mis-matched parameters
             # so the pass never gets executed
             pass  # pragma: no cover
     should_raise(TypeError)(Test)()
开发者ID:Simplistix,项目名称:testfixtures,代码行数:7,代码来源:test_should_raise.py


示例4: test_both

 def test_both(self):
     def to_test(*args,**kw):
         raise ValueError('%r %r'%(args,kw))
     should_raise(
         to_test,
         ValueError("(1,) {'x': 2}")
         )(1,x=2)
开发者ID:cart0113,项目名称:testfixtures,代码行数:7,代码来源:test_should_raise.py


示例5: test_formatting_info

    def test_formatting_info(self):
        r = TestReader()
        f = Mock()
        
        r.formatting_info = True
        
        r.setup(('Sheet1',[['R1C1','R1C2']]))

        # at this point you can now manipulate the xf index as follows:
        book = r.books[0][0]
        sx,rx,cx = 0,0,0
        book.sheet_by_index(sx)._cell_xf_indexes[rx][cx]=42

        # NB: cells where you haven't specified an xf index manually as
        #     above will have an xf index of 0:
        compare(book.sheet_by_index(0).cell(0,1).xf_index,0)
        # and no matching style:
        should_raise(book.xf_list,IndexError)[0]

        r(f)
        
        compare([
            ('start', (), {}),
            ('workbook',(C('xlutils.tests.fixtures.DummyBook'), 'test.xls'),{}),
            ('sheet', (C('xlrd.sheet.Sheet'), 'Sheet1'), {}),
            ('row', (0, 0), {}),
            ('cell', (0, 0, 0, 0), {}),
            ('cell', (0, 1, 0, 1), {}),
            ('finish', (), {})],f.method_calls)

        compare(book.sheet_by_index(0).cell(0,0).xf_index,42)
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:31,代码来源:test_filter.py


示例6: test_wrong_exception

 def test_wrong_exception(self):
     def to_test():
         raise ValueError('bar')
     with ShouldAssert(
         "ValueError('foo',) (expected) != ValueError('bar',) (raised)"
     ):
         should_raise(ValueError('foo'))(to_test)()
开发者ID:nebulans,项目名称:testfixtures,代码行数:7,代码来源:test_should_raise.py


示例7: test_kw_to_args

 def test_kw_to_args(self):
     def to_test(x):
         raise ValueError('%s'%x)
     should_raise(
         to_test,
         ValueError('1')
         )(x=1)
开发者ID:cart0113,项目名称:testfixtures,代码行数:7,代码来源:test_should_raise.py


示例8: test_no_supplied_or_raised

 def test_no_supplied_or_raised(self):
     # effectvely we're saying "something should be raised!"
     # but we want to inspect s.raised rather than making
     # an up-front assertion
     def to_test():
         pass
     with ShouldAssert("No exception raised!"):
         should_raise()(to_test)()
开发者ID:Simplistix,项目名称:testfixtures,代码行数:8,代码来源:test_should_raise.py


示例9: test_method_args

 def test_method_args(self):
     class X:
         def to_test(self, *args):
             self.args = args
             raise ValueError()
     x = X()
     should_raise(ValueError)(x.to_test)(1, 2, 3)
     self.assertEqual(x.args, (1, 2, 3))
开发者ID:Simplistix,项目名称:testfixtures,代码行数:8,代码来源:test_should_raise.py


示例10: test_method_kw

 def test_method_kw(self):
     class X:
         def to_test(self, **kw):
             self.kw = kw
             raise ValueError()
     x = X()
     should_raise(ValueError)(x.to_test)(x=1, y=2)
     self.assertEqual(x.kw, {'x': 1, 'y': 2})
开发者ID:Simplistix,项目名称:testfixtures,代码行数:8,代码来源:test_should_raise.py


示例11: test_empty_sheet_name

 def test_empty_sheet_name(self):
     r = TestReader(
         ('',([['S1R0C0']]),),
         )
     book = tuple(r.get_workbooks())[0][0]
     # fire methods on writer
     should_raise(r,ValueError(
         'Empty sheet name will result in invalid Excel file!'
         ))(TestWriter())
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:9,代码来源:test_filter.py


示例12: test_wrong_exception

 def test_wrong_exception(self):
     def to_test():
         raise ValueError('bar')
     if PY_37_PLUS:
         expected = "ValueError('foo') (expected) != ValueError('bar') (raised)"
     else:
         expected = "ValueError('foo',) (expected) != ValueError('bar',) (raised)"
     with ShouldAssert(expected):
         should_raise(ValueError('foo'))(to_test)()
开发者ID:Simplistix,项目名称:testfixtures,代码行数:9,代码来源:test_should_raise.py


示例13: test_not_there

    def test_not_there(self):

        o = object()

        @replace("testfixtures.tests.sample1.bad", o)
        def test_something(r):
            pass  # pragma: no cover

        should_raise(test_something, AttributeError("Original 'bad' not found"))()
开发者ID:yoyossy,项目名称:testfixtures__Simplistix,代码行数:9,代码来源:test_replace.py


示例14: test_wrong_exception

 def test_wrong_exception(self):
     def to_test():
         raise ValueError('bar')
     try:
         should_raise(to_test,ValueError('foo'))()
     except AssertionError,e:
         self.assertEqual(
             e,
             C(AssertionError("ValueError('bar',) raised, ValueError('foo',) expected"))
             )
开发者ID:yoyossy,项目名称:testfixtures__Simplistix,代码行数:10,代码来源:test_should_raise.py


示例15: test_no_exception

 def test_no_exception(self):
     def to_test():
         pass
     try:
         should_raise(to_test,ValueError())()
     except AssertionError,e:
         self.assertEqual(
             e,
             C(AssertionError('None raised, ValueError() expected'))
             )
开发者ID:yoyossy,项目名称:testfixtures__Simplistix,代码行数:10,代码来源:test_should_raise.py


示例16: test_method_both

 def test_method_both(self):
     class X:
         def to_test(self, *args, **kw):
             self.args = args
             self.kw = kw
             raise ValueError()
     x = X()
     should_raise(ValueError)(x.to_test)(1, y=2)
     self.assertEqual(x.args, (1, ))
     self.assertEqual(x.kw, {'y': 2})
开发者ID:Simplistix,项目名称:testfixtures,代码行数:10,代码来源:test_should_raise.py


示例17: test_excessive_length_sheet_name

 def test_excessive_length_sheet_name(self):
     r = TestReader(
         ('X'*32,([['S1R0C0']]),),
         )
     book = tuple(r.get_workbooks())[0][0]
     # fire methods on writer
     should_raise(r,ValueError(
         'Sheet name cannot be more than 31 characters long, '
         'supplied name was 32 characters long!'
         ))(TestWriter())
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:10,代码来源:test_filter.py


示例18: test_bogus_sheet_name

 def test_bogus_sheet_name(self):
     r = TestReader(
         ('sheet',([['S1R0C0']]),),
         ('Sheet',([['S2R0C0']]),),
         )
     book = tuple(r.get_workbooks())[0][0]
     # fire methods on writer
     should_raise(r,ValueError(
         "A sheet named 'sheet' has already been added!"
         ))(TestWriter())
开发者ID:policy-innovations,项目名称:survey-tracker,代码行数:10,代码来源:test_filter.py


示例19: test_wrong_exception_class

 def test_wrong_exception_class(self):
     def to_test():
         raise ValueError('bar')
     if PY3:
         message = ("<class 'KeyError'> (expected) != "
                    "ValueError('bar',) (raised)")
     else:
         message = ("<type 'exceptions.KeyError'> (expected) != "
                    "ValueError('bar',) (raised)")
     with ShouldAssert(message):
         should_raise(KeyError)(to_test)()
开发者ID:nebulans,项目名称:testfixtures,代码行数:11,代码来源:test_should_raise.py


示例20: test_wrong_exception

 def test_wrong_exception(self):
     def to_test():
         raise ValueError('bar')
     try:
         should_raise(ValueError('foo'))(to_test)()
     except AssertionError as e:
         self.assertEqual(
             e,
             C(AssertionError("ValueError('bar',) raised, ValueError('foo',) expected"))
             )
     else:
         self.fail('No exception raised!')
开发者ID:B-Rich,项目名称:testfixtures,代码行数:12,代码来源:test_should_raise.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python testfixtures.LogCapture类代码示例发布时间:2022-05-27
下一篇:
Python testfixtures.generator函数代码示例发布时间: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