Skip to content

Commit

Permalink
refactor: format test/conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wookayin committed Dec 26, 2023
1 parent d31e2bb commit 918bb4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 14 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ast
import json
import symtable
from textwrap import dedent

from semshi.parser import Parser
Expand All @@ -20,27 +22,32 @@ def make_tree(names):
n['names'].append(node.symname)
return root['top']


def dump_dict(root):
import json
print(json.dumps(root, indent=4))


def dump_symtable(table_or_code):
import symtable
if isinstance(table_or_code, str):
table = symtable.symtable(dedent(table_or_code), '?', 'exec')
else:
table = table_or_code

def visit_table(table, indent=0):
it = indent*' '
it = indent * ' '
print(it, table)
if isinstance(table, symtable.Class):
print(table.get_methods())
for symbol in table.get_symbols():
print((indent+4)*' ', symbol, symbol.is_namespace(), symbol.get_namespaces(), 'free', symbol.is_free(), 'local', symbol.is_local(), 'global', symbol.is_global())
print((indent + 4) * ' ', symbol, symbol.is_namespace(),
symbol.get_namespaces(), 'free', symbol.is_free(), 'local',
symbol.is_local(), 'global', symbol.is_global())
for child in table.get_children():
visit_table(child, indent=indent+4)
visit_table(child, indent=indent + 4)

visit_table(table)


def dump_ast(node_or_code):
if isinstance(node_or_code, str):
node = ast.parse(dedent(node_or_code))
Expand All @@ -49,13 +56,15 @@ def dump_ast(node_or_code):
tree = ast.dump(node)
print(tree)


def parse(code):
add, remove = Parser().parse(dedent(code))
assert len(remove) == 0
for node in add:
node.base_table()
return add


def make_parser(code):
parser = Parser()
add, remove = parser.parse(dedent(code))
Expand Down
5 changes: 3 additions & 2 deletions test/test_fuzz.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
from semshi.parser import UnparsableError

import pytest

from .conftest import parse, dump_symtable
from semshi.parser import UnparsableError

from .conftest import dump_symtable, parse


def test_multiple_files():
Expand Down

0 comments on commit 918bb4c

Please sign in to comment.