diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /contrib/tools/cython/Cython/Build/Tests | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Build/Tests')
4 files changed, 180 insertions, 180 deletions
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestInline.py b/contrib/tools/cython/Cython/Build/Tests/TestInline.py index d209488083..0877dee03f 100644 --- a/contrib/tools/cython/Cython/Build/Tests/TestInline.py +++ b/contrib/tools/cython/Cython/Build/Tests/TestInline.py @@ -1,71 +1,71 @@ -import os, tempfile -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 TestInline(CythonTest): - def setUp(self): - CythonTest.setUp(self) - self.test_kwds = dict(test_kwds) +import os, tempfile +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 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') - else: - lib_dir = tempfile.mkdtemp(prefix='cython_inline_') - self.test_kwds['lib_dir'] = lib_dir - - def test_simple(self): + else: + lib_dir = tempfile.mkdtemp(prefix='cython_inline_') + self.test_kwds['lib_dir'] = lib_dir + + def test_simple(self): self.assertEqual(inline("return 1+2", **self.test_kwds), 3) - - def test_types(self): + + 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')) - - def test_locals(self): - a = 1 - b = 2 + cimport cython + return cython.typeof(a), cython.typeof(b) + """, a=1.0, b=[], **self.test_kwds), ('double', 'list object')) + + def test_locals(self): + a = 1 + b = 2 self.assertEqual(inline("return a+b", **self.test_kwds), 3) - - def test_globals(self): + + def test_globals(self): self.assertEqual(inline("return global_value + 1", **self.test_kwds), global_value + 1) - - def test_no_return(self): + + def test_no_return(self): self.assertEqual(inline(""" - a = 1 - cdef double b = 2 - cdef c = [] + a = 1 + cdef double b = 2 + cdef c = [] """, **self.test_kwds), dict(a=1, b=2.0, c=[])) - - def test_def_node(self): + + def test_def_node(self): 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_pure(self): - import cython as cy - b = inline(""" - b = cy.declare(float, a) - c = cy.declare(cy.pointer(cy.float), &b) - return b + 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) self.assertEqual(type(b), float) - + def test_compiler_directives(self): self.assertEqual( inline('return sum(x)', @@ -86,11 +86,11 @@ class TestInline(CythonTest): 2.5 ) - if has_numpy: - - def test_numpy(self): - import numpy - a = numpy.ndarray((10, 20)) - a[0,0] = 10 + 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) diff --git a/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py b/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py index 24213091b2..1b67a970c6 100644 --- a/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py +++ b/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py @@ -1,17 +1,17 @@ -# -*- coding: utf-8 -*- -# tag: ipython - -"""Tests for the Cython magics extension.""" - +# -*- coding: utf-8 -*- +# tag: ipython + +"""Tests for the Cython magics extension.""" + from __future__ import absolute_import -import os -import sys +import os +import sys from contextlib import contextmanager from Cython.Build import IpythonMagic from Cython.TestUtils import CythonTest - -try: + +try: import IPython.testing.globalipapp except ImportError: # Disable tests and fake helpers for initialisation below. @@ -21,22 +21,22 @@ else: def skip_if_not_installed(c): return c -try: +try: # disable IPython history thread before it gets started to avoid having to clean it up - from IPython.core.history import HistoryManager - HistoryManager.enabled = False -except ImportError: - pass - + from IPython.core.history import HistoryManager + HistoryManager.enabled = False +except ImportError: + pass + code = u"""\ def f(x): - return 2*x + return 2*x """ - + cython3_code = u"""\ def f(int x): return 2 / x - + def call(x): return f(*(x,)) """ @@ -48,72 +48,72 @@ main() """ -if sys.platform == 'win32': - # not using IPython's decorators here because they depend on "nose" - try: - from unittest import skip as skip_win32 - except ImportError: - # poor dev's silent @unittest.skip() +if sys.platform == 'win32': + # not using IPython's decorators here because they depend on "nose" + try: + from unittest import skip as skip_win32 + except ImportError: + # poor dev's silent @unittest.skip() def skip_win32(dummy): def _skip_win32(func): return None return _skip_win32 -else: +else: def skip_win32(dummy): def _skip_win32(func): def wrapper(*args, **kwargs): func(*args, **kwargs) return wrapper return _skip_win32 - - + + @skip_if_not_installed -class TestIPythonMagic(CythonTest): - +class TestIPythonMagic(CythonTest): + @classmethod def setUpClass(cls): CythonTest.setUpClass() cls._ip = IPython.testing.globalipapp.get_ipython() - def setUp(self): - CythonTest.setUp(self) + def setUp(self): + CythonTest.setUp(self) self._ip.extension_manager.load_extension('cython') - - def test_cython_inline(self): + + def test_cython_inline(self): ip = self._ip - ip.ex('a=10; b=20') - result = ip.run_cell_magic('cython_inline', '', 'return a+b') - self.assertEqual(result, 30) - + ip.ex('a=10; b=20') + result = ip.run_cell_magic('cython_inline', '', 'return a+b') + self.assertEqual(result, 30) + @skip_win32('Skip on Windows') - def test_cython_pyximport(self): + def test_cython_pyximport(self): ip = self._ip - module_name = '_test_cython_pyximport' - ip.run_cell_magic('cython_pyximport', module_name, code) - ip.ex('g = f(10)') - self.assertEqual(ip.user_ns['g'], 20.0) - ip.run_cell_magic('cython_pyximport', module_name, code) - ip.ex('h = f(-10)') - self.assertEqual(ip.user_ns['h'], -20.0) - try: - os.remove(module_name + '.pyx') - except OSError: - pass - - def test_cython(self): + module_name = '_test_cython_pyximport' + ip.run_cell_magic('cython_pyximport', module_name, code) + ip.ex('g = f(10)') + self.assertEqual(ip.user_ns['g'], 20.0) + ip.run_cell_magic('cython_pyximport', module_name, code) + ip.ex('h = f(-10)') + self.assertEqual(ip.user_ns['h'], -20.0) + try: + os.remove(module_name + '.pyx') + except OSError: + pass + + def test_cython(self): ip = self._ip - ip.run_cell_magic('cython', '', code) - ip.ex('g = f(10)') - self.assertEqual(ip.user_ns['g'], 20.0) - - def test_cython_name(self): - # The Cython module named 'mymodule' defines the function f. + ip.run_cell_magic('cython', '', code) + ip.ex('g = f(10)') + self.assertEqual(ip.user_ns['g'], 20.0) + + def test_cython_name(self): + # The Cython module named 'mymodule' defines the function f. ip = self._ip - ip.run_cell_magic('cython', '--name=mymodule', code) - # This module can now be imported in the interactive namespace. - ip.ex('import mymodule; g = mymodule.f(10)') - self.assertEqual(ip.user_ns['g'], 20.0) - + ip.run_cell_magic('cython', '--name=mymodule', code) + # This module can now be imported in the interactive namespace. + 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(). ip = self._ip @@ -152,15 +152,15 @@ class TestIPythonMagic(CythonTest): self.assertEqual(ip.user_ns['h'], 2.0 / 10.0) @skip_win32('Skip on Windows') - def test_extlibs(self): + def test_extlibs(self): ip = self._ip code = u""" -from libc.math cimport sin -x = sin(0.0) +from libc.math cimport sin +x = sin(0.0) """ - ip.user_ns['x'] = 1 - ip.run_cell_magic('cython', '-l m', code) - self.assertEqual(ip.user_ns['x'], 0) + ip.user_ns['x'] = 1 + ip.run_cell_magic('cython', '-l m', code) + self.assertEqual(ip.user_ns['x'], 0) def test_cython_verbose(self): diff --git a/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py b/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py index a7572a5083..3f4261128f 100644 --- a/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py +++ b/contrib/tools/cython/Cython/Build/Tests/TestStripLiterals.py @@ -1,57 +1,57 @@ -from Cython.Build.Dependencies import strip_string_literals - -from Cython.TestUtils import CythonTest - -class TestStripLiterals(CythonTest): - - def t(self, before, expected): - actual, literals = strip_string_literals(before, prefix="_L") +from Cython.Build.Dependencies import strip_string_literals + +from Cython.TestUtils import CythonTest + +class TestStripLiterals(CythonTest): + + def t(self, before, expected): + actual, literals = strip_string_literals(before, prefix="_L") self.assertEqual(expected, actual) - for key, value in literals.items(): - actual = actual.replace(key, value) + for key, value in literals.items(): + actual = actual.replace(key, value) self.assertEqual(before, actual) - - def test_empty(self): - self.t("", "") - - def test_single_quote(self): - self.t("'x'", "'_L1_'") - - def test_double_quote(self): - self.t('"x"', '"_L1_"') - - def test_nested_quotes(self): - self.t(""" '"' "'" """, """ '_L1_' "_L2_" """) - - def test_triple_quote(self): - self.t(" '''a\n''' ", " '''_L1_''' ") - - def test_backslash(self): - self.t(r"'a\'b'", "'_L1_'") - self.t(r"'a\\'", "'_L1_'") - self.t(r"'a\\\'b'", "'_L1_'") - - def test_unicode(self): - self.t("u'abc'", "u'_L1_'") - - def test_raw(self): - self.t(r"r'abc\\'", "r'_L1_'") - - def test_raw_unicode(self): - self.t(r"ru'abc\\'", "ru'_L1_'") - - def test_comment(self): - self.t("abc # foo", "abc #_L1_") - - def test_comment_and_quote(self): - self.t("abc # 'x'", "abc #_L1_") - self.t("'abc#'", "'_L1_'") - - def test_include(self): - self.t("include 'a.pxi' # something here", - "include '_L1_' #_L2_") - - def test_extern(self): - self.t("cdef extern from 'a.h': # comment", - "cdef extern from '_L1_': #_L2_") - + + def test_empty(self): + self.t("", "") + + def test_single_quote(self): + self.t("'x'", "'_L1_'") + + def test_double_quote(self): + self.t('"x"', '"_L1_"') + + def test_nested_quotes(self): + self.t(""" '"' "'" """, """ '_L1_' "_L2_" """) + + def test_triple_quote(self): + self.t(" '''a\n''' ", " '''_L1_''' ") + + def test_backslash(self): + self.t(r"'a\'b'", "'_L1_'") + self.t(r"'a\\'", "'_L1_'") + self.t(r"'a\\\'b'", "'_L1_'") + + def test_unicode(self): + self.t("u'abc'", "u'_L1_'") + + def test_raw(self): + self.t(r"r'abc\\'", "r'_L1_'") + + def test_raw_unicode(self): + self.t(r"ru'abc\\'", "ru'_L1_'") + + def test_comment(self): + self.t("abc # foo", "abc #_L1_") + + def test_comment_and_quote(self): + self.t("abc # 'x'", "abc #_L1_") + self.t("'abc#'", "'_L1_'") + + def test_include(self): + self.t("include 'a.pxi' # something here", + "include '_L1_' #_L2_") + + def test_extern(self): + self.t("cdef extern from 'a.h': # comment", + "cdef extern from '_L1_': #_L2_") + diff --git a/contrib/tools/cython/Cython/Build/Tests/__init__.py b/contrib/tools/cython/Cython/Build/Tests/__init__.py index fa81adaff6..4a2889e8e1 100644 --- a/contrib/tools/cython/Cython/Build/Tests/__init__.py +++ b/contrib/tools/cython/Cython/Build/Tests/__init__.py @@ -1 +1 @@ -# empty file +# empty file |