Skip to content

Commit

Permalink
Fix no hoist __slots__ test on Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Aug 6, 2024
1 parent 326b0f3 commit 3343406
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/test_hoist_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ def test_hoisted_types_py2():
compare_ast(expected_ast, actual_ast)

def test_no_hoist_slots():
if sys.version_info < (3, 3):
pytest.skip('Literal rename iterates bindings in a different order with Python2')

source = '''
class SlotsA(object):
__slots__ = ['aaaaa', 'bbbbb']
Expand All @@ -515,6 +518,35 @@ class SlotsB(object):
expected_ast = ast.parse(expected)
actual_ast = hoist(source)

print(print_ast(expected_ast))
print(print_ast(actual_ast))
compare_ast(expected_ast, actual_ast)

def test_no_hoist_slots_python2():
if sys.version_info > (2, 7):
pytest.skip('Literal rename iterates bindings in a different order with Python3')

source = '''
class SlotsA(object):
__slots__ = ['aaaaa', 'bbbbb']
notslots = ['aaaaa', 'bbbbb']
class SlotsB(object):
__slots__ = 'aaaaa', 'bbbbb'
notslots = ['aaaaa', 'bbbbb']
'''
expected = '''
B = 'aaaaa'
A = 'bbbbb'
class SlotsA(object):
__slots__ = ['aaaaa', 'bbbbb']
notslots = [A, B]
class SlotsB(object):
__slots__ = 'aaaaa', 'bbbbb'
notslots = [A, B]
'''
expected_ast = ast.parse(expected)
actual_ast = hoist(source)

print(print_ast(expected_ast))
print(print_ast(actual_ast))
compare_ast(expected_ast, actual_ast)

0 comments on commit 3343406

Please sign in to comment.