Did I find the right examples for you? yes no Crawl my project Python Jobs
All Samples(3299) | Call(3146) | Derive(0) | Import(153)
assert that a code block/function call raises @ExpectedException and raise a failure exception otherwise. This helper produces a ``py.code.ExceptionInfo()`` object. If using Python 2.5 or above, you may use this function as a context manager:: >>> with raises(ZeroDivisionError): ... 1/0(more...)
def raises(ExpectedException, *args, **kwargs): """ assert that a code block/function call raises @ExpectedException and raise a failure exception otherwise. This helper produces a ``py.code.ExceptionInfo()`` object. If using Python 2.5 or above, you may use this function as a context manager:: >>> with raises(ZeroDivisionError): ... 1/0 Or you can specify a callable by passing a to-be-called lambda:: >>> raises(ZeroDivisionError, lambda: 1/0)or you can specify an arbitrary callable with arguments:: >>> def f(x): return 1/x ... >>> raises(ZeroDivisionError, f, 0) >>> raises(ZeroDivisionError, f, x=0) A third possibility is to use a string to be executed:: >>> raises(ZeroDivisionError, "f(0)") Performance note: ----------------- Similar to caught exception objects in Python, explicitly clearing local references to returned ``py.code.ExceptionInfo`` objects can help the Python interpreter speed up its garbage collection. Clearing those references breaks a reference cycle (``ExceptionInfo`` --> caught exception --> frame stack raising the exception --> current frame stack --> local variables --> ``ExceptionInfo``) which makes Python keep all objects referenced from that cycle (including all local variables in the current frame) alive until the next cyclic garbage collection run. See the official Python ``try`` statement documentation for more detailed information. """ __tracebackhide__ = True if ExpectedException is AssertionError: # we want to catch a AssertionError # replace our subclass with the builtin one # see https://bitbucket.org/hpk42/pytest/issue/176/pytestraises from _pytest.assertion.util import BuiltinAssertionError as ExpectedException if not args: return RaisesContext(ExpectedException) elif isinstance(args[0], str): code, = args assert isinstance(code, str) frame = sys._getframe(1) loc = frame.f_locals.copy() loc.update(kwargs) #print "raises frame scope: %r" % frame.f_locals try: code = py.code.Source(code).compile() py.builtin.exec_(code, frame.f_globals, loc) # XXX didn'T mean f_globals == f_locals something special? # this is destroyed here ... except ExpectedException: return py.code.ExceptionInfo() else: func = args[0] try: func(*args[1:], **kwargs) except ExpectedException: return py.code.ExceptionInfo() pytest.fail("DID NOT RAISE")
from py.test import raises import py def otherfunc(a,b): assert a==b
def test_raises(self): s = 'qwe' raises(TypeError, "int(s)") def test_raises_doesnt(self): raises(IOError, "int('3')")
src/p/l/plexnet-HEAD/third_party/generic/pypy/pypy/interpreter/test/test_argument.py plexnet(Download)
def test_fixedunpacked(self): space = DummySpace() args = Arguments(space, [], ["k"], [1]) py.test.raises(ValueError, args.fixedunpack, 1) args = Arguments(space, ["a", "b"]) py.test.raises(ValueError, args.fixedunpack, 0) py.test.raises(ValueError, args.fixedunpack, 1) py.test.raises(ValueError, args.fixedunpack, 3)
py.test.raises(ValueError, args.fixedunpack, 1) py.test.raises(ValueError, args.fixedunpack, 3) py.test.raises(ValueError, args.fixedunpack, 4) assert args.fixedunpack(2) == ['a', 'b']
src/s/y/Sypy-HEAD/interpreter/test/test_argument.py Sypy(Download)
def test_fixedunpacked(self): space = DummySpace() args = Arguments(space, [], ["k"], [1]) py.test.raises(ValueError, args.fixedunpack, 1) args = Arguments(space, ["a", "b"]) py.test.raises(ValueError, args.fixedunpack, 0) py.test.raises(ValueError, args.fixedunpack, 1) py.test.raises(ValueError, args.fixedunpack, 3)
py.test.raises(ValueError, args.fixedunpack, 1) py.test.raises(ValueError, args.fixedunpack, 3) py.test.raises(ValueError, args.fixedunpack, 4) assert args.fixedunpack(2) == ['a', 'b']
src/p/l/plexnet-HEAD/third_party/generic/pypy/pypy/lib/test2/test_array.py plexnet(Download)
# minimal tests. See also lib-python/modified-2.4.1/test/test_array. import autopath import py from py.test import raises
assert a.args == ('i', range(10)) assert a.kwds == {'some': 42} raises(TypeError, A) raises(TypeError, A, 42) raises(TypeError, A, 'i', [], []) raises(TypeError, self.array.array, 'i', [], foo='bar')
src/w/h/wheeler.pygtkhelpers-0.5.post1.dev6264335/tests/test_utils.py wheeler.pygtkhelpers(Download)
from py.test import raises as assert_raises import gobject, gtk from pygtkhelpers.utils import gsignal, gproperty, \
class T1(gobject.GObject): __gtype_name__ = 'test1' gsignal('testsignal') gsignal('b', retval=gobject.TYPE_INT) assert_raises(TypeError, gsignal, 'c', retval=gobject.TYPE_INT, flags=gobject.SIGNAL_RUN_FIRST)
__gtype_name__ = 'test2' gproperty('a', int, default=0) assert_raises(TypeError, gproperty, 'b', bool) assert_raises(TypeError, gproperty, 'c', bool, default='a') assert_raises(TypeError, gproperty, 'd', bool, nick=1)
src/p/y/pygtkhelpers-0.4.3/tests/test_utils.py pygtkhelpers(Download)
from py.test import raises as assert_raises import gobject, gtk from pygtkhelpers.utils import gsignal, gproperty, \
class T1(gobject.GObject): __gtype_name__ = 'test1' gsignal('testsignal') gsignal('b', retval=gobject.TYPE_INT) assert_raises(TypeError, gsignal, 'c', retval=gobject.TYPE_INT, flags=gobject.SIGNAL_RUN_FIRST)
__gtype_name__ = 'test2' gproperty('a', int, default=0) assert_raises(TypeError, gproperty, 'b', bool) assert_raises(TypeError, gproperty, 'c', bool, default='a') assert_raises(TypeError, gproperty, 'd', bool, nick=1)
src/s/y/Sypy-HEAD/module/array/test/test_array_old.py Sypy(Download)
# minimal tests. See also lib-python/modified-2.4.1/test/test_array. import py from py.test import raises import struct
assert a.args == ('i', range(10)) assert a.kwds == {'some': 42} raises(TypeError, A) raises(TypeError, A, 42) raises(TypeError, A, 'i', [], []) raises(TypeError, self.array.array, 'i', [], foo='bar')
src/m/o/moingo-HEAD/MoinMoin/_tests/test_wikiutil.py moingo(Download)
def testTooMuchWantedArguments(self): args = 'width=100, height=200, alt=Example' argParser = wikiutil.ParameterParser("%(width)s%(height)s") py.test.raises(ValueError, argParser.parse_parameters, args) def testMalformedArguments(self): args = '=' argParser = wikiutil.ParameterParser("%(width)s%(height)s") py.test.raises(ValueError, argParser.parse_parameters, args)
def testWrongTypeFixedPosArgument(self): args = '0.0' argParser = wikiutil.ParameterParser("%b") py.test.raises(ValueError, argParser.parse_parameters, args) def testWrongTypeNamedArgument(self): args = 'flag=0.0' argParser = wikiutil.ParameterParser("%(flag)b") py.test.raises(ValueError, argParser.parse_parameters, args)
def testUnitArgument(self): result = wikiutil.UnitArgument('7mm', float, ['%', 'mm']) assert result.get_default() == (7.0, 'mm') assert result.parse_argument('8%') == (8.0, '%') py.test.raises(ValueError, result.parse_argument, u'7m')
src/m/o/moingo-HEAD/MoinMoin/events/_tests/test_events.py moingo(Download)
def test_page_change_message(request): page = Page(request, "FrontPage") print "Provided with a dumb change type argument, this should raise an exception!" py.test.raises(notification.UnknownChangeType, notification.page_change_message,
src/p/l/plexnet-HEAD/third_party/generic/pypy/pypy/rpython/ootypesystem/test/test_oortype.py plexnet(Download)
def fn(): return Bar() py.test.raises(AssertionError, gengraph, fn, mangle=False) def test_pbc_record():
return ooupcast(A, c) py.test.raises(AnnotatorError, interpret, fn, [], type_system='ootype') def test_oodowncast():
return oodowncast(A, c) py.test.raises(AnnotatorError, interpret, fn, [], type_system='ootype') def test_method_wrapper():
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next