Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions testing/cffi0/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,18 @@ def test_function_typedef(self):
def test_fputs_custom_FILE(self):
if self.Backend is CTypesBackend:
pytest.skip("FILE not supported with the ctypes backend")
filename = str(udir.join('fputs_custom_FILE'))
temp_file = udir / 'fputs_custom_FILE'
ffi = FFI(backend=self.Backend())
ffi.cdef("int fputs(const char *, FILE *);")
needs_dlopen_none()
C = ffi.dlopen(None)
with open(filename, 'wb') as f:
with temp_file.open('wb') as f:
f.write(b'[')
C.fputs(b"hello from custom file", f)
f.write(b'][')
C.fputs(b"some more output", f)
f.write(b']')
with open(filename, 'rb') as f:
with temp_file.open('rb') as f:
res = f.read()
assert res == b'[hello from custom file][some more output]'

Expand Down
10 changes: 5 additions & 5 deletions testing/cffi0/test_ownlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ class TestOwnLib(object):
def setup_class(cls):
cls.module = None
from testing.udir import udir
udir.join('testownlib.c').write(SOURCE)
(udir / 'testownlib.c').write_text(SOURCE)
if sys.platform == 'win32':
# did we already build it?
if cls.Backend is CTypesBackend:
dll_path = str(udir) + '\\testownlib1.dll' # only ascii for the ctypes backend
dll_path = f"{udir}\\testownlib1.dll" # only ascii for the ctypes backend
else:
dll_path = str(udir) + '\\' + (u+'testownlib\u03be.dll') # non-ascii char
dll_path = f"{udir}\\testownlib\u03be.dll" # non-ascii char
if os.path.exists(dll_path):
cls.module = dll_path
return
Expand All @@ -159,7 +159,7 @@ def setup_class(cls):
cmd = '"%s" %s' % (vcvarsall, arch) + ' & cl.exe testownlib.c ' \
' /LD /Fetestownlib.dll'
subprocess.check_call(cmd, cwd = str(udir), shell=True)
os.rename(str(udir) + '\\testownlib.dll', dll_path)
os.rename(f"{udir}\\testownlib.dll", dll_path)
cls.module = dll_path
else:
encoded = None
Expand All @@ -177,7 +177,7 @@ def setup_class(cls):
subprocess.check_call(
"cc testownlib.c -shared -fPIC -o '%s.so'" % (encoded,),
cwd=str(udir), shell=True)
cls.module = os.path.join(str(udir), unicode_name + (u+'.so'))
cls.module = f"{udir / unicode_name}.so"
print(repr(cls.module))

def test_getting_errno(self):
Expand Down
37 changes: 19 additions & 18 deletions testing/cffi0/test_zdistutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def setup_class(self):
self.lib_m = 'msvcrt'

def teardown_class(self):
if udir.isdir():
udir.remove(ignore_errors=True)
udir.ensure(dir=1)
if udir.is_dir():
shutil.rmtree(udir)
udir.mkdir()

def test_locate_engine_class(self):
cls = _locate_engine_class(FFI(), self.generic)
Expand Down Expand Up @@ -55,12 +55,11 @@ def test_write_source_explicit_filename(self):
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
libraries=[self.lib_m])
v.sourcefilename = filename = str(udir.join('write_source.c'))
source_file = udir / 'write_source.c'
v.sourcefilename = str(source_file)
v.write_source()
assert filename == v.sourcefilename
with open(filename, 'r') as f:
data = f.read()
assert csrc in data
assert str(source_file) == v.sourcefilename
assert csrc in source_file.read_text()

def test_write_source_to_file_obj(self):
ffi = FFI()
Expand Down Expand Up @@ -95,9 +94,10 @@ def test_compile_module_explicit_filename(self):
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
libraries=[self.lib_m])
basename = self.__class__.__name__[:10] + '_test_compile_module'
v.modulefilename = filename = str(udir.join(basename + '.so'))
module_file = udir / (basename + '.so')
v.modulefilename = str(module_file)
v.compile_module()
assert filename == v.modulefilename
assert str(module_file) == v.modulefilename
assert v.get_module_name() == basename
if v.generates_python_module():
mod = load_dynamic(v.get_module_name(), v.modulefilename)
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_verifier_args(self):
ffi = FFI()
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!4*/#include "test_verifier_args.h"\n' % self
udir.join('test_verifier_args.h').write('#include <math.h>\n')
(udir / 'test_verifier_args.h').write_text('#include <math.h>\n')
v = Verifier(ffi, csrc, include_dirs=[str(udir)],
force_generic_engine=self.generic,
libraries=[self.lib_m])
Expand Down Expand Up @@ -189,21 +189,21 @@ def test_extension_forces_write_source(self):
def test_extension_object_extra_sources(self):
ffi = FFI()
ffi.cdef("double test1eoes(double x);")
extra_source = str(udir.join('extension_extra_sources.c'))
with open(extra_source, 'w') as f:
f.write('double test1eoes(double x) { return x * 6.0; }\n')
extra_source = udir / 'extension_extra_sources.c'
extra_source.write_text(
'double test1eoes(double x) { return x * 6.0; }\n')
csrc = '/*9%s*/' % self + '''
double test1eoes(double x); /* or #include "extra_sources.h" */
'''
lib = ffi.verify(csrc, sources=[extra_source],
lib = ffi.verify(csrc, sources=[str(extra_source)],
force_generic_engine=self.generic)
assert lib.test1eoes(7.0) == 42.0
v = ffi.verifier
ext = v.get_extension()
assert 'distutils.extension.Extension' in str(ext.__class__) or \
'setuptools.extension.Extension' in str(ext.__class__)
assert ext.sources == [maybe_relative_path(v.sourcefilename),
extra_source]
str(extra_source)]
assert ext.name == v.get_module_name()

