aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Build/Tests
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/tools/cython/Cython/Build/Tests
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
downloadydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Build/Tests')
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestCyCache.py212
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestInline.py38
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py64
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py4
4 files changed, 159 insertions, 159 deletions
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestCyCache.py b/contrib/tools/cython/Cython/Build/Tests/TestCyCache.py
index a3224b4175..a0ed3f389a 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestCyCache.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestCyCache.py
@@ -1,106 +1,106 @@
-import difflib
-import glob
-import gzip
-import os
-import tempfile
-
-import Cython.Build.Dependencies
-import Cython.Utils
-from Cython.TestUtils import CythonTest
-
-
-class TestCyCache(CythonTest):
-
- def setUp(self):
- CythonTest.setUp(self)
- self.temp_dir = tempfile.mkdtemp(
- prefix='cycache-test',
- dir='TEST_TMP' if os.path.isdir('TEST_TMP') else None)
- self.src_dir = tempfile.mkdtemp(prefix='src', dir=self.temp_dir)
- self.cache_dir = tempfile.mkdtemp(prefix='cache', dir=self.temp_dir)
-
- def cache_files(self, file_glob):
- return glob.glob(os.path.join(self.cache_dir, file_glob))
-
- def fresh_cythonize(self, *args, **kwargs):
- Cython.Utils.clear_function_caches()
- Cython.Build.Dependencies._dep_tree = None # discard method caches
- Cython.Build.Dependencies.cythonize(*args, **kwargs)
-
- def test_cycache_switch(self):
- content1 = 'value = 1\n'
- content2 = 'value = 2\n'
- a_pyx = os.path.join(self.src_dir, 'a.pyx')
- a_c = a_pyx[:-4] + '.c'
-
- open(a_pyx, 'w').write(content1)
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- self.assertEqual(1, len(self.cache_files('a.c*')))
- a_contents1 = open(a_c).read()
- os.unlink(a_c)
-
- open(a_pyx, 'w').write(content2)
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- a_contents2 = open(a_c).read()
- os.unlink(a_c)
-
- self.assertNotEqual(a_contents1, a_contents2, 'C file not changed!')
- self.assertEqual(2, len(self.cache_files('a.c*')))
-
- open(a_pyx, 'w').write(content1)
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- self.assertEqual(2, len(self.cache_files('a.c*')))
- a_contents = open(a_c).read()
- self.assertEqual(
- a_contents, a_contents1,
- msg='\n'.join(list(difflib.unified_diff(
- a_contents.split('\n'), a_contents1.split('\n')))[:10]))
-
- def test_cycache_uses_cache(self):
- a_pyx = os.path.join(self.src_dir, 'a.pyx')
- a_c = a_pyx[:-4] + '.c'
- open(a_pyx, 'w').write('pass')
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- a_cache = os.path.join(self.cache_dir, os.listdir(self.cache_dir)[0])
- gzip.GzipFile(a_cache, 'wb').write('fake stuff'.encode('ascii'))
- os.unlink(a_c)
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- a_contents = open(a_c).read()
- self.assertEqual(a_contents, 'fake stuff',
- 'Unexpected contents: %s...' % a_contents[:100])
-
- def test_multi_file_output(self):
- a_pyx = os.path.join(self.src_dir, 'a.pyx')
- a_c = a_pyx[:-4] + '.c'
- a_h = a_pyx[:-4] + '.h'
- a_api_h = a_pyx[:-4] + '_api.h'
- open(a_pyx, 'w').write('cdef public api int foo(int x): return x\n')
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- expected = [a_c, a_h, a_api_h]
- for output in expected:
- self.assertTrue(os.path.exists(output), output)
- os.unlink(output)
- self.fresh_cythonize(a_pyx, cache=self.cache_dir)
- for output in expected:
- self.assertTrue(os.path.exists(output), output)
-
- def test_options_invalidation(self):
- hash_pyx = os.path.join(self.src_dir, 'options.pyx')
- hash_c = hash_pyx[:-len('.pyx')] + '.c'
-
- open(hash_pyx, 'w').write('pass')
- self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=False)
- self.assertEqual(1, len(self.cache_files('options.c*')))
-
- os.unlink(hash_c)
- self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=True)
- self.assertEqual(2, len(self.cache_files('options.c*')))
-
- os.unlink(hash_c)
- self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=False, show_version=False)
- self.assertEqual(2, len(self.cache_files('options.c*')))
-
- os.unlink(hash_c)
- self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=False, show_version=True)
- self.assertEqual(2, len(self.cache_files('options.c*')))
+import difflib
+import glob
+import gzip
+import os
+import tempfile
+
+import Cython.Build.Dependencies
+import Cython.Utils
+from Cython.TestUtils import CythonTest
+
+
+class TestCyCache(CythonTest):
+
+ def setUp(self):
+ CythonTest.setUp(self)
+ self.temp_dir = tempfile.mkdtemp(
+ prefix='cycache-test',
+ dir='TEST_TMP' if os.path.isdir('TEST_TMP') else None)
+ self.src_dir = tempfile.mkdtemp(prefix='src', dir=self.temp_dir)
+ self.cache_dir = tempfile.mkdtemp(prefix='cache', dir=self.temp_dir)
+
+ def cache_files(self, file_glob):
+ return glob.glob(os.path.join(self.cache_dir, file_glob))
+
+ def fresh_cythonize(self, *args, **kwargs):
+ Cython.Utils.clear_function_caches()
+ Cython.Build.Dependencies._dep_tree = None # discard method caches
+ Cython.Build.Dependencies.cythonize(*args, **kwargs)
+
+ def test_cycache_switch(self):
+ content1 = 'value = 1\n'
+ content2 = 'value = 2\n'
+ a_pyx = os.path.join(self.src_dir, 'a.pyx')
+ a_c = a_pyx[:-4] + '.c'
+
+ open(a_pyx, 'w').write(content1)
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ self.assertEqual(1, len(self.cache_files('a.c*')))
+ a_contents1 = open(a_c).read()
+ os.unlink(a_c)
+
+ open(a_pyx, 'w').write(content2)
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ a_contents2 = open(a_c).read()
+ os.unlink(a_c)
+
+ self.assertNotEqual(a_contents1, a_contents2, 'C file not changed!')
+ self.assertEqual(2, len(self.cache_files('a.c*')))
+
+ open(a_pyx, 'w').write(content1)
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ self.assertEqual(2, len(self.cache_files('a.c*')))
+ a_contents = open(a_c).read()
+ self.assertEqual(
+ a_contents, a_contents1,
+ msg='\n'.join(list(difflib.unified_diff(
+ a_contents.split('\n'), a_contents1.split('\n')))[:10]))
+
+ def test_cycache_uses_cache(self):
+ a_pyx = os.path.join(self.src_dir, 'a.pyx')
+ a_c = a_pyx[:-4] + '.c'
+ open(a_pyx, 'w').write('pass')
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ a_cache = os.path.join(self.cache_dir, os.listdir(self.cache_dir)[0])
+ gzip.GzipFile(a_cache, 'wb').write('fake stuff'.encode('ascii'))
+ os.unlink(a_c)
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ a_contents = open(a_c).read()
+ self.assertEqual(a_contents, 'fake stuff',
+ 'Unexpected contents: %s...' % a_contents[:100])
+
+ def test_multi_file_output(self):
+ a_pyx = os.path.join(self.src_dir, 'a.pyx')
+ a_c = a_pyx[:-4] + '.c'
+ a_h = a_pyx[:-4] + '.h'
+ a_api_h = a_pyx[:-4] + '_api.h'
+ open(a_pyx, 'w').write('cdef public api int foo(int x): return x\n')
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ expected = [a_c, a_h, a_api_h]
+ for output in expected:
+ self.assertTrue(os.path.exists(output), output)
+ os.unlink(output)
+ self.fresh_cythonize(a_pyx, cache=self.cache_dir)
+ for output in expected:
+ self.assertTrue(os.path.exists(output), output)
+
+ def test_options_invalidation(self):
+ hash_pyx = os.path.join(self.src_dir, 'options.pyx')
+ hash_c = hash_pyx[:-len('.pyx')] + '.c'
+
+ open(hash_pyx, 'w').write('pass')
+ self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=False)
+ self.assertEqual(1, len(self.cache_files('options.c*')))
+
+ os.unlink(hash_c)
+ self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=True)
+ self.assertEqual(2, len(self.cache_files('options.c*')))
+
+ os.unlink(hash_c)
+ self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=False, show_version=False)
+ self.assertEqual(2, len(self.cache_files('options.c*')))
+
+ os.unlink(hash_c)
+ self.fresh_cythonize(hash_pyx, cache=self.cache_dir, cplus=False, show_version=True)
+ self.assertEqual(2, len(self.cache_files('options.c*')))
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestInline.py b/contrib/tools/cython/Cython/Build/Tests/TestInline.py
index d209488083..30fab094b5 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestInline.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestInline.py
@@ -17,8 +17,8 @@ class TestInline(CythonTest):
def setUp(self):
CythonTest.setUp(self)
self.test_kwds = dict(test_kwds)
- if os.path.isdir('TEST_TMP'):
- lib_dir = os.path.join('TEST_TMP','inline')
+ 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
@@ -45,35 +45,35 @@ class TestInline(CythonTest):
a = 1
cdef double b = 2
cdef c = []
- """, **self.test_kwds), dict(a=1, b=2.0, c=[]))
+ """, **self.test_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.test_kwds)['foo']
self.assertEqual(foo(7), 49)
- def test_class_ref(self):
- class Type(object):
- pass
- tp = inline("Type")['Type']
- self.assertEqual(tp, Type)
-
+ def test_class_ref(self):
+ class Type(object):
+ pass
+ tp = inline("Type")['Type']
+ self.assertEqual(tp, Type)
+
def test_pure(self):
import cython as cy
b = inline("""
b = cy.declare(float, a)
c = cy.declare(cy.pointer(cy.float), &b)
return b
- """, a=3, **self.test_kwds)
+ """, a=3, **self.test_kwds)
self.assertEqual(type(b), float)
- def test_compiler_directives(self):
- self.assertEqual(
- inline('return sum(x)',
- x=[1, 2, 3],
- cython_compiler_directives={'boundscheck': False}),
- 6
- )
-
+ def test_compiler_directives(self):
+ self.assertEqual(
+ inline('return sum(x)',
+ x=[1, 2, 3],
+ cython_compiler_directives={'boundscheck': False}),
+ 6
+ )
+
def test_lang_version(self):
# GH-3419. Caching for inline code didn't always respect compiler directives.
inline_divcode = "def f(int a, int b): return a/b"
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py b/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py
index 24213091b2..9d2e1531a5 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py
@@ -29,24 +29,24 @@ except ImportError:
pass
code = u"""\
-def f(x):
+def f(x):
return 2*x
"""
cython3_code = u"""\
-def f(int x):
- return 2 / x
+def f(int x):
+ return 2 / x
-def call(x):
- return f(*(x,))
+def call(x):
+ return f(*(x,))
"""
-
+
pgo_cython3_code = cython3_code + u"""\
def main():
for _ in range(100): call(5)
main()
"""
-
+
if sys.platform == 'win32':
# not using IPython's decorators here because they depend on "nose"
@@ -114,34 +114,34 @@ class TestIPythonMagic(CythonTest):
ip.ex('import mymodule; g = mymodule.f(10)')
self.assertEqual(ip.user_ns['g'], 20.0)
- def test_cython_language_level(self):
- # The Cython cell defines the functions f() and call().
+ def test_cython_language_level(self):
+ # The Cython cell defines the functions f() and call().
ip = self._ip
- ip.run_cell_magic('cython', '', cython3_code)
- ip.ex('g = f(10); h = call(10)')
- if sys.version_info[0] < 3:
- self.assertEqual(ip.user_ns['g'], 2 // 10)
- self.assertEqual(ip.user_ns['h'], 2 // 10)
- else:
- self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
- self.assertEqual(ip.user_ns['h'], 2.0 / 10.0)
-
- def test_cython3(self):
- # The Cython cell defines the functions f() and call().
+ ip.run_cell_magic('cython', '', cython3_code)
+ ip.ex('g = f(10); h = call(10)')
+ if sys.version_info[0] < 3:
+ self.assertEqual(ip.user_ns['g'], 2 // 10)
+ self.assertEqual(ip.user_ns['h'], 2 // 10)
+ else:
+ self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
+ self.assertEqual(ip.user_ns['h'], 2.0 / 10.0)
+
+ def test_cython3(self):
+ # The Cython cell defines the functions f() and call().
ip = self._ip
- ip.run_cell_magic('cython', '-3', cython3_code)
- ip.ex('g = f(10); h = call(10)')
- self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
- self.assertEqual(ip.user_ns['h'], 2.0 / 10.0)
-
- def test_cython2(self):
- # The Cython cell defines the functions f() and call().
+ ip.run_cell_magic('cython', '-3', cython3_code)
+ ip.ex('g = f(10); h = call(10)')
+ self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
+ self.assertEqual(ip.user_ns['h'], 2.0 / 10.0)
+
+ def test_cython2(self):
+ # The Cython cell defines the functions f() and call().
ip = self._ip
- ip.run_cell_magic('cython', '-2', cython3_code)
- ip.ex('g = f(10); h = call(10)')
- self.assertEqual(ip.user_ns['g'], 2 // 10)
- self.assertEqual(ip.user_ns['h'], 2 // 10)
-
+ ip.run_cell_magic('cython', '-2', cython3_code)
+ ip.ex('g = f(10); h = call(10)')
+ self.assertEqual(ip.user_ns['g'], 2 // 10)
+ self.assertEqual(ip.user_ns['h'], 2 // 10)
+
@skip_win32('Skip on Windows')
def test_cython3_pgo(self):
# The Cython cell defines the functions f() and call().
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py b/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py
index a7572a5083..494a4e03b1 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py
@@ -6,10 +6,10 @@ class TestStripLiterals(CythonTest):
def t(self, before, expected):
actual, literals = strip_string_literals(before, prefix="_L")
- self.assertEqual(expected, actual)
+ self.assertEqual(expected, actual)
for key, value in literals.items():
actual = actual.replace(key, value)
- self.assertEqual(before, actual)
+ self.assertEqual(before, actual)
def test_empty(self):
self.t("", "")