Ignore Python 2 specific code in tests

This commit is contained in:
Dave Halter
2020-07-25 01:41:33 +02:00
parent 7c68ba4c45
commit 6eb6ac0bb2
5 changed files with 7 additions and 45 deletions

View File

@@ -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

View File

@@ -109,15 +109,7 @@ 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())
check('def x(a, (b, c)):\n pass', ['a'])
@@ -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):
"""

View File

@@ -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 "

View File

@@ -1,9 +1,4 @@
try:
from itertools import zip_longest
except ImportError:
# Python 2
from itertools import izip_longest as zip_longest
from codecs import BOM_UTF8
import pytest

View File

@@ -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
def test_quoted_strings():