def test_install_and_reload_module(self, targetpackage='', ext_package=''):
Expand All @@ -212,7 +212,8 @@ def test_install_and_reload_module(self, targetpackage='', ext_package=''):
pytest.skip("test requires os.fork()")

if targetpackage:
udir.ensure(targetpackage, dir=1).ensure('__init__.py')
(udir / targetpackage).mkdir(exist_ok=True)
(udir / targetpackage / "__init__.py").touch(exist_ok=True)
sys.path.insert(0, str(udir))

def make_ffi(**verifier_args):
Expand All @@ -232,7 +233,7 @@ def make_ffi(**verifier_args):
assert lib.test1iarm(1.5) == 63.0
# "install" the module by moving it into udir (/targetpackage)
if targetpackage:
target = udir.join(targetpackage)
target = udir / targetpackage
else:
target = udir
shutil.move(ffi.verifier.modulefilename, str(target))
Expand Down
37 changes: 19 additions & 18 deletions testing/cffi0/test_zintegration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import py, os, sys, shutil
import os, sys, shutil
import subprocess
import sysconfig
import textwrap
from pathlib import Path
from testing.udir import udir
import pytest

Expand All @@ -13,7 +14,7 @@
' in a non-2.6-friendly way')

def create_venv(name):
tmpdir = udir.join(name)
tmpdir = udir / name
try:
# FUTURE: we should probably update this to use venv for at least more modern Pythons, and
# install setuptools/pip/etc explicitly for the tests that require them (as venv has stopped including
Expand All @@ -27,7 +28,7 @@ def create_venv(name):
# Newer venv/virtualenv no longer include setuptools by default, which
# breaks a number of these tests; ensure they're always present
subprocess.check_call([
os.path.join(tmpdir, 'bin/python'),
str(tmpdir / 'bin/python'),
'-m',
'pip',
'install',
Expand All @@ -39,8 +40,8 @@ def create_venv(name):
pytest.skip("Cannot execute virtualenv: %s" % (e,))

site_packages = None
for dirpath, dirnames, filenames in os.walk(str(tmpdir)):
if os.path.basename(dirpath) == 'site-packages':
for dirpath, dirnames, filenames in os.walk(tmpdir):
if Path(dirpath).name == 'site-packages':
site_packages = dirpath
break
paths = ""
Expand Down Expand Up @@ -70,27 +71,27 @@ def create_venv(name):
paths = os.pathsep.join(paths)
return tmpdir, paths

SNIPPET_DIR = py.path.local(__file__).join('..', 'snippets')
SNIPPET_DIR = Path(__file__).absolute().parent / 'snippets'

def really_run_setup_and_program(dirname, venv_dir_and_paths, python_snippet):
venv_dir, paths = venv_dir_and_paths
def remove(dir):
dir = str(SNIPPET_DIR.join(dirname, dir))
dir = str(SNIPPET_DIR / dirname / dir)
shutil.rmtree(dir, ignore_errors=True)
remove('build')
remove('__pycache__')
for basedir in os.listdir(str(SNIPPET_DIR.join(dirname))):
remove(os.path.join(basedir, '__pycache__'))
for basedir in (SNIPPET_DIR / dirname).iterdir():
remove(basedir / '__pycache__')
olddir = os.getcwd()
python_f = udir.join('x.py')
python_f.write(textwrap.dedent(python_snippet))
python_f = udir / 'x.py'
python_f.write_text(textwrap.dedent(python_snippet))
try:
os.chdir(str(SNIPPET_DIR.join(dirname)))
os.chdir(str(SNIPPET_DIR / dirname))
if os.name == 'nt':
bindir = 'Scripts'
else:
bindir = 'bin'
vp = str(venv_dir.join(bindir).join('python'))
vp = str(venv_dir / bindir / 'python')
env = os.environ.copy()
env['PYTHONPATH'] = paths
subprocess.check_call((vp, 'setup.py', 'clean'), env=env)
Expand All @@ -114,15 +115,15 @@ def run_setup_and_program(dirname, python_snippet):
del sys._force_generic_engine_
# the two files lextab.py and yacctab.py are created by not-correctly-
# installed versions of pycparser.
assert not os.path.exists(str(SNIPPET_DIR.join(dirname, 'lextab.py')))
assert not os.path.exists(str(SNIPPET_DIR.join(dirname, 'yacctab.py')))
assert not (SNIPPET_DIR / dirname / 'lextab.py').exists()
assert not (SNIPPET_DIR / dirname / 'yacctab.py').exists()

@pytest.mark.thread_unsafe(reason="very slow in parallel")
class TestZIntegration(object):
def teardown_class(self):
if udir.isdir():
udir.remove(ignore_errors=True)
udir.ensure(dir=1)
if udir.is_dir():
shutil.rmtree(udir)
udir.mkdir()

def test_infrastructure(self):
run_setup_and_program('infrastructure', '''
Expand Down
Loading
Loading