Commit 7ba6c7b8 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2290 from gabrieldemarmiesse/enable_tests_for_documentation

Added tests for the convolve with the memoryviews in the docs.
parents 00d3bbf2 ae0d9040
#include "C_func_file.h"
void multiply_by_10_in_C(double arr[], unsigned int n) void multiply_by_10_in_C(double arr[], unsigned int n)
{ {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
......
#ifndef C_FUNC_FILE_H
#define C_FUNC_FILE_H
void multiply_by_10_in_C(double arr[], unsigned int n);
#endif
# distutils: sources=./C_func_file.c cdef extern from "C_func_file.c":
# distutils: include_dirs=./ # C is include here so that it doesn't need to be compiled externally
pass
cdef extern from "C_func_file.h": cdef extern from "C_func_file.h":
void multiply_by_10_in_C(double *, unsigned int) void multiply_by_10_in_C(double *, unsigned int)
......
...@@ -706,9 +706,10 @@ array with an external C function implemented in :file:`C_func_file.c`: ...@@ -706,9 +706,10 @@ array with an external C function implemented in :file:`C_func_file.c`:
.. literalinclude:: ../../examples/memoryviews/C_func_file.c .. literalinclude:: ../../examples/memoryviews/C_func_file.c
:linenos: :linenos:
This file comes with a header file called :file:`C_func_file.h` containing:: This file comes with a header file called :file:`C_func_file.h` containing:
void multiply_by_10_in_C(double arr[], unsigned int n); .. literalinclude:: ../../examples/memoryviews/C_func_file.h
:linenos:
where ``arr`` points to the array and ``n`` is its size. where ``arr`` points to the array and ``n`` is its size.
......
...@@ -518,28 +518,30 @@ class ErrorWriter(object): ...@@ -518,28 +518,30 @@ class ErrorWriter(object):
class TestBuilder(object): class TestBuilder(object):
def __init__(self, rootdir, workdir, selectors, exclude_selectors, annotate, def __init__(self, rootdir, workdir, selectors, exclude_selectors, options,
cleanup_workdir, cleanup_sharedlibs, cleanup_failures, with_pyregr, languages, test_bugs, language_level,
with_pyregr, cython_only, languages, test_bugs, fork, language_level, common_utility_dir, pythran_dir=None,
test_determinism, default_mode='run',
common_utility_dir, pythran_dir=None): add_embedded_test=False):
self.rootdir = rootdir self.rootdir = rootdir
self.workdir = workdir self.workdir = workdir
self.selectors = selectors self.selectors = selectors
self.exclude_selectors = exclude_selectors self.exclude_selectors = exclude_selectors
self.annotate = annotate self.annotate = options.annotate_source
self.cleanup_workdir = cleanup_workdir self.cleanup_workdir = options.cleanup_workdir
self.cleanup_sharedlibs = cleanup_sharedlibs self.cleanup_sharedlibs = options.cleanup_sharedlibs
self.cleanup_failures = cleanup_failures self.cleanup_failures = options.cleanup_failures
self.with_pyregr = with_pyregr self.with_pyregr = with_pyregr
self.cython_only = cython_only self.cython_only = options.cython_only
self.languages = languages self.languages = languages
self.test_bugs = test_bugs self.test_bugs = test_bugs
self.fork = fork self.fork = options.fork
self.language_level = language_level self.language_level = language_level
self.test_determinism = test_determinism self.test_determinism = options.test_determinism
self.common_utility_dir = common_utility_dir self.common_utility_dir = common_utility_dir
self.pythran_dir = pythran_dir self.pythran_dir = pythran_dir
self.default_mode = default_mode
self.add_embedded_test = add_embedded_test
def build_suite(self): def build_suite(self):
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -554,7 +556,7 @@ class TestBuilder(object): ...@@ -554,7 +556,7 @@ class TestBuilder(object):
continue continue
suite.addTest( suite.addTest(
self.handle_directory(path, filename)) self.handle_directory(path, filename))
if sys.platform not in ['win32']: if sys.platform not in ['win32'] and self.add_embedded_test:
# Non-Windows makefile. # Non-Windows makefile.
if [1 for selector in self.selectors if selector("embedded")] \ if [1 for selector in self.selectors if selector("embedded")] \
and not [1 for selector in self.exclude_selectors if selector("embedded")]: and not [1 for selector in self.exclude_selectors if selector("embedded")]:
...@@ -589,7 +591,7 @@ class TestBuilder(object): ...@@ -589,7 +591,7 @@ class TestBuilder(object):
if match(fqmodule, tags)]: if match(fqmodule, tags)]:
continue continue
mode = 'run' # default mode = self.default_mode
if tags['mode']: if tags['mode']:
mode = tags['mode'][0] mode = tags['mode'][0]
elif context == 'pyregr': elif context == 'pyregr':
...@@ -610,8 +612,10 @@ class TestBuilder(object): ...@@ -610,8 +612,10 @@ class TestBuilder(object):
test_class = CythonUnitTestCase test_class = CythonUnitTestCase
else: else:
test_class = CythonRunTestCase test_class = CythonRunTestCase
else: elif mode in ['compile', 'error', 'test']:
test_class = CythonCompileTestCase test_class = CythonCompileTestCase
else:
raise KeyError('Invalid test mode: ' + mode)
for test in self.build_tests(test_class, path, workdir, for test in self.build_tests(test_class, path, workdir,
module, mode == 'error', tags): module, mode == 'error', tags):
...@@ -1802,6 +1806,9 @@ def main(): ...@@ -1802,6 +1806,9 @@ def main():
parser.add_option("--no-pyregr", dest="pyregr", parser.add_option("--no-pyregr", dest="pyregr",
action="store_false", default=True, action="store_false", default=True,
help="do not run the regression tests of CPython in tests/pyregr/") help="do not run the regression tests of CPython in tests/pyregr/")
parser.add_option("--no-examples", dest="examples",
action="store_false", default=True,
help="Do not run the documentation tests in the examples directory.")
parser.add_option("--cython-only", dest="cython_only", parser.add_option("--cython-only", dest="cython_only",
action="store_true", default=False, action="store_true", default=False,
help="only compile pyx to c, do not run C compiler or run the tests") help="only compile pyx to c, do not run C compiler or run the tests")
...@@ -1858,6 +1865,9 @@ def main(): ...@@ -1858,6 +1865,9 @@ def main():
parser.add_option("--root-dir", dest="root_dir", default=os.path.join(DISTDIR, 'tests'), parser.add_option("--root-dir", dest="root_dir", default=os.path.join(DISTDIR, 'tests'),
help=("Directory to look for the file based " help=("Directory to look for the file based "
"tests (the ones which are deactivated with '--no-file'.")) "tests (the ones which are deactivated with '--no-file'."))
parser.add_option("--examples-dir", dest="examples_dir",
default=os.path.join(DISTDIR, 'docs', 'examples'),
help="working directory")
parser.add_option("--work-dir", dest="work_dir", default=os.path.join(os.getcwd(), 'TEST_TMP'), parser.add_option("--work-dir", dest="work_dir", default=os.path.join(os.getcwd(), 'TEST_TMP'),
help="working directory") help="working directory")
parser.add_option("--cython-dir", dest="cython_dir", default=os.getcwd(), parser.add_option("--cython-dir", dest="cython_dir", default=os.getcwd(),
...@@ -2123,13 +2133,16 @@ def runtests(options, cmd_args, coverage=None): ...@@ -2123,13 +2133,16 @@ def runtests(options, cmd_args, coverage=None):
if options.filetests and languages: if options.filetests and languages:
filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, exclude_selectors, filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, exclude_selectors,
options.annotate_source, options.cleanup_workdir, options, options.pyregr, languages, test_bugs,
options.cleanup_sharedlibs, options.cleanup_failures, options.language_level, common_utility_dir,
options.pyregr, options.pythran_dir, add_embedded_test=True)
options.cython_only, languages, test_bugs, test_suite.addTest(filetests.build_suite())
options.fork, options.language_level, if options.examples and languages:
options.test_determinism, filetests = TestBuilder(options.examples_dir, WORKDIR, selectors, exclude_selectors,
common_utility_dir, options.pythran_dir) options, options.pyregr, languages, test_bugs,
options.language_level, common_utility_dir,
options.pythran_dir,
default_mode='compile')
test_suite.addTest(filetests.build_suite()) test_suite.addTest(filetests.build_suite())
if options.system_pyregr and languages: if options.system_pyregr and languages:
...@@ -2138,13 +2151,9 @@ def runtests(options, cmd_args, coverage=None): ...@@ -2138,13 +2151,9 @@ def runtests(options, cmd_args, coverage=None):
sys_pyregr_dir = os.path.join(os.path.dirname(sys.executable), 'Lib', 'test') # source build sys_pyregr_dir = os.path.join(os.path.dirname(sys.executable), 'Lib', 'test') # source build
if os.path.isdir(sys_pyregr_dir): if os.path.isdir(sys_pyregr_dir):
filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, exclude_selectors, filetests = TestBuilder(ROOTDIR, WORKDIR, selectors, exclude_selectors,
options.annotate_source, options.cleanup_workdir, options, True, languages, test_bugs,
options.cleanup_sharedlibs, options.cleanup_failures, sys.version_info[0], common_utility_dir,
True, add_embedded_test=True)
options.cython_only, languages, test_bugs,
options.fork, sys.version_info[0],
options.test_determinism,
common_utility_dir)
sys.stderr.write("Including CPython regression tests in %s\n" % sys_pyregr_dir) sys.stderr.write("Including CPython regression tests in %s\n" % sys_pyregr_dir)
test_suite.addTest(filetests.handle_directory(sys_pyregr_dir, 'pyregr')) test_suite.addTest(filetests.handle_directory(sys_pyregr_dir, 'pyregr'))
......
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