Skip to content

Commit

Permalink
Fix test_no_hoist_slots
Browse files Browse the repository at this point in the history
Fix to pass with non-deterministic dict order
  • Loading branch information
dflook committed Aug 7, 2024
1 parent 9c2a03e commit c2496f1
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions test/test_hoist_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,59 +494,26 @@ 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']
notslots = ['aaaaa', 'bbbbb']
notslots = ['aaaaa']
class SlotsB(object):
__slots__ = 'aaaaa', 'bbbbb'
notslots = ['aaaaa', 'bbbbb']
notslots = ['aaaaa']
'''
expected = '''
B = 'bbbbb'
A = 'aaaaa'
class SlotsA(object):
__slots__ = ['aaaaa', 'bbbbb']
notslots = [A, B]
notslots = [A]
class SlotsB(object):
__slots__ = 'aaaaa', 'bbbbb'
notslots = [A, B]
notslots = [A]
'''
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 c2496f1

Please sign in to comment.