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') csrc = '/*9%s*/' % self + ''' double test1eoes(double x); /* or #include "extra_sources.h" */ ''' lib = ffi.verify(csrc, sources=[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__) assert ext.sources == [maybe_relative_path(v.sourcefilename), extra_source] assert ext.name == v.get_module_name()
def test_extension_object(self): ffi = FFI() ffi.cdef("double sin(double x);") csrc = '/*7%s*/' % self + ''' #include <math.h> #ifndef TEST_EXTENSION_OBJECT # error "define_macros missing" #endif ''' lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')], force_generic_engine=self.generic) assert lib.sin(12.3) == math.sin(12.3) v = ffi.verifier ext = v.get_extension() assert 'distutils.extension.Extension' in str(ext.__class__) assert ext.sources == [maybe_relative_path(v.sourcefilename)] assert ext.name == v.get_module_name() assert ext.define_macros == [('TEST_EXTENSION_OBJECT', '1')]
def test_extension_object(self): ffi = FFI() ffi.cdef("double sin(double x);") csrc = '/*7%s*/' % self + ''' #include <math.h> #ifndef TEST_EXTENSION_OBJECT # error "define_macros missing" #endif ''' lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')], force_generic_engine=self.generic, libraries=[self.lib_m]) assert lib.sin(12.3) == math.sin(12.3) v = ffi.verifier ext = v.get_extension() assert 'distutils.extension.Extension' in str(ext.__class__) assert ext.sources == [maybe_relative_path(v.sourcefilename)] assert ext.name == v.get_module_name() assert ext.define_macros == [('TEST_EXTENSION_OBJECT', '1')]
def test_different_absolute(): p = os.path.join('..', 'baz.py') assert maybe_relative_path(p) == p
def test_not_absolute(): assert maybe_relative_path('foo/bar') == 'foo/bar' assert maybe_relative_path('test_platform.py') == 'test_platform.py'
def test_absolute_mapping(): p = os.path.abspath('baz.py') assert maybe_relative_path(p) == 'baz.py' foobaz = os.path.join('foo', 'baz.py') assert maybe_relative_path(os.path.abspath(foobaz)) == foobaz
def test_not_absolute(): assert maybe_relative_path("foo/bar") == "foo/bar" assert maybe_relative_path("test_platform.py") == "test_platform.py"
def test_absolute_mapping(): p = os.path.abspath("baz.py") assert maybe_relative_path(p) == "baz.py" foobaz = os.path.join("foo", "baz.py") assert maybe_relative_path(os.path.abspath(foobaz)) == foobaz
def test_different_absolute(): p = os.path.join("..", "baz.py") assert maybe_relative_path(p) == p