Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_samekeyword_twice_raises(self):
py.test.raises(ValueError, "XSpec('popen//popen')")
py.test.raises(ValueError, "XSpec('popen//popen=123')")
if self.Backend is CTypesBackend:
py.test.skip("not with the ctypes backend")
ffi = FFI(backend=self.Backend())
ffi.cdef("int foobar(void); int foobaz;")
lib = ffi.dlopen(lib_m)
ffi.dlclose(lib)
e = py.test.raises(ValueError, ffi.dlclose, lib)
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
e = py.test.raises(ValueError, getattr, lib, 'foobar')
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
e = py.test.raises(ValueError, getattr, lib, 'foobaz')
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
e = py.test.raises(ValueError, setattr, lib, 'foobaz', 42)
assert str(e.value).startswith("library '")
assert str(e.value).endswith("' has already been closed")
def test_failed_get():
bag = Bag(name='bagnine')
with py.test.raises(NoBagError):
store.get(bag)
def test_exe_exists_foo():
with py.test.raises(Exception):
oz.ozutil.executable_exists('foo')
def test_get_method_self():
class X(object):
def m(self):
pass
x = X()
assert six.get_method_self(x.m) is x
py.test.raises(AttributeError, six.get_method_self, 42)
def test_no_cross_include():
baseffi = FFI()
baseffi.set_source('test_no_cross_include_base', "..source..")
#
ffi = FFI()
ffi.include(baseffi)
target = udir.join('test_no_cross_include.py')
py.test.raises(VerificationError, make_py_source,
ffi, 'test_no_cross_include', str(target))
def test_simple_fail_second_start(self, tmpfile):
fd = tmpfile.fileno()
cap = py.io.FDCapture(fd)
f = cap.done()
py.test.raises(ValueError, cap.start)
f.close()
def test_put_no_bag():
tiddler = Tiddler('hi')
with py.test.raises(NoBagError):
store.put(tiddler)
lib.my_value = 42 # [2]
assert values[2] == 42
assert p[-1] == 41
assert p[+1] == 42
#
# if get_my_value raises or returns nonsense, the exception is printed
# to stderr like with any callback, but then the C expression 'my_value'
# expand to '*NULL'. We assume here that '&my_value' will return NULL
# without segfaulting, and check for NULL when accessing the variable.
@ffi.callback("int *(*)(void)")
def get_my_value():
raise LookupError
lib.get_my_value = get_my_value
py.test.raises(ffi.error, getattr, lib, 'my_value')
py.test.raises(ffi.error, setattr, lib, 'my_value', 50)
py.test.raises(ffi.error, ffi.addressof, lib, 'my_value')
@ffi.callback("int *(*)(void)")
def get_my_value():
return "hello"
lib.get_my_value = get_my_value
py.test.raises(ffi.error, getattr, lib, 'my_value')
e = py.test.raises(ffi.error, setattr, lib, 'my_value', 50)
assert str(e.value) == "global variable 'my_value' is at address NULL"
def test_new_handle(self):
ffi = FFI(backend=self.Backend())
o = [2, 3, 4]
p = ffi.new_handle(o)
assert ffi.typeof(p) == ffi.typeof("void *")
assert ffi.from_handle(p) is o
assert ffi.from_handle(ffi.cast("char *", p)) is o
py.test.raises(RuntimeError, ffi.from_handle, ffi.NULL)