MCPcopy Create free account
hub / github.com/psf/black / test_idempotent_any_syntatically_valid_python

Function test_idempotent_any_syntatically_valid_python

scripts/fuzz.py:41–71  ·  view source on GitHub ↗
(
    src_contents: str, mode: black.FileMode
)

Source from the content-addressed store, hash-verified

39 ),
40)
41def test_idempotent_any_syntatically_valid_python(
42 src_contents: str, mode: black.FileMode
43) -> None:
44 # Before starting, let's confirm that the input string is valid Python:
45 compile(src_contents, "<string>", "exec") # else the bug is in hypothesmith
46
47 # Then format the code...
48 try:
49 dst_contents = black.format_str(src_contents, mode=mode)
50 except black.InvalidInput:
51 # This is a bug - if it's valid Python code, as above, Black should be
52 # able to cope with it. See issues #970, #1012
53 # TODO: remove this try-except block when issues are resolved.
54 return
55 except TokenError as e:
56 if ( # Special-case logic for backslashes followed by newlines or end-of-input
57 e.args[0] == "EOF in multi-line statement"
58 and re.search(r"\\($|\r?\n)", src_contents) is not None
59 ):
60 # This is a bug - if it's valid Python code, as above, Black should be
61 # able to cope with it. See issue #1012.
62 # TODO: remove this block when the issue is resolved.
63 return
64 raise
65
66 # And check that we got equivalent and stable output.
67 black.assert_equivalent(src_contents, dst_contents)
68 black.assert_stable(src_contents, dst_contents, mode=mode)
69
70 # Future test: check that pure-python and mypyc versions of black
71 # give identical output for identical input?
72
73
74if __name__ == "__main__":

Callers 1

fuzz.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected