From 6eb6ac0bb24c19fb8dc16777fa25b28e980de213 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 25 Jul 2020 01:41:33 +0200 Subject: [PATCH] Ignore Python 2 specific code in tests --- test/test_cache.py | 7 ++++--- test/test_parser.py | 19 +------------------ test/test_pgen2.py | 12 ------------ test/test_prefix.py | 7 +------ test/test_tokenize.py | 7 +------ 5 files changed, 7 insertions(+), 45 deletions(-) diff --git a/test/test_cache.py b/test/test_cache.py index 793f552..2706827 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -180,12 +180,13 @@ def test_inactive_cache(tmpdir, isolated_parso_cache): @skip_pypy def test_permission_error(monkeypatch): def save(*args, **kwargs): - was_called[0] = True # Python 2... Use nonlocal instead + nonlocal was_called + was_called = True raise PermissionError - was_called = [False] + was_called = False monkeypatch.setattr(cache, '_save_to_file_system', save) with pytest.warns(Warning): parse(path=__file__, cache=True, diff_cache=True) - assert was_called[0] + assert was_called diff --git a/test/test_parser.py b/test/test_parser.py index a941e6a..e087b0d 100644 --- a/test/test_parser.py +++ b/test/test_parser.py @@ -109,16 +109,8 @@ def test_param_splitting(each_version): but Jedi does this to simplify argument parsing. """ def check(src, result): - # Python 2 tuple params should be ignored for now. m = parse(src, version=each_version) - if each_version.startswith('2'): - # We don't want b and c to be a part of the param enumeration. Just - # ignore them, because it's not what we want to support in the - # future. - func = next(m.iter_funcdefs()) - assert [param.name.value for param in func.get_params()] == result - else: - assert not list(m.iter_funcdefs()) + assert not list(m.iter_funcdefs()) check('def x(a, (b, c)):\n pass', ['a']) check('def x((b, c)):\n pass', []) @@ -138,15 +130,6 @@ def test_started_lambda_stmt(each_version): assert m.children[0].type == 'error_node' -def test_python2_octal(each_version): - module = parse('0660', version=each_version) - first = module.children[0] - if each_version.startswith('2'): - assert first.type == 'number' - else: - assert first.type == 'error_node' - - @pytest.mark.parametrize('code', ['foo "', 'foo """\n', 'foo """\nbar']) def test_open_string_literal(each_version, code): """ diff --git a/test/test_pgen2.py b/test/test_pgen2.py index 2166cdc..9b0dd34 100644 --- a/test/test_pgen2.py +++ b/test/test_pgen2.py @@ -1,11 +1,3 @@ -"""Test suite for 2to3's parser and grammar files. - -This is the place to add tests for changes to 2to3's grammar, such as those -merging the grammars for Python 2 and 3. In addition to specific tests for -parts of the grammar we've changed, we also make sure we can parse the -test_grammar.py files from both Python 2 and Python 3. -""" - from textwrap import dedent import pytest @@ -281,10 +273,6 @@ def test_parser_idempotency_extended_unpacking(works_in_py): def test_multiline_bytes_literals(each_version): - """ - It's not possible to get the same result when using \xaa in Python 2/3, - because it's treated differently. - """ s = """ md5test(b"\xaa" * 80, (b"Test Using Larger Than Block-Size Key " diff --git a/test/test_prefix.py b/test/test_prefix.py index 82f7702..a6e254b 100644 --- a/test/test_prefix.py +++ b/test/test_prefix.py @@ -1,9 +1,4 @@ -try: - from itertools import zip_longest -except ImportError: - # Python 2 - from itertools import izip_longest as zip_longest - +from itertools import zip_longest from codecs import BOM_UTF8 import pytest diff --git a/test/test_tokenize.py b/test/test_tokenize.py index 174d274..c0183e5 100644 --- a/test/test_tokenize.py +++ b/test/test_tokenize.py @@ -136,12 +136,7 @@ def test_identifier_contains_unicode(): ''') token_list = _get_token_list(fundef) unicode_token = token_list[1] - if sys.version_info.major >= 3: - assert unicode_token[0] == NAME - else: - # Unicode tokens in Python 2 seem to be identified as operators. - # They will be ignored in the parser, that's ok. - assert unicode_token[0] == ERRORTOKEN + assert unicode_token[0] == NAME def test_quoted_strings():