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


Python testfixtures.should_raise函数代码示例

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


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


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