From: Robert Bradshaw Date: Sat, 11 Dec 2010 09:41:41 +0000 (-0800) Subject: More inline tests, quiet tests. X-Git-Tag: 0.14.rc0~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a0cbd421cae6442ebf9cedb4d02314079b0081ea;p=cython.git More inline tests, quiet tests. --- diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py index 04844bdc..378a7821 100644 --- a/Cython/Build/Dependencies.py +++ b/Cython/Build/Dependencies.py @@ -314,8 +314,8 @@ class DependencyTree(object): self_pxd = [] a = self.cimports(filename) b = filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)]) - if len(a) != len(b): - print(filename) + if len(a) - int('cython' in a) != len(b): + print("missing cimport", filename) print("\n\t".join(a)) print("\n\t".join(b)) return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)])) @@ -442,7 +442,7 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None): return module_list # This is the user-exposed entry point. -def cythonize(module_list, exclude=[], nthreads=0, aliases=None, **options): +def cythonize(module_list, exclude=[], nthreads=0, aliases=None, quiet=False, **options): if 'include_path' not in options: options['include_path'] = ['.'] c_options = CompilationOptions(**options) @@ -479,10 +479,11 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, **options): dep_timestamp, dep = deps.newest_dependency(source) priority = 2 - (dep in deps.immediate_dependencies(source)) if c_timestamp < dep_timestamp: - if source == dep: - print("Cythonizing %s because it changed." % source) - else: - print("Cythonizing %s because it depends on %s." % (source, dep)) + if not quiet: + if source == dep: + print("Cythonizing %s because it changed." % source) + else: + print("Cythonizing %s because it depends on %s." % (source, dep)) to_compile.append((priority, source, c_file, options)) new_sources.append(c_file) else: diff --git a/Cython/Build/Inline.py b/Cython/Build/Inline.py index 61cbf98e..7295afa2 100644 --- a/Cython/Build/Inline.py +++ b/Cython/Build/Inline.py @@ -1,6 +1,3 @@ -#no doctest -print "Warning: Using prototype cython.inline code..." - import tempfile import sys, os, re, inspect @@ -86,6 +83,7 @@ def cython_inline(code, lib_dir=os.path.expanduser('~/.cython/inline'), cython_include_dirs=['.'], force=False, + quiet=False, locals=None, globals=None, **kwds): @@ -107,10 +105,11 @@ def cython_inline(code, elif symbol in globals: kwds[symbol] = globals[symbol] else: - print "Couldn't find ", symbol + print("Couldn't find ", symbol) except AssertionError: - # Parsing from strings not fully supported (e.g. cimports). - print "Could not parse code as a string (to extract unbound symbols)." + if not quiet: + # Parsing from strings not fully supported (e.g. cimports). + print("Could not parse code as a string (to extract unbound symbols).") arg_names = kwds.keys() arg_names.sort() arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names]) @@ -158,7 +157,7 @@ def __invoke(%(params)s): extra_compile_args = cflags) build_extension = build_ext(Distribution()) build_extension.finalize_options() - build_extension.extensions = cythonize([extension], ctx=ctx) + build_extension.extensions = cythonize([extension], ctx=ctx, quiet=quiet) build_extension.build_temp = os.path.dirname(pyx_file) build_extension.build_lib = lib_dir build_extension.run() diff --git a/Cython/Build/Tests/TestInline.py b/Cython/Build/Tests/TestInline.py index 8a8fb78d..e0ed3273 100644 --- a/Cython/Build/Tests/TestInline.py +++ b/Cython/Build/Tests/TestInline.py @@ -1,8 +1,41 @@ from Cython.Shadow import inline - +from Cython.Build.Inline import safe_type from Cython.TestUtils import CythonTest +try: + import numpy + has_numpy = True +except: + has_numpy = False + +test_kwds = dict(force=True, quiet=True) + +global_value = 100 + class TestStripLiterals(CythonTest): - def test_inline(self): - self.assertEquals(inline("return 1+2"), 3) + def test_simple(self): + self.assertEquals(inline("return 1+2", **test_kwds), 3) + + def test_types(self): + self.assertEquals(inline(""" + cimport cython + return cython.typeof(a), cython.typeof(b) + """, a=1.0, b=[], **test_kwds), ('double', 'list object')) + + def test_locals(self): + a = 1 + b = 2 + self.assertEquals(inline("return a+b", **test_kwds), 3) + + def test_globals(self): + self.assertEquals(inline("return global_value + 1", **test_kwds), global_value + 1) + + if has_numpy: + + def test_numpy(self): + import numpy + a = numpy.ndarray((10, 20)) + a[0,0] = 10 + self.assertEquals(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]') + self.assertEquals(inline("return a[0,0]", a=a, **test_kwds), 10.0) diff --git a/runtests.py b/runtests.py index b2d65c8f..5f27a055 100644 --- a/runtests.py +++ b/runtests.py @@ -715,7 +715,6 @@ def collect_doctests(path, module_prefix, suite, selectors): if not f.endswith('.py'): continue filepath = os.path.join(dirpath, f) if os.path.getsize(filepath) == 0: continue - if 'no doctest' in open(filepath).next(): continue filepath = filepath[:-len(".py")] modulename = module_prefix + filepath[len(path)+1:].replace(os.path.sep, '.') if not [ 1 for match in selectors if match(modulename) ]: