More inline tests, quiet tests.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sat, 11 Dec 2010 09:41:41 +0000 (01:41 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sat, 11 Dec 2010 09:41:41 +0000 (01:41 -0800)
Cython/Build/Dependencies.py
Cython/Build/Inline.py
Cython/Build/Tests/TestInline.py
runtests.py

index 04844bdce30868522ea89cac0fcae1e23fc84d41..378a7821d500e9a7c2def03c177edee3a7149e4e 100644 (file)
@@ -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:
index 61cbf98ebe7959f393cad33d9b6220df2cf00773..7295afa2d2062529b9207ab82776a22f799886c8 100644 (file)
@@ -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()
index 8a8fb78d0ec590960ed85b89b2330eca5155cf03..e0ed3273d6ee3255f5b47ffa4d3e6ed19000535c 100644 (file)
@@ -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)
index b2d65c8f7c1be1cebddc218929aefcd7009eae00..5f27a0553570ed8f3e22be304ed460e73572e4c8 100644 (file)
@@ -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) ]: