diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/tools/cython/Cython/Compiler/Tests | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Compiler/Tests')
4 files changed, 316 insertions, 316 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestCmdLine.py b/contrib/tools/cython/Cython/Compiler/Tests/TestCmdLine.py index abc7c0a892..f8862d064a 100644 --- a/contrib/tools/cython/Cython/Compiler/Tests/TestCmdLine.py +++ b/contrib/tools/cython/Cython/Compiler/Tests/TestCmdLine.py @@ -1,118 +1,118 @@ - -import sys -from unittest import TestCase -try: - from StringIO import StringIO -except ImportError: - from io import StringIO # doesn't accept 'str' in Py2 - -from .. import Options -from ..CmdLine import parse_command_line - - -class CmdLineParserTest(TestCase): - def setUp(self): - backup = {} - for name, value in vars(Options).items(): - backup[name] = value - self._options_backup = backup - - def tearDown(self): - no_value = object() - for name, orig_value in self._options_backup.items(): - if getattr(Options, name, no_value) != orig_value: - setattr(Options, name, orig_value) - - def test_short_options(self): - options, sources = parse_command_line([ - '-V', '-l', '-+', '-t', '-v', '-v', '-v', '-p', '-D', '-a', '-3', - ]) - self.assertFalse(sources) - self.assertTrue(options.show_version) - self.assertTrue(options.use_listing_file) - self.assertTrue(options.cplus) - self.assertTrue(options.timestamps) - self.assertTrue(options.verbose >= 3) - self.assertTrue(Options.embed_pos_in_docstring) - self.assertFalse(Options.docstrings) - self.assertTrue(Options.annotate) - self.assertEqual(options.language_level, 3) - - options, sources = parse_command_line([ - '-f', '-2', 'source.pyx', - ]) - self.assertTrue(sources) - self.assertTrue(len(sources) == 1) - self.assertFalse(options.timestamps) - self.assertEqual(options.language_level, 2) - - def test_long_options(self): - options, sources = parse_command_line([ - '--version', '--create-listing', '--cplus', '--embed', '--timestamps', - '--verbose', '--verbose', '--verbose', - '--embed-positions', '--no-docstrings', '--annotate', '--lenient', - ]) - self.assertFalse(sources) - self.assertTrue(options.show_version) - self.assertTrue(options.use_listing_file) - self.assertTrue(options.cplus) - self.assertEqual(Options.embed, 'main') - self.assertTrue(options.timestamps) - self.assertTrue(options.verbose >= 3) - self.assertTrue(Options.embed_pos_in_docstring) - self.assertFalse(Options.docstrings) - self.assertTrue(Options.annotate) - self.assertFalse(Options.error_on_unknown_names) - self.assertFalse(Options.error_on_uninitialized) - - options, sources = parse_command_line([ - '--force', 'source.pyx', - ]) - self.assertTrue(sources) - self.assertTrue(len(sources) == 1) - self.assertFalse(options.timestamps) - - def test_options_with_values(self): - options, sources = parse_command_line([ - '--embed=huhu', - '-I/test/include/dir1', '--include-dir=/test/include/dir2', - '--include-dir', '/test/include/dir3', - '--working=/work/dir', - 'source.pyx', - '--output-file=/output/dir', - '--pre-import=/pre/import', - '--cleanup=3', - '--annotate-coverage=cov.xml', - '--gdb-outdir=/gdb/outdir', - '--directive=wraparound=false', - ]) - self.assertEqual(sources, ['source.pyx']) - self.assertEqual(Options.embed, 'huhu') - self.assertEqual(options.include_path, ['/test/include/dir1', '/test/include/dir2', '/test/include/dir3']) - self.assertEqual(options.working_path, '/work/dir') - self.assertEqual(options.output_file, '/output/dir') - self.assertEqual(Options.pre_import, '/pre/import') - self.assertEqual(Options.generate_cleanup_code, 3) - self.assertTrue(Options.annotate) - self.assertEqual(Options.annotate_coverage_xml, 'cov.xml') - self.assertTrue(options.gdb_debug) - self.assertEqual(options.output_dir, '/gdb/outdir') - - def test_errors(self): - def error(*args): - old_stderr = sys.stderr - stderr = sys.stderr = StringIO() - try: - self.assertRaises(SystemExit, parse_command_line, list(args)) - finally: - sys.stderr = old_stderr - self.assertTrue(stderr.getvalue()) - - error('-1') - error('-I') - error('--version=-a') - error('--version=--annotate=true') - error('--working') - error('--verbose=1') - error('--verbose=1') - error('--cleanup') + +import sys +from unittest import TestCase +try: + from StringIO import StringIO +except ImportError: + from io import StringIO # doesn't accept 'str' in Py2 + +from .. import Options +from ..CmdLine import parse_command_line + + +class CmdLineParserTest(TestCase): + def setUp(self): + backup = {} + for name, value in vars(Options).items(): + backup[name] = value + self._options_backup = backup + + def tearDown(self): + no_value = object() + for name, orig_value in self._options_backup.items(): + if getattr(Options, name, no_value) != orig_value: + setattr(Options, name, orig_value) + + def test_short_options(self): + options, sources = parse_command_line([ + '-V', '-l', '-+', '-t', '-v', '-v', '-v', '-p', '-D', '-a', '-3', + ]) + self.assertFalse(sources) + self.assertTrue(options.show_version) + self.assertTrue(options.use_listing_file) + self.assertTrue(options.cplus) + self.assertTrue(options.timestamps) + self.assertTrue(options.verbose >= 3) + self.assertTrue(Options.embed_pos_in_docstring) + self.assertFalse(Options.docstrings) + self.assertTrue(Options.annotate) + self.assertEqual(options.language_level, 3) + + options, sources = parse_command_line([ + '-f', '-2', 'source.pyx', + ]) + self.assertTrue(sources) + self.assertTrue(len(sources) == 1) + self.assertFalse(options.timestamps) + self.assertEqual(options.language_level, 2) + + def test_long_options(self): + options, sources = parse_command_line([ + '--version', '--create-listing', '--cplus', '--embed', '--timestamps', + '--verbose', '--verbose', '--verbose', + '--embed-positions', '--no-docstrings', '--annotate', '--lenient', + ]) + self.assertFalse(sources) + self.assertTrue(options.show_version) + self.assertTrue(options.use_listing_file) + self.assertTrue(options.cplus) + self.assertEqual(Options.embed, 'main') + self.assertTrue(options.timestamps) + self.assertTrue(options.verbose >= 3) + self.assertTrue(Options.embed_pos_in_docstring) + self.assertFalse(Options.docstrings) + self.assertTrue(Options.annotate) + self.assertFalse(Options.error_on_unknown_names) + self.assertFalse(Options.error_on_uninitialized) + + options, sources = parse_command_line([ + '--force', 'source.pyx', + ]) + self.assertTrue(sources) + self.assertTrue(len(sources) == 1) + self.assertFalse(options.timestamps) + + def test_options_with_values(self): + options, sources = parse_command_line([ + '--embed=huhu', + '-I/test/include/dir1', '--include-dir=/test/include/dir2', + '--include-dir', '/test/include/dir3', + '--working=/work/dir', + 'source.pyx', + '--output-file=/output/dir', + '--pre-import=/pre/import', + '--cleanup=3', + '--annotate-coverage=cov.xml', + '--gdb-outdir=/gdb/outdir', + '--directive=wraparound=false', + ]) + self.assertEqual(sources, ['source.pyx']) + self.assertEqual(Options.embed, 'huhu') + self.assertEqual(options.include_path, ['/test/include/dir1', '/test/include/dir2', '/test/include/dir3']) + self.assertEqual(options.working_path, '/work/dir') + self.assertEqual(options.output_file, '/output/dir') + self.assertEqual(Options.pre_import, '/pre/import') + self.assertEqual(Options.generate_cleanup_code, 3) + self.assertTrue(Options.annotate) + self.assertEqual(Options.annotate_coverage_xml, 'cov.xml') + self.assertTrue(options.gdb_debug) + self.assertEqual(options.output_dir, '/gdb/outdir') + + def test_errors(self): + def error(*args): + old_stderr = sys.stderr + stderr = sys.stderr = StringIO() + try: + self.assertRaises(SystemExit, parse_command_line, list(args)) + finally: + sys.stderr = old_stderr + self.assertTrue(stderr.getvalue()) + + error('-1') + error('-I') + error('--version=-a') + error('--version=--annotate=true') + error('--working') + error('--verbose=1') + error('--verbose=1') + error('--cleanup') diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestFlowControl.py b/contrib/tools/cython/Cython/Compiler/Tests/TestFlowControl.py index 443551ab88..cad428607a 100644 --- a/contrib/tools/cython/Cython/Compiler/Tests/TestFlowControl.py +++ b/contrib/tools/cython/Cython/Compiler/Tests/TestFlowControl.py @@ -1,68 +1,68 @@ - -from __future__ import absolute_import - -from copy import deepcopy -from unittest import TestCase - -from Cython.Compiler.FlowControl import ( - NameAssignment, StaticAssignment, Argument, NameDeletion) - - -class FakeType(object): - is_pyobject = True - - -class FakeNode(object): - pos = ('filename.pyx', 1, 2) - cf_state = None - type = FakeType() - - def infer_type(self, scope): - return self.type - - -class FakeEntry(object): - type = FakeType() - - -class TestGraph(TestCase): - def test_deepcopy(self): - lhs, rhs = FakeNode(), FakeNode() - entry = FakeEntry() - entry.pos = lhs.pos - - name_ass = NameAssignment(lhs, rhs, entry) - ass = deepcopy(name_ass) - self.assertTrue(ass.lhs) - self.assertTrue(ass.rhs) - self.assertTrue(ass.entry) - self.assertEqual(ass.pos, name_ass.pos) - self.assertFalse(ass.is_arg) - self.assertFalse(ass.is_deletion) - - static_ass = StaticAssignment(entry) - ass = deepcopy(static_ass) - self.assertTrue(ass.lhs) - self.assertTrue(ass.rhs) - self.assertTrue(ass.entry) - self.assertEqual(ass.pos, static_ass.pos) - self.assertFalse(ass.is_arg) - self.assertFalse(ass.is_deletion) - - arg_ass = Argument(lhs, rhs, entry) - ass = deepcopy(arg_ass) - self.assertTrue(ass.lhs) - self.assertTrue(ass.rhs) - self.assertTrue(ass.entry) - self.assertEqual(ass.pos, arg_ass.pos) - self.assertTrue(ass.is_arg) - self.assertFalse(ass.is_deletion) - - name_del = NameDeletion(lhs, entry) - ass = deepcopy(name_del) - self.assertTrue(ass.lhs) - self.assertTrue(ass.rhs) - self.assertTrue(ass.entry) - self.assertEqual(ass.pos, name_del.pos) - self.assertFalse(ass.is_arg) - self.assertTrue(ass.is_deletion) + +from __future__ import absolute_import + +from copy import deepcopy +from unittest import TestCase + +from Cython.Compiler.FlowControl import ( + NameAssignment, StaticAssignment, Argument, NameDeletion) + + +class FakeType(object): + is_pyobject = True + + +class FakeNode(object): + pos = ('filename.pyx', 1, 2) + cf_state = None + type = FakeType() + + def infer_type(self, scope): + return self.type + + +class FakeEntry(object): + type = FakeType() + + +class TestGraph(TestCase): + def test_deepcopy(self): + lhs, rhs = FakeNode(), FakeNode() + entry = FakeEntry() + entry.pos = lhs.pos + + name_ass = NameAssignment(lhs, rhs, entry) + ass = deepcopy(name_ass) + self.assertTrue(ass.lhs) + self.assertTrue(ass.rhs) + self.assertTrue(ass.entry) + self.assertEqual(ass.pos, name_ass.pos) + self.assertFalse(ass.is_arg) + self.assertFalse(ass.is_deletion) + + static_ass = StaticAssignment(entry) + ass = deepcopy(static_ass) + self.assertTrue(ass.lhs) + self.assertTrue(ass.rhs) + self.assertTrue(ass.entry) + self.assertEqual(ass.pos, static_ass.pos) + self.assertFalse(ass.is_arg) + self.assertFalse(ass.is_deletion) + + arg_ass = Argument(lhs, rhs, entry) + ass = deepcopy(arg_ass) + self.assertTrue(ass.lhs) + self.assertTrue(ass.rhs) + self.assertTrue(ass.entry) + self.assertEqual(ass.pos, arg_ass.pos) + self.assertTrue(ass.is_arg) + self.assertFalse(ass.is_deletion) + + name_del = NameDeletion(lhs, entry) + ass = deepcopy(name_del) + self.assertTrue(ass.lhs) + self.assertTrue(ass.rhs) + self.assertTrue(ass.entry) + self.assertEqual(ass.pos, name_del.pos) + self.assertFalse(ass.is_arg) + self.assertTrue(ass.is_deletion) diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestGrammar.py b/contrib/tools/cython/Cython/Compiler/Tests/TestGrammar.py index 3dddc960b3..a0ece5c1b5 100644 --- a/contrib/tools/cython/Cython/Compiler/Tests/TestGrammar.py +++ b/contrib/tools/cython/Cython/Compiler/Tests/TestGrammar.py @@ -1,129 +1,129 @@ -# mode: run -# tag: syntax - -""" -Uses TreeFragment to test invalid syntax. -""" - -from __future__ import absolute_import - -from ...TestUtils import CythonTest -from ..Errors import CompileError -from .. import ExprNodes - -# Copied from CPython's test_grammar.py -VALID_UNDERSCORE_LITERALS = [ - '0_0_0', - '4_2', - '1_0000_0000', - '0b1001_0100', - '0xffff_ffff', - '0o5_7_7', - '1_00_00.5', - '1_00_00.5j', - '1_00_00.5e5', - '1_00_00j', - '1_00_00e5_1', - '1e1_0', - '.1_4', - '.1_4e1', - '.1_4j', -] - -# Copied from CPython's test_grammar.py -INVALID_UNDERSCORE_LITERALS = [ - # Trailing underscores: - '0_', - '42_', - '1.4j_', - '0b1_', - '0xf_', - '0o5_', - # Underscores in the base selector: - '0_b0', - '0_xf', - '0_o5', - # Underscore right after the base selector: - '0b_0', - '0x_f', - '0o_5', - # Old-style octal, still disallowed: - #'0_7', - #'09_99', - # Special case with exponent: - '0 if 1_Else 1', - # Underscore right before a dot: - '1_.4', - '1_.4j', - # Underscore right after a dot: - '1._4', - '1._4j', - '._5', - # Underscore right after a sign: - '1.0e+_1', - # Multiple consecutive underscores: - '4_______2', - '0.1__4', - '0b1001__0100', - '0xffff__ffff', - '0o5__77', - '1e1__0', - # Underscore right before j: - '1.4_j', - '1.4e5_j', - # Underscore right before e: - '1_e1', - '1.4_e1', - # Underscore right after e: - '1e_1', - '1.4e_1', - # Whitespace in literals - '1_ 2', - '1 _2', - '1_2.2_ 1', - '1_2.2 _1', - '1_2e _1', - '1_2e2 _1', - '1_2e 2_1', -] - - -class TestGrammar(CythonTest): - - def test_invalid_number_literals(self): - for literal in INVALID_UNDERSCORE_LITERALS: - for expression in ['%s', '1 + %s', '%s + 1', '2 * %s', '%s * 2']: - code = 'x = ' + expression % literal - try: - self.fragment(u'''\ - # cython: language_level=3 - ''' + code) - except CompileError as exc: - assert code in [s.strip() for s in str(exc).splitlines()], str(exc) - else: - assert False, "Invalid Cython code '%s' failed to raise an exception" % code - - def test_valid_number_literals(self): - for literal in VALID_UNDERSCORE_LITERALS: - for i, expression in enumerate(['%s', '1 + %s', '%s + 1', '2 * %s', '%s * 2']): - code = 'x = ' + expression % literal - node = self.fragment(u'''\ - # cython: language_level=3 - ''' + code).root - assert node is not None - - literal_node = node.stats[0].rhs # StatListNode([SingleAssignmentNode('x', expr)]) - if i > 0: - # Add/MulNode() -> literal is first or second operand - literal_node = literal_node.operand2 if i % 2 else literal_node.operand1 - if 'j' in literal or 'J' in literal: - assert isinstance(literal_node, ExprNodes.ImagNode) - elif '.' in literal or 'e' in literal or 'E' in literal and not ('0x' in literal or '0X' in literal): - assert isinstance(literal_node, ExprNodes.FloatNode) - else: - assert isinstance(literal_node, ExprNodes.IntNode) - - -if __name__ == "__main__": - import unittest - unittest.main() +# mode: run +# tag: syntax + +""" +Uses TreeFragment to test invalid syntax. +""" + +from __future__ import absolute_import + +from ...TestUtils import CythonTest +from ..Errors import CompileError +from .. import ExprNodes + +# Copied from CPython's test_grammar.py +VALID_UNDERSCORE_LITERALS = [ + '0_0_0', + '4_2', + '1_0000_0000', + '0b1001_0100', + '0xffff_ffff', + '0o5_7_7', + '1_00_00.5', + '1_00_00.5j', + '1_00_00.5e5', + '1_00_00j', + '1_00_00e5_1', + '1e1_0', + '.1_4', + '.1_4e1', + '.1_4j', +] + +# Copied from CPython's test_grammar.py +INVALID_UNDERSCORE_LITERALS = [ + # Trailing underscores: + '0_', + '42_', + '1.4j_', + '0b1_', + '0xf_', + '0o5_', + # Underscores in the base selector: + '0_b0', + '0_xf', + '0_o5', + # Underscore right after the base selector: + '0b_0', + '0x_f', + '0o_5', + # Old-style octal, still disallowed: + #'0_7', + #'09_99', + # Special case with exponent: + '0 if 1_Else 1', + # Underscore right before a dot: + '1_.4', + '1_.4j', + # Underscore right after a dot: + '1._4', + '1._4j', + '._5', + # Underscore right after a sign: + '1.0e+_1', + # Multiple consecutive underscores: + '4_______2', + '0.1__4', + '0b1001__0100', + '0xffff__ffff', + '0o5__77', + '1e1__0', + # Underscore right before j: + '1.4_j', + '1.4e5_j', + # Underscore right before e: + '1_e1', + '1.4_e1', + # Underscore right after e: + '1e_1', + '1.4e_1', + # Whitespace in literals + '1_ 2', + '1 _2', + '1_2.2_ 1', + '1_2.2 _1', + '1_2e _1', + '1_2e2 _1', + '1_2e 2_1', +] + + +class TestGrammar(CythonTest): + + def test_invalid_number_literals(self): + for literal in INVALID_UNDERSCORE_LITERALS: + for expression in ['%s', '1 + %s', '%s + 1', '2 * %s', '%s * 2']: + code = 'x = ' + expression % literal + try: + self.fragment(u'''\ + # cython: language_level=3 + ''' + code) + except CompileError as exc: + assert code in [s.strip() for s in str(exc).splitlines()], str(exc) + else: + assert False, "Invalid Cython code '%s' failed to raise an exception" % code + + def test_valid_number_literals(self): + for literal in VALID_UNDERSCORE_LITERALS: + for i, expression in enumerate(['%s', '1 + %s', '%s + 1', '2 * %s', '%s * 2']): + code = 'x = ' + expression % literal + node = self.fragment(u'''\ + # cython: language_level=3 + ''' + code).root + assert node is not None + + literal_node = node.stats[0].rhs # StatListNode([SingleAssignmentNode('x', expr)]) + if i > 0: + # Add/MulNode() -> literal is first or second operand + literal_node = literal_node.operand2 if i % 2 else literal_node.operand1 + if 'j' in literal or 'J' in literal: + assert isinstance(literal_node, ExprNodes.ImagNode) + elif '.' in literal or 'e' in literal or 'E' in literal and not ('0x' in literal or '0X' in literal): + assert isinstance(literal_node, ExprNodes.FloatNode) + else: + assert isinstance(literal_node, ExprNodes.IntNode) + + +if __name__ == "__main__": + import unittest + unittest.main() diff --git a/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py b/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py index 166bb225b9..4b0bef8175 100644 --- a/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py +++ b/contrib/tools/cython/Cython/Compiler/Tests/TestSignatureMatching.py @@ -16,7 +16,7 @@ class SignatureMatcherTest(unittest.TestCase): Test the signature matching algorithm for overloaded signatures. """ def assertMatches(self, expected_type, arg_types, functions): - match = pt.best_match(arg_types, functions) + match = pt.best_match(arg_types, functions) if expected_type is not None: self.assertNotEqual(None, match) self.assertEqual(expected_type, match.type) |