Skip to content

Commit 9b07e4b

Browse files
committed
wip
1 parent e7c3368 commit 9b07e4b

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

scripts/find_issue.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pathlib import Path
2+
3+
from pysource_codegen import generate
4+
from pysource_minimize import minimize
5+
6+
import black
7+
8+
base_path = Path(__file__).parent
9+
10+
11+
def bug_in_code(src_contents: str, mode: black.FileMode) -> bool:
12+
try:
13+
dst_contents = black.format_str(src_contents, mode=mode)
14+
15+
black.assert_equivalent(src_contents, dst_contents)
16+
black.assert_stable(src_contents, dst_contents, mode=mode)
17+
except Exception as e:
18+
print("error:", e)
19+
return True
20+
return False
21+
22+
23+
def find_issue() -> None:
24+
mode = black.FileMode(
25+
line_length=80,
26+
string_normalization=True,
27+
is_pyi=False,
28+
magic_trailing_comma=False,
29+
)
30+
for seed in range(1000):
31+
src_code = generate(seed)
32+
print("seed:", seed)
33+
34+
compile(src_code, "<string>", "exec")
35+
36+
if bug_in_code(src_code, mode):
37+
minimized = minimize(src_code, lambda code: bug_in_code(code, mode))
38+
assert bug_in_code(minimized, mode)
39+
40+
print("seed:", seed)
41+
print("minimized code:")
42+
print(minimized)
43+
44+
if "with" in minimized:
45+
# propably known issue
46+
# https://github.com/psf/black/issues/3678
47+
# https://github.com/psf/black/issues/3677
48+
continue
49+
50+
(base_path / "min_code.py").write_text(minimized)
51+
return
52+
53+
54+
if __name__ == "__main__":
55+
find_issue()

test_requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ pytest >= 6.1.1
44
pytest-xdist >= 3.0.2
55
pytest-cov >= 4.1.0
66
tox
7+
pysource_codegen >= 0.4.1
8+
pysource_minimize >= 0.4.0

0 commit comments

Comments
 (0)