Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/cython/src/Cython/Build/Tests/TestInline.py

Issue 385073004: Adding cython v0.20.2 in third-party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reference cython dev list thread. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 import os, tempfile
2 from Cython.Shadow import inline
3 from Cython.Build.Inline import safe_type
4 from Cython.TestUtils import CythonTest
5
6 try:
7 import numpy
8 has_numpy = True
9 except:
10 has_numpy = False
11
12 test_kwds = dict(force=True, quiet=True)
13
14 global_value = 100
15
16 class TestInline(CythonTest):
17 def setUp(self):
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')
22 else:
23 lib_dir = tempfile.mkdtemp(prefix='cython_inline_')
24 self.test_kwds['lib_dir'] = lib_dir
25
26 def test_simple(self):
27 self.assertEquals(inline("return 1+2", **self.test_kwds), 3)
28
29 def test_types(self):
30 self.assertEquals(inline("""
31 cimport cython
32 return cython.typeof(a), cython.typeof(b)
33 """, a=1.0, b=[], **self.test_kwds), ('double', 'list object'))
34
35 def test_locals(self):
36 a = 1
37 b = 2
38 self.assertEquals(inline("return a+b", **self.test_kwds), 3)
39
40 def test_globals(self):
41 self.assertEquals(inline("return global_value + 1", **self.test_kwds), g lobal_value + 1)
42
43 def test_pure(self):
44 import cython as cy
45 b = inline("""
46 b = cy.declare(float, a)
47 c = cy.declare(cy.pointer(cy.float), &b)
48 return b
49 """, a=3)
50 self.assertEquals(type(b), float)
51
52 if has_numpy:
53
54 def test_numpy(self):
55 import numpy
56 a = numpy.ndarray((10, 20))
57 a[0,0] = 10
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)
OLDNEW
« no previous file with comments | « third_party/cython/src/Cython/Build/Inline.py ('k') | third_party/cython/src/Cython/Build/Tests/TestStripLiterals.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698