2 from Cython.Shadow import inline
3 from Cython.Build.Inline import safe_type
4 from Cython.TestUtils import CythonTest
12 test_kwds = dict(force=True, quiet=True)
16 class TestInline(CythonTest):
18 CythonTest.setUp(self)
19 self.test_kwds = dict(test_kwds)
20 if os.path.isdir('BUILD'):
21 lib_dir = os.path.join('BUILD','inline')
23 lib_dir = tempfile.mkdtemp(prefix='cython_inline_')
24 self.test_kwds['lib_dir'] = lib_dir
26 def test_simple(self):
27 self.assertEquals(inline("return 1+2", **self.test_kwds), 3)
30 self.assertEquals(inline("""
32 return cython.typeof(a), cython.typeof(b)
33 """, a=1.0, b=[], **self.test_kwds), ('double', 'list object'))
35 def test_locals(self):
38 self.assertEquals(inline("return a+b", **self.test_kwds), 3)
40 def test_globals(self):
41 self.assertEquals(inline("return global_value + 1", **self.test_kwds), global_value + 1)
46 b = cy.declare(float, a)
47 c = cy.declare(cy.pointer(cy.float), &b)
50 self.assertEquals(type(b), float)
56 a = numpy.ndarray((10, 20))
58 self.assertEquals(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
59 self.assertEquals(inline("return a[0,0]", a=a, **self.test_kwds), 10.0)