diff options
| author | Matti Picus <matti.picus@gmail.com> | 2014-03-02 17:33:33 +0200 |
|---|---|---|
| committer | Matti Picus <matti.picus@gmail.com> | 2014-03-02 17:33:33 +0200 |
| commit | dc7ee4dc153b181165da10d645f6eb32e00de0d4 (patch) | |
| tree | 3dc2d079de0395542294036a359c5fcb8510f105 | |
| parent | 067f25f29f990feb266e48d69e4398d027bbe13f (diff) | |
| download | cffi-dc7ee4dc153b181165da10d645f6eb32e00de0d4.tar.gz | |
fix for win32
| -rw-r--r-- | testing/test_function.py | 26 | ||||
| -rw-r--r-- | testing/test_parsing.py | 14 | ||||
| -rw-r--r-- | testing/test_unicode_literals.py | 9 | ||||
| -rw-r--r-- | testing/test_verify.py | 13 | ||||
| -rw-r--r-- | testing/test_zdistutils.py | 29 |
5 files changed, 60 insertions, 31 deletions
diff --git a/testing/test_function.py b/testing/test_function.py index 4ff2efa..85180bf 100644 --- a/testing/test_function.py +++ b/testing/test_function.py @@ -34,6 +34,12 @@ class FdWriteCapture(object): def getvalue(self): return self._value +lib_m = 'm' +if sys.platform == 'win32': + #there is a small chance this fails on Mingw via environ $CC + import distutils.ccompiler + if distutils.ccompiler.get_default_compiler() == 'msvc': + lib_m = 'msvcrt' class TestFunction(object): Backend = CTypesBackend @@ -43,18 +49,16 @@ class TestFunction(object): ffi.cdef(""" double sin(double x); """) - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) x = m.sin(1.23) assert x == math.sin(1.23) def test_sinf(self): - if sys.platform == 'win32': - py.test.skip("no 'sinf'") ffi = FFI(backend=self.Backend()) ffi.cdef(""" float sinf(float x); """) - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) x = m.sinf(1.23) assert type(x) is float assert x != math.sin(1.23) # rounding effects @@ -66,14 +70,14 @@ class TestFunction(object): ffi.cdef(""" void sin(double x); """) - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) x = m.sin(1.23) assert x is None def test_dlopen_filename(self): - path = ctypes.util.find_library("m") + path = ctypes.util.find_library(lib_m) if not path: - py.test.skip("libm not found") + py.test.skip("%s not found" % lib_m) ffi = FFI(backend=self.Backend()) ffi.cdef(""" double cos(double x); @@ -91,7 +95,7 @@ class TestFunction(object): ffi.cdef(""" double cos(double x); """) - m = ffi.dlopen("m", ffi.RTLD_LAZY | ffi.RTLD_LOCAL) + m = ffi.dlopen(lib_m, ffi.RTLD_LAZY | ffi.RTLD_LOCAL) x = m.cos(1.23) assert x == math.cos(1.23) @@ -292,7 +296,7 @@ class TestFunction(object): typedef double func_t(double); func_t sin; """) - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) x = m.sin(1.23) assert x == math.sin(1.23) @@ -355,7 +359,7 @@ class TestFunction(object): ffi.cdef(""" int nonexistent(); """) - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) assert not hasattr(m, 'nonexistent') def test_wraps_from_stdlib(self): @@ -369,7 +373,7 @@ class TestFunction(object): def wrapper(*args): return f(*args) + 100 return wrapper - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) sin100 = my_decorator(m.sin) x = sin100(1.23) assert x == math.sin(1.23) + 100 diff --git a/testing/test_parsing.py b/testing/test_parsing.py index 7d5cdd7..3b59a69 100644 --- a/testing/test_parsing.py +++ b/testing/test_parsing.py @@ -36,7 +36,7 @@ class FakeBackend(object): totalsize=-1, totalalignment=-1, sflags=0): assert isinstance(s, FakeStruct) s.fields = fields - + def new_array_type(self, ptrtype, length): return FakeType('<array %s x %s>' % (ptrtype, length)) @@ -60,7 +60,7 @@ class FakeStruct(object): return ', '.join([str(y) + str(x) for x, y, z in self.fields]) class FakeLibrary(object): - + def load_function(self, BType, name): return FakeFunction(BType, name) @@ -70,11 +70,17 @@ class FakeFunction(object): self.BType = str(BType) self.name = name +lib_m = "m" +if sys.platform == 'win32': + #there is a small chance this fails on Mingw via environ $CC + import distutils.ccompiler + if distutils.ccompiler.get_default_compiler() == 'msvc': + lib_m = 'msvcrt' def test_simple(): ffi = FFI(backend=FakeBackend()) ffi.cdef("double sin(double x);") - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) func = m.sin # should be a callable on real backends assert func.name == 'sin' assert func.BType == '<func (<double>), <double>, False>' @@ -148,7 +154,7 @@ def test_remove_comments(): x, double/*several*//*comment*/y) /*on the same line*/ ; """) - m = ffi.dlopen("m") + m = ffi.dlopen(lib_m) func = m.sin assert func.name == 'sin' assert func.BType == '<func (<double>, <double>), <double>, False>' diff --git a/testing/test_unicode_literals.py b/testing/test_unicode_literals.py index 90902a4..7b0a5cc 100644 --- a/testing/test_unicode_literals.py +++ b/testing/test_unicode_literals.py @@ -10,6 +10,13 @@ from __future__ import unicode_literals import sys, math from cffi import FFI +lib_m = "m" +if sys.platform == 'win32': + #there is a small chance this fails on Mingw via environ $CC + import distutils.ccompiler + if distutils.ccompiler.get_default_compiler() == 'msvc': + lib_m = 'msvcrt' + def test_cast(): ffi = FFI() @@ -55,7 +62,7 @@ def test_enum(): def test_dlopen(): ffi = FFI() ffi.cdef("double sin(double x);") - m = ffi.dlopen("m") # unicode literal + m = ffi.dlopen(lib_m) # unicode literal x = m.sin(1.23) assert x == math.sin(1.23) diff --git a/testing/test_verify.py b/testing/test_verify.py index 853004a..ac0aaa4 100644 --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -4,7 +4,12 @@ from cffi import FFI, VerificationError, VerificationMissing, model from testing.support import * +lib_m = ['m'] if sys.platform == 'win32': + #there is a small chance this fails on Mingw via environ $CC + import distutils.ccompiler + if distutils.ccompiler.get_default_compiler() == 'msvc': + lib_m = ['msvcrt'] pass # no obvious -Werror equivalent on MSVC else: if (sys.platform == 'darwin' and @@ -63,13 +68,13 @@ def test_missing_function_import_error(): def test_simple_case(): ffi = FFI() ffi.cdef("double sin(double x);") - lib = ffi.verify('#include <math.h>', libraries=["m"]) + lib = ffi.verify('#include <math.h>', libraries=lib_m) assert lib.sin(1.23) == math.sin(1.23) def test_rounding_1(): ffi = FFI() ffi.cdef("float sin(double x);") - lib = ffi.verify('#include <math.h>', libraries=["m"]) + lib = ffi.verify('#include <math.h>', libraries=lib_m) res = lib.sin(1.23) assert res != math.sin(1.23) # not exact, because of double->float assert abs(res - math.sin(1.23)) < 1E-5 @@ -77,7 +82,7 @@ def test_rounding_1(): def test_rounding_2(): ffi = FFI() ffi.cdef("double sin(float x);") - lib = ffi.verify('#include <math.h>', libraries=["m"]) + lib = ffi.verify('#include <math.h>', libraries=lib_m) res = lib.sin(1.23) assert res != math.sin(1.23) # not exact, because of double->float assert abs(res - math.sin(1.23)) < 1E-5 @@ -103,7 +108,7 @@ def test_strlen_array_of_char(): def test_longdouble(): ffi = FFI() ffi.cdef("long double sinl(long double x);") - lib = ffi.verify('#include <math.h>', libraries=["m"]) + lib = ffi.verify('#include <math.h>', libraries=lib_m) for input in [1.23, ffi.cast("double", 1.23), ffi.cast("long double", 1.23)]: diff --git a/testing/test_zdistutils.py b/testing/test_zdistutils.py index 2137a89..f97d015 100644 --- a/testing/test_zdistutils.py +++ b/testing/test_zdistutils.py @@ -7,6 +7,13 @@ from testing.udir import udir class DistUtilsTest(object): + def setup_class(self): + self.lib_m = "m" + if sys.platform == 'win32': + #there is a small chance this fails on Mingw via environ $CC + import distutils.ccompiler + if distutils.ccompiler.get_default_compiler() == 'msvc': + self.lib_m = 'msvcrt' def test_locate_engine_class(self): cls = _locate_engine_class(FFI(), self.generic) @@ -26,7 +33,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there %s!*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) v.write_source() with open(v.sourcefilename, 'r') as f: data = f.read() @@ -37,7 +44,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there %s!*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) v.sourcefilename = filename = str(udir.join('write_source.c')) v.write_source() assert filename == v.sourcefilename @@ -50,7 +57,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there %s!*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) try: from StringIO import StringIO except ImportError: @@ -64,7 +71,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there %s!*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) v.compile_module() assert v.get_module_name().startswith('_cffi_') if v.generates_python_module(): @@ -76,7 +83,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there %s!2*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) basename = self.__class__.__name__ + 'test_compile_module' v.modulefilename = filename = str(udir.join(basename + '.so')) v.compile_module() @@ -93,7 +100,7 @@ class DistUtilsTest(object): ffi.cdef("%s sin(double x);" % csrc) v = Verifier(ffi, "#include <math.h>", force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) names.append(v.get_module_name()) assert names[0] == names[1] != names[2] @@ -111,7 +118,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there %s!3*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) library = v.load_library() assert library.sin(12.3) == math.sin(12.3) @@ -122,7 +129,7 @@ class DistUtilsTest(object): udir.join('test_verifier_args.h').write('#include <math.h>\n') v = Verifier(ffi, csrc, include_dirs=[str(udir)], force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) library = v.load_library() assert library.sin(12.3) == math.sin(12.3) @@ -131,7 +138,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = "/*6%s*/\n#include <math.h>" % self lib = ffi.verify(csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) assert lib.sin(12.3) == math.sin(12.3) assert isinstance(ffi.verifier, Verifier) with open(ffi.verifier.sourcefilename, 'r') as f: @@ -149,7 +156,7 @@ class DistUtilsTest(object): ''' lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')], force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) assert lib.sin(12.3) == math.sin(12.3) v = ffi.verifier ext = v.get_extension() @@ -163,7 +170,7 @@ class DistUtilsTest(object): ffi.cdef("double sin(double x);") csrc = '/*hi there9!%s*/\n#include <math.h>\n' % self v = Verifier(ffi, csrc, force_generic_engine=self.generic, - libraries=["m"]) + libraries=[self.lib_m]) assert not os.path.exists(v.sourcefilename) v.get_extension() assert os.path.exists(v.sourcefilename) |
