Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 1, 2023
1 parent e7c3368 commit 9b07e4b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions scripts/find_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from pathlib import Path

from pysource_codegen import generate
from pysource_minimize import minimize

import black

base_path = Path(__file__).parent


def bug_in_code(src_contents: str, mode: black.FileMode) -> bool:
try:
dst_contents = black.format_str(src_contents, mode=mode)

black.assert_equivalent(src_contents, dst_contents)
black.assert_stable(src_contents, dst_contents, mode=mode)
except Exception as e:
print("error:", e)
return True
return False


def find_issue() -> None:
mode = black.FileMode(
line_length=80,
string_normalization=True,
is_pyi=False,
magic_trailing_comma=False,
)
for seed in range(1000):
src_code = generate(seed)
print("seed:", seed)

compile(src_code, "<string>", "exec")

if bug_in_code(src_code, mode):
minimized = minimize(src_code, lambda code: bug_in_code(code, mode))
assert bug_in_code(minimized, mode)

print("seed:", seed)
print("minimized code:")
print(minimized)

if "with" in minimized:
# propably known issue
# https://github.com/psf/black/issues/3678
# https://github.com/psf/black/issues/3677
continue

(base_path / "min_code.py").write_text(minimized)
return


if __name__ == "__main__":
find_issue()
2 changes: 2 additions & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ pytest >= 6.1.1
pytest-xdist >= 3.0.2
pytest-cov >= 4.1.0
tox
pysource_codegen >= 0.4.1
pysource_minimize >= 0.4.0

0 comments on commit 9b07e4b

Please sign in to comment.