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/Compiler/Tests/TestVisitor.py | |
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/Compiler/Tests/TestVisitor.py')
-rw-r--r-- | contrib/tools/cython/Cython/Compiler/Tests/TestVisitor.py | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestVisitor.py b/contrib/tools/cython/Cython/Compiler/Tests/TestVisitor.py index dbc8e0c03a..ee0fcc199f 100644 --- a/contrib/tools/cython/Cython/Compiler/Tests/TestVisitor.py +++ b/contrib/tools/cython/Cython/Compiler/Tests/TestVisitor.py @@ -1,61 +1,61 @@ -from Cython.Compiler.ModuleNode import ModuleNode -from Cython.Compiler.Symtab import ModuleScope -from Cython.TestUtils import TransformTest -from Cython.Compiler.Visitor import MethodDispatcherTransform -from Cython.Compiler.ParseTreeTransforms import ( - NormalizeTree, AnalyseDeclarationsTransform, - AnalyseExpressionsTransform, InterpretCompilerDirectives) - - -class TestMethodDispatcherTransform(TransformTest): - _tree = None - - def _build_tree(self): - if self._tree is None: - context = None - - def fake_module(node): - scope = ModuleScope('test', None, None) - return ModuleNode(node.pos, doc=None, body=node, - scope=scope, full_module_name='test', - directive_comments={}) - pipeline = [ - fake_module, - NormalizeTree(context), - InterpretCompilerDirectives(context, {}), - AnalyseDeclarationsTransform(context), - AnalyseExpressionsTransform(context), - ] - self._tree = self.run_pipeline(pipeline, u""" - cdef bytes s = b'asdfg' - cdef dict d = {1:2} - x = s * 3 - d.get('test') - """) - return self._tree - - def test_builtin_method(self): - calls = [0] - class Test(MethodDispatcherTransform): - def _handle_simple_method_dict_get(self, node, func, args, unbound): - calls[0] += 1 - return node - - tree = self._build_tree() - Test(None)(tree) - self.assertEqual(1, calls[0]) - - def test_binop_method(self): - calls = {'bytes': 0, 'object': 0} - class Test(MethodDispatcherTransform): - def _handle_simple_method_bytes___mul__(self, node, func, args, unbound): - calls['bytes'] += 1 - return node - def _handle_simple_method_object___mul__(self, node, func, args, unbound): - calls['object'] += 1 - return node - - tree = self._build_tree() - Test(None)(tree) - self.assertEqual(1, calls['bytes']) - self.assertEqual(0, calls['object']) +from Cython.Compiler.ModuleNode import ModuleNode +from Cython.Compiler.Symtab import ModuleScope +from Cython.TestUtils import TransformTest +from Cython.Compiler.Visitor import MethodDispatcherTransform +from Cython.Compiler.ParseTreeTransforms import ( + NormalizeTree, AnalyseDeclarationsTransform, + AnalyseExpressionsTransform, InterpretCompilerDirectives) + + +class TestMethodDispatcherTransform(TransformTest): + _tree = None + + def _build_tree(self): + if self._tree is None: + context = None + + def fake_module(node): + scope = ModuleScope('test', None, None) + return ModuleNode(node.pos, doc=None, body=node, + scope=scope, full_module_name='test', + directive_comments={}) + pipeline = [ + fake_module, + NormalizeTree(context), + InterpretCompilerDirectives(context, {}), + AnalyseDeclarationsTransform(context), + AnalyseExpressionsTransform(context), + ] + self._tree = self.run_pipeline(pipeline, u""" + cdef bytes s = b'asdfg' + cdef dict d = {1:2} + x = s * 3 + d.get('test') + """) + return self._tree + + def test_builtin_method(self): + calls = [0] + class Test(MethodDispatcherTransform): + def _handle_simple_method_dict_get(self, node, func, args, unbound): + calls[0] += 1 + return node + + tree = self._build_tree() + Test(None)(tree) + self.assertEqual(1, calls[0]) + + def test_binop_method(self): + calls = {'bytes': 0, 'object': 0} + class Test(MethodDispatcherTransform): + def _handle_simple_method_bytes___mul__(self, node, func, args, unbound): + calls['bytes'] += 1 + return node + def _handle_simple_method_object___mul__(self, node, func, args, unbound): + calls['object'] += 1 + return node + + tree = self._build_tree() + Test(None)(tree) + self.assertEqual(1, calls['bytes']) + self.assertEqual(0, calls['object']) |