Skip to content

Commit

Permalink
small polish
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Sep 28, 2023
1 parent a6984c4 commit 0c37a9d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from black.mode import TargetVersion
from black.output import diff, err, out

from . import conftest

PYTHON_SUFFIX = ".py"
ALLOWED_SUFFIXES = (PYTHON_SUFFIX, ".pyi", ".out", ".diff", ".ipynb")

Expand All @@ -34,32 +36,29 @@


def _assert_format_equal(expected: str, actual: str) -> None:
# need to import inside the function for the monkeypatching tests to work
from .conftest import PRINT_FULL_TREE, PRINT_TREE_DIFF

if actual != expected and (PRINT_FULL_TREE or PRINT_TREE_DIFF):
if actual != expected and (conftest.PRINT_FULL_TREE or conftest.PRINT_TREE_DIFF):
bdv: DebugVisitor[Any]
actual_out: str = ""
expected_out: str = ""
if PRINT_FULL_TREE:
if conftest.PRINT_FULL_TREE:
out("Expected tree:", fg="green")
try:
exp_node = black.lib2to3_parse(expected)
bdv = DebugVisitor(print_output=bool(PRINT_FULL_TREE))
bdv = DebugVisitor(print_output=conftest.PRINT_FULL_TREE)
list(bdv.visit(exp_node))
expected_out = "\n".join(bdv.list_output)
except Exception as ve:
err(str(ve))
if PRINT_FULL_TREE:
if conftest.PRINT_FULL_TREE:
out("Actual tree:", fg="red")
try:
exp_node = black.lib2to3_parse(actual)
bdv = DebugVisitor(print_output=bool(PRINT_FULL_TREE))
bdv = DebugVisitor(print_output=conftest.PRINT_FULL_TREE)
list(bdv.visit(exp_node))
actual_out = "\n".join(bdv.list_output)
except Exception as ve:
err(str(ve))
if PRINT_TREE_DIFF:
if conftest.PRINT_TREE_DIFF:
out("Tree Diff:")
out(
diff(expected_out, actual_out, "expected tree", "actual tree")
Expand Down

0 comments on commit 0c37a9d

Please sign in to comment.