Skip to content

Commit

Permalink
Fix test_no_hoist_slots
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Aug 6, 2024
1 parent 3ed7c91 commit a765c26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions ascii.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from python_minifier import minify

with open('snippet.py', 'rb') as f:
source = f.read()

minified = minify(source)

with open('minified.py', 'w', encoding='ascii', errors='backslashreplace') as f:
f.write(minified)
18 changes: 14 additions & 4 deletions test/test_hoist_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from python_minifier import unparse
from python_minifier.ast_compare import compare_ast
from python_minifier.ast_printer import print_ast
from python_minifier.rename import add_namespace, bind_names, resolve_names, rename, rename_literals, allow_rename_locals, allow_rename_globals

def hoist(source):
Expand Down Expand Up @@ -496,15 +497,24 @@ def test_no_hoist_slots():
source = '''
class SlotsA(object):
__slots__ = ['aaaaa', 'bbbbb']
notslots = ['aaaaa', 'bbbbb']
class SlotsB(object):
__slots__ = 'aaaaa', 'bbbbb'
notslots = ['aaaaa', 'bbbbb']
'''
expected = '''
class A:
__slots__=['aaaaa', 'bbbbb']
class B:
__slots__='aaaaa', 'bbbbb'
B = 'bbbbb'
A = 'aaaaa'
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 a765c26

Please sign in to comment.