Commit a0cbd421 authored by Robert Bradshaw's avatar Robert Bradshaw

More inline tests, quiet tests.

parent de46c66d
...@@ -314,8 +314,8 @@ class DependencyTree(object): ...@@ -314,8 +314,8 @@ class DependencyTree(object):
self_pxd = [] self_pxd = []
a = self.cimports(filename) a = self.cimports(filename)
b = filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)]) b = filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)])
if len(a) != len(b): if len(a) - int('cython' in a) != len(b):
print(filename) print("missing cimport", filename)
print("\n\t".join(a)) print("\n\t".join(a))
print("\n\t".join(b)) print("\n\t".join(b))
return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)])) 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): ...@@ -442,7 +442,7 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None):
return module_list return module_list
# This is the user-exposed entry point. # 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: if 'include_path' not in options:
options['include_path'] = ['.'] options['include_path'] = ['.']
c_options = CompilationOptions(**options) c_options = CompilationOptions(**options)
...@@ -479,6 +479,7 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, **options): ...@@ -479,6 +479,7 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, **options):
dep_timestamp, dep = deps.newest_dependency(source) dep_timestamp, dep = deps.newest_dependency(source)
priority = 2 - (dep in deps.immediate_dependencies(source)) priority = 2 - (dep in deps.immediate_dependencies(source))
if c_timestamp < dep_timestamp: if c_timestamp < dep_timestamp:
if not quiet:
if source == dep: if source == dep:
print("Cythonizing %s because it changed." % source) print("Cythonizing %s because it changed." % source)
else: else:
......
#no doctest
print "Warning: Using prototype cython.inline code..."
import tempfile import tempfile
import sys, os, re, inspect import sys, os, re, inspect
...@@ -86,6 +83,7 @@ def cython_inline(code, ...@@ -86,6 +83,7 @@ def cython_inline(code,
lib_dir=os.path.expanduser('~/.cython/inline'), lib_dir=os.path.expanduser('~/.cython/inline'),
cython_include_dirs=['.'], cython_include_dirs=['.'],
force=False, force=False,
quiet=False,
locals=None, locals=None,
globals=None, globals=None,
**kwds): **kwds):
...@@ -107,10 +105,11 @@ def cython_inline(code, ...@@ -107,10 +105,11 @@ def cython_inline(code,
elif symbol in globals: elif symbol in globals:
kwds[symbol] = globals[symbol] kwds[symbol] = globals[symbol]
else: else:
print "Couldn't find ", symbol print("Couldn't find ", symbol)
except AssertionError: except AssertionError:
if not quiet:
# Parsing from strings not fully supported (e.g. cimports). # Parsing from strings not fully supported (e.g. cimports).
print "Could not parse code as a string (to extract unbound symbols)." print("Could not parse code as a string (to extract unbound symbols).")
arg_names = kwds.keys() arg_names = kwds.keys()
arg_names.sort() arg_names.sort()
arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names]) arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names])
...@@ -158,7 +157,7 @@ def __invoke(%(params)s): ...@@ -158,7 +157,7 @@ def __invoke(%(params)s):
extra_compile_args = cflags) extra_compile_args = cflags)
build_extension = build_ext(Distribution()) build_extension = build_ext(Distribution())
build_extension.finalize_options() 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_temp = os.path.dirname(pyx_file)
build_extension.build_lib = lib_dir build_extension.build_lib = lib_dir
build_extension.run() build_extension.run()
......
from Cython.Shadow import inline from Cython.Shadow import inline
from Cython.Build.Inline import safe_type
from Cython.TestUtils import CythonTest 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): class TestStripLiterals(CythonTest):
def test_inline(self): def test_simple(self):
self.assertEquals(inline("return 1+2"), 3) 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)
...@@ -715,7 +715,6 @@ def collect_doctests(path, module_prefix, suite, selectors): ...@@ -715,7 +715,6 @@ def collect_doctests(path, module_prefix, suite, selectors):
if not f.endswith('.py'): continue if not f.endswith('.py'): continue
filepath = os.path.join(dirpath, f) filepath = os.path.join(dirpath, f)
if os.path.getsize(filepath) == 0: continue if os.path.getsize(filepath) == 0: continue
if 'no doctest' in open(filepath).next(): continue
filepath = filepath[:-len(".py")] filepath = filepath[:-len(".py")]
modulename = module_prefix + filepath[len(path)+1:].replace(os.path.sep, '.') modulename = module_prefix + filepath[len(path)+1:].replace(os.path.sep, '.')
if not [ 1 for match in selectors if match(modulename) ]: if not [ 1 for match in selectors if match(modulename) ]:
......
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