summaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Build/Tests/TestInline.py
diff options
context:
space:
mode:
authornik-bes <[email protected]>2025-05-19 07:20:13 +0300
committernik-bes <[email protected]>2025-05-19 07:36:02 +0300
commit317b7368e24941ff76499f500579fd9b10f6656e (patch)
treeabbcbaea595e7d2e9f23cf59a408b3082fe4340d /contrib/tools/cython/Cython/Build/Tests/TestInline.py
parent6b666a52d40308ab9b3532cd8d3008b9f37cfffb (diff)
Update Cython to 3.0.10.
commit_hash:b43c96b868cd36d636192fd2c6024d9f0d2fb6f8
Diffstat (limited to 'contrib/tools/cython/Cython/Build/Tests/TestInline.py')
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestInline.py52
1 files changed, 34 insertions, 18 deletions
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestInline.py b/contrib/tools/cython/Cython/Build/Tests/TestInline.py
index d209488083e..53346137052 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestInline.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestInline.py
@@ -1,4 +1,6 @@
-import os, tempfile
+import os
+import tempfile
+import unittest
from Cython.Shadow import inline
from Cython.Build.Inline import safe_type
from Cython.TestUtils import CythonTest
@@ -16,39 +18,39 @@ global_value = 100
class TestInline(CythonTest):
def setUp(self):
CythonTest.setUp(self)
- self.test_kwds = dict(test_kwds)
+ self._call_kwds = dict(test_kwds)
if os.path.isdir('TEST_TMP'):
lib_dir = os.path.join('TEST_TMP','inline')
else:
lib_dir = tempfile.mkdtemp(prefix='cython_inline_')
- self.test_kwds['lib_dir'] = lib_dir
+ self._call_kwds['lib_dir'] = lib_dir
def test_simple(self):
- self.assertEqual(inline("return 1+2", **self.test_kwds), 3)
+ self.assertEqual(inline("return 1+2", **self._call_kwds), 3)
def test_types(self):
self.assertEqual(inline("""
cimport cython
return cython.typeof(a), cython.typeof(b)
- """, a=1.0, b=[], **self.test_kwds), ('double', 'list object'))
+ """, a=1.0, b=[], **self._call_kwds), ('double', 'list object'))
def test_locals(self):
a = 1
b = 2
- self.assertEqual(inline("return a+b", **self.test_kwds), 3)
+ self.assertEqual(inline("return a+b", **self._call_kwds), 3)
def test_globals(self):
- self.assertEqual(inline("return global_value + 1", **self.test_kwds), global_value + 1)
+ self.assertEqual(inline("return global_value + 1", **self._call_kwds), global_value + 1)
def test_no_return(self):
self.assertEqual(inline("""
a = 1
cdef double b = 2
cdef c = []
- """, **self.test_kwds), dict(a=1, b=2.0, c=[]))
+ """, **self._call_kwds), dict(a=1, b=2.0, c=[]))
def test_def_node(self):
- foo = inline("def foo(x): return x * x", **self.test_kwds)['foo']
+ foo = inline("def foo(x): return x * x", **self._call_kwds)['foo']
self.assertEqual(foo(7), 49)
def test_class_ref(self):
@@ -63,7 +65,7 @@ class TestInline(CythonTest):
b = cy.declare(float, a)
c = cy.declare(cy.pointer(cy.float), &b)
return b
- """, a=3, **self.test_kwds)
+ """, a=3, **self._call_kwds)
self.assertEqual(type(b), float)
def test_compiler_directives(self):
@@ -85,12 +87,26 @@ class TestInline(CythonTest):
inline(inline_divcode, language_level=3)['f'](5,2),
2.5
)
+ self.assertEqual(
+ inline(inline_divcode, language_level=2)['f'](5,2),
+ 2
+ )
- if has_numpy:
-
- def test_numpy(self):
- import numpy
- a = numpy.ndarray((10, 20))
- a[0,0] = 10
- self.assertEqual(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
- self.assertEqual(inline("return a[0,0]", a=a, **self.test_kwds), 10.0)
+ def test_repeated_use(self):
+ inline_mulcode = "def f(int a, int b): return a * b"
+ self.assertEqual(inline(inline_mulcode)['f'](5, 2), 10)
+ self.assertEqual(inline(inline_mulcode)['f'](5, 3), 15)
+ self.assertEqual(inline(inline_mulcode)['f'](6, 2), 12)
+ self.assertEqual(inline(inline_mulcode)['f'](5, 2), 10)
+
+ f = inline(inline_mulcode)['f']
+ self.assertEqual(f(5, 2), 10)
+ self.assertEqual(f(5, 3), 15)
+
+ @unittest.skipIf(not has_numpy, "NumPy is not available")
+ def test_numpy(self):
+ import numpy
+ a = numpy.ndarray((10, 20))
+ a[0,0] = 10
+ self.assertEqual(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
+ self.assertEqual(inline("return a[0,0]", a=a, **self._call_kwds), 10.0)