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_syntax(pyversion):
executable = py.path.local.sysfind("python" + pyversion)
if executable is None:
py.test.skip("no python%s found" % (pyversion,))
for path, dirs, filenames in os.walk(str(_py_root)):
for fn in filenames:
if fn.endswith(".py"):
full = os.path.join(path, fn)
executable.sysexec(_compile_checker, full)
def test_relative_to():
py.test.skip("not available")
import tempfile, os
from extra_tests.cffi_tests.udir import udir
tmpdir = tempfile.mkdtemp(dir=str(udir))
ffi = FFI()
ffi.cdef("int foo(int);")
f = open(os.path.join(tmpdir, 'foo.h'), 'w')
f.write("int foo(int a) { return a + 42; }\n")
f.close()
lib = ffi.verify('#include "foo.h"',
include_dirs=['.'],
relative_to=os.path.join(tmpdir, 'x'))
assert lib.foo(100) == 142
def test_set_py_limited_api(self):
from cffi.setuptools_ext import _set_py_limited_api
try:
import setuptools
except ImportError as e:
py.test.skip(str(e))
orig_version = setuptools.__version__
expecting_limited_api = not hasattr(sys, 'gettotalrefcount')
try:
setuptools.__version__ = '26.0.0'
from setuptools import Extension
kwds = _set_py_limited_api(Extension, {})
assert kwds.get('py_limited_api', False) == expecting_limited_api
setuptools.__version__ = '25.0'
kwds = _set_py_limited_api(Extension, {})
assert kwds.get('py_limited_api', False) == False
setuptools.__version__ = 'development'
kwds = _set_py_limited_api(Extension, {})
assert kwds.get('py_limited_api', False) == expecting_limited_api
def test_dlopen_none():
import _cffi_backend
from re_python_pysrc import ffi
name = None
if sys.platform == 'win32':
import ctypes.util
name = ctypes.util.find_msvcrt()
if name is None:
py.test.skip("dlopen(None) cannot work on Windows with Python 3")
lib = ffi.dlopen(name)
assert lib.strlen(b"hello") == 5
def test_float_strategy(self):
py.test.skip("no special float strategy for now")
output = self.run('''
$a = array();
$a[] = 3.0;
$b = array(1.2, 3.2);
echo $a, $b;
$a[1] = 1.2;
$b[0] = 1;
echo $a, $b;
''')
[i.force_write() for i in output]
assert [i.strategy.name for i in output] == [
'lfloat', 'lfloat', 'lfloat', 'lobject']
assert output[0].strategy.unerase(output[0].storage) == [3.0]
assert output[1].strategy.unerase(output[1].storage) == [1.2, 3.2]
assert output[2].strategy.unerase(output[2].storage) == [3.0, 1.2]
assert self.space.int_w(
def test_termination_on_remote_channel_receive(monkeypatch, makegateway):
if not py.path.local.sysfind("ps"):
py.test.skip("need 'ps' command to externally check process status")
monkeypatch.setenv("EXECNET_DEBUG", "2")
gw = makegateway("popen")
pid = gw.remote_exec("import os ; channel.send(os.getpid())").receive()
gw.remote_exec("channel.receive()")
gw._group.terminate()
command = ["ps", "-p", str(pid)]
popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, err = popen.communicate()
out = py.builtin._totext(out, "utf8")
assert str(pid) not in out, out
import py, os, sys, shutil
import subprocess
from testing.udir import udir
if sys.platform == 'win32':
py.test.skip('snippets do not run on win32')
if sys.version_info < (2, 7):
py.test.skip('fails e.g. on a Debian/Ubuntu which patches virtualenv'
' in a non-2.6-friendly way')
def create_venv(name):
tmpdir = udir.join(name)
try:
subprocess.check_call(['virtualenv',
#'--never-download', <= could be added, but causes failures
# in random cases on random machines
'-p', os.path.abspath(sys.executable),
str(tmpdir)])
except OSError as e:
py.test.skip("Cannot execute virtualenv: %s" % (e,))
site_packages = None
def test_getting_errno(self):
if self.module is None:
py.test.skip("fix the auto-generation of the tiny test lib")
if sys.platform == 'win32':
py.test.skip("fails, errno at multiple addresses")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
int test_getting_errno(void);
""")
ownlib = ffi.dlopen(self.module)
res = ownlib.test_getting_errno()
assert res == -1
assert ffi.errno == 123
def test_move_items_urllib_parse(item_name):
"""Ensure that everything loads correctly."""
if item_name == "ParseResult" and sys.version_info < (2, 5):
py.test.skip("ParseResult is only found on 2.5+")
if item_name in ("parse_qs", "parse_qsl") and sys.version_info < (2, 6):
py.test.skip("parse_qs[l] is new in 2.6")
if sys.version_info[:2] >= (2, 6):
assert item_name in dir(six.moves.urllib.parse)
getattr(six.moves.urllib.parse, item_name)
def test_nested_anonymous_struct_exact_error():
if sys.platform == 'win32':
py.test.skip("nested anonymous struct/union")
ffi = FFI()
ffi.cdef("""
struct foo_s { struct { int a; char b; }; union { char c, d; }; };
""")
py.test.raises(VerificationError, ffi.verify, """
struct foo_s { struct { int a; short b; }; union { char c, d; }; };
""")
py.test.raises(VerificationError, ffi.verify, """
struct foo_s { struct { int a; char e, b; }; union { char c, d; }; };