(expected: str, actual: str)
| 52 | |
| 53 | |
| 54 | def _assert_format_equal(expected: str, actual: str) -> None: |
| 55 | if actual != expected and (conftest.PRINT_FULL_TREE or conftest.PRINT_TREE_DIFF): |
| 56 | bdv: DebugVisitor[Any] |
| 57 | actual_out: str = "" |
| 58 | expected_out: str = "" |
| 59 | if conftest.PRINT_FULL_TREE: |
| 60 | out("Expected tree:", fg="green") |
| 61 | try: |
| 62 | exp_node = black.lib2to3_parse(expected) |
| 63 | bdv = DebugVisitor(print_output=conftest.PRINT_FULL_TREE) |
| 64 | list(bdv.visit(exp_node)) |
| 65 | expected_out = "\n".join(bdv.list_output) |
| 66 | except Exception as ve: |
| 67 | err(str(ve)) |
| 68 | if conftest.PRINT_FULL_TREE: |
| 69 | out("Actual tree:", fg="red") |
| 70 | try: |
| 71 | exp_node = black.lib2to3_parse(actual) |
| 72 | bdv = DebugVisitor(print_output=conftest.PRINT_FULL_TREE) |
| 73 | list(bdv.visit(exp_node)) |
| 74 | actual_out = "\n".join(bdv.list_output) |
| 75 | except Exception as ve: |
| 76 | err(str(ve)) |
| 77 | if conftest.PRINT_TREE_DIFF: |
| 78 | out("Tree Diff:") |
| 79 | out( |
| 80 | diff(expected_out, actual_out, "expected tree", "actual tree") |
| 81 | or "Trees do not differ" |
| 82 | ) |
| 83 | |
| 84 | if actual != expected: |
| 85 | out(diff(expected, actual, "expected", "actual")) |
| 86 | |
| 87 | assert actual == expected |
| 88 | |
| 89 | |
| 90 | class FormatFailure(Exception): |
no test coverage detected