Commit 144c66ee authored by Craig Citro's avatar Craig Citro

merge

parents 34741cc4 1dcb8c52
...@@ -28,8 +28,8 @@ from distutils.core import Extension ...@@ -28,8 +28,8 @@ from distutils.core import Extension
from distutils.command.build_ext import build_ext as _build_ext from distutils.command.build_ext import build_ext as _build_ext
distutils_distro = Distribution() distutils_distro = Distribution()
TEST_DIRS = ['compile', 'errors', 'run', 'pyregr'] TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr']
TEST_RUN_DIRS = ['run', 'pyregr'] TEST_RUN_DIRS = ['run', 'wrappers', 'pyregr']
# Lists external modules, and a matcher matching tests # Lists external modules, and a matcher matching tests
# which should be excluded if the module is not present. # which should be excluded if the module is not present.
...@@ -200,10 +200,10 @@ class TestBuilder(object): ...@@ -200,10 +200,10 @@ class TestBuilder(object):
fork=self.fork) fork=self.fork)
class CythonCompileTestCase(unittest.TestCase): class CythonCompileTestCase(unittest.TestCase):
def __init__(self, directory, workdir, module, language='c', def __init__(self, test_directory, workdir, module, language='c',
expect_errors=False, annotate=False, cleanup_workdir=True, expect_errors=False, annotate=False, cleanup_workdir=True,
cleanup_sharedlibs=True, cython_only=False, fork=True): cleanup_sharedlibs=True, cython_only=False, fork=True):
self.directory = directory self.test_directory = test_directory
self.workdir = workdir self.workdir = workdir
self.module = module self.module = module
self.language = language self.language = language
...@@ -257,8 +257,8 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -257,8 +257,8 @@ class CythonCompileTestCase(unittest.TestCase):
self.runCompileTest() self.runCompileTest()
def runCompileTest(self): def runCompileTest(self):
self.compile(self.directory, self.module, self.workdir, self.compile(self.test_directory, self.module, self.workdir,
self.directory, self.expect_errors, self.annotate) self.test_directory, self.expect_errors, self.annotate)
def find_module_source_file(self, source_file): def find_module_source_file(self, source_file):
if not os.path.exists(source_file): if not os.path.exists(source_file):
...@@ -269,8 +269,15 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -269,8 +269,15 @@ class CythonCompileTestCase(unittest.TestCase):
target = '%s.%s' % (module_name, self.language) target = '%s.%s' % (module_name, self.language)
return target return target
def split_source_and_output(self, directory, module, workdir): def find_source_files(self, test_directory, module_name):
source_file = os.path.join(directory, module) + '.pyx' is_related = re.compile('%s_.*[.]%s' % (module_name, self.language)).match
return [self.build_target_filename(module_name)] + [
os.path.join(test_directory, filename)
for filename in os.listdir(test_directory)
if is_related(filename) and os.path.isfile(os.path.join(test_directory, filename)) ]
def split_source_and_output(self, test_directory, module, workdir):
source_file = os.path.join(test_directory, module) + '.pyx'
source_and_output = codecs.open( source_and_output = codecs.open(
self.find_module_source_file(source_file), 'rU', 'ISO-8859-1') self.find_module_source_file(source_file), 'rU', 'ISO-8859-1')
out = codecs.open(os.path.join(workdir, module + '.pyx'), out = codecs.open(os.path.join(workdir, module + '.pyx'),
...@@ -289,12 +296,12 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -289,12 +296,12 @@ class CythonCompileTestCase(unittest.TestCase):
else: else:
return geterrors() return geterrors()
def run_cython(self, directory, module, targetdir, incdir, annotate): def run_cython(self, test_directory, module, targetdir, incdir, annotate):
include_dirs = INCLUDE_DIRS[:] include_dirs = INCLUDE_DIRS[:]
if incdir: if incdir:
include_dirs.append(incdir) include_dirs.append(incdir)
source = self.find_module_source_file( source = self.find_module_source_file(
os.path.join(directory, module + '.pyx')) os.path.join(test_directory, module + '.pyx'))
target = os.path.join(targetdir, self.build_target_filename(module)) target = os.path.join(targetdir, self.build_target_filename(module))
options = CompilationOptions( options = CompilationOptions(
pyrex_default_options, pyrex_default_options,
...@@ -309,7 +316,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -309,7 +316,7 @@ class CythonCompileTestCase(unittest.TestCase):
cython_compile(source, options=options, cython_compile(source, options=options,
full_module_name=module) full_module_name=module)
def run_distutils(self, module, workdir, incdir): def run_distutils(self, test_directory, module, workdir, incdir):
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(workdir) os.chdir(workdir)
try: try:
...@@ -324,7 +331,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -324,7 +331,7 @@ class CythonCompileTestCase(unittest.TestCase):
ext_include_dirs += get_additional_include_dirs() ext_include_dirs += get_additional_include_dirs()
extension = Extension( extension = Extension(
module, module,
sources = [self.build_target_filename(module)], sources = self.find_source_files(test_directory, module),
include_dirs = ext_include_dirs, include_dirs = ext_include_dirs,
extra_compile_args = CFLAGS, extra_compile_args = CFLAGS,
) )
...@@ -337,19 +344,19 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -337,19 +344,19 @@ class CythonCompileTestCase(unittest.TestCase):
finally: finally:
os.chdir(cwd) os.chdir(cwd)
def compile(self, directory, module, workdir, incdir, def compile(self, test_directory, module, workdir, incdir,
expect_errors, annotate): expect_errors, annotate):
expected_errors = errors = () expected_errors = errors = ()
if expect_errors: if expect_errors:
expected_errors = self.split_source_and_output( expected_errors = self.split_source_and_output(
directory, module, workdir) test_directory, module, workdir)
directory = workdir test_directory = workdir
if WITH_CYTHON: if WITH_CYTHON:
old_stderr = sys.stderr old_stderr = sys.stderr
try: try:
sys.stderr = ErrorWriter() sys.stderr = ErrorWriter()
self.run_cython(directory, module, workdir, incdir, annotate) self.run_cython(test_directory, module, workdir, incdir, annotate)
errors = sys.stderr.geterrors() errors = sys.stderr.geterrors()
finally: finally:
sys.stderr = old_stderr sys.stderr = old_stderr
...@@ -373,7 +380,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -373,7 +380,7 @@ class CythonCompileTestCase(unittest.TestCase):
raise raise
else: else:
if not self.cython_only: if not self.cython_only:
self.run_distutils(module, workdir, incdir) self.run_distutils(test_directory, module, workdir, incdir)
class CythonRunTestCase(CythonCompileTestCase): class CythonRunTestCase(CythonCompileTestCase):
def shortDescription(self): def shortDescription(self):
......
...@@ -10,3 +10,5 @@ cfunc_call_tuple_args_T408 ...@@ -10,3 +10,5 @@ cfunc_call_tuple_args_T408
cascaded_list_unpacking_T467 cascaded_list_unpacking_T467
compile.cpp_operators compile.cpp_operators
cpp_nested_templates cpp_nested_templates
cppwrap
cpp_overload_wrapper
cimport cppwrap_lib
cdef class DoubleKeeper:
cdef cppwrap_lib.DoubleKeeper* keeper
def __cinit__(self, number=None):
if number is None:
self.keeper = new cppwrap_lib.DoubleKeeper()
else:
self.keeper = new cppwrap_lib.DoubleKeeper(number)
def __dealloc__(self):
del self.keeper
def set_number(self, number=None):
if number is None:
self.keeper.set_number()
else:
self.keeper.set_number(number)
def get_number(self):
return self.keeper.get_number()
def transmogrify(self, double value):
return self.keeper.transmogrify(value)
def voidfunc():
cppwrap_lib.voidfunc()
def doublefunc(double x, double y, double z):
return cppwrap_lib.doublefunc(x, y, z)
def transmogrify_from_cpp(DoubleKeeper obj not None, double value):
return cppwrap_lib.transmogrify_from_cpp(obj.keeper, value)
#include "cppwrap_lib.h"
void voidfunc (void)
{
}
double doublefunc (double a, double b, double c)
{
return a + b + c;
}
DoubleKeeper::DoubleKeeper ()
: number (1.0)
{
}
DoubleKeeper::DoubleKeeper (double factor)
: number (factor)
{
}
DoubleKeeper::~DoubleKeeper ()
{
}
double DoubleKeeper::get_number () const
{
return number;
}
void DoubleKeeper::set_number (double f)
{
number = f;
}
void DoubleKeeper::set_number ()
{
number = 1.0;
}
double
DoubleKeeper::transmogrify (double value) const
{
return value*number;
}
double
transmogrify_from_cpp (DoubleKeeper const *obj, double value)
{
return obj->transmogrify (value);
}
void voidfunc(void);
double doublefunc (double a, double b, double c);
class DoubleKeeper
{
double number;
public:
DoubleKeeper ();
DoubleKeeper (double number);
virtual ~DoubleKeeper ();
void set_number (double num);
void set_number (void);
double get_number () const;
virtual double transmogrify (double value) const;
};
double transmogrify_from_cpp (DoubleKeeper const *obj, double value);
cdef extern from "testapi.h":
void voidfunc()
double doublefunc(double a, double b, double c)
cdef cppclass DoubleKeeper:
DoubleKeeper()
DoubleKeeper(double factor)
void set_number()
void set_number(double f)
double get_number()
double transmogrify(double value)
double transmogrify_from_cpp (DoubleKeeper *obj, double value)
cimport cppwrap_lib
cdef class DoubleKeeper:
cdef cppwrap_lib.DoubleKeeper* keeper
def __cinit__(self, double number):
self.keeper = new cppwrap_lib.DoubleKeeper(number)
def __dealloc__(self):
del self.keeper
def set_number(self, double number):
self.keeper.set_number(number)
def get_number(self):
return self.keeper.get_number()
def transmogrify(self, double value):
return self.keeper.transmogrify(value)
def voidfunc():
cppwrap_lib.voidfunc()
def doublefunc(double x, double y, double z):
return cppwrap_lib.doublefunc(x, y, z)
def transmogrify_from_cpp(DoubleKeeper obj not None, double value):
return cppwrap_lib.transmogrify_from_cpp(obj.keeper, value)
#include "cppwrap_lib.h"
void voidfunc (void)
{
}
double doublefunc (double a, double b, double c)
{
return a + b + c;
}
DoubleKeeper::DoubleKeeper ()
: number (1.0)
{
}
DoubleKeeper::DoubleKeeper (double factor)
: number (factor)
{
}
DoubleKeeper::~DoubleKeeper ()
{
}
double DoubleKeeper::get_number () const
{
return number;
}
void DoubleKeeper::set_number (double f)
{
number = f;
}
void DoubleKeeper::set_number ()
{
number = 1.0;
}
double
DoubleKeeper::transmogrify (double value) const
{
return value*number;
}
double
transmogrify_from_cpp (DoubleKeeper const *obj, double value)
{
return obj->transmogrify (value);
}
void voidfunc(void);
double doublefunc (double a, double b, double c);
class DoubleKeeper
{
double number;
public:
DoubleKeeper (double number);
virtual ~DoubleKeeper ();
void set_number (double num);
double get_number () const;
virtual double transmogrify (double value) const;
};
double transmogrify_from_cpp (DoubleKeeper const *obj, double value);
cdef extern from "testapi.h":
void voidfunc()
double doublefunc(double a, double b, double c)
cdef cppclass DoubleKeeper:
DoubleKeeper(double factor)
void set_number(double f)
double get_number()
double transmogrify(double value)
double transmogrify_from_cpp (DoubleKeeper *obj, double value)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment