-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config options handle spaces and newlines #93
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,9 @@ def test_eval(test: str, path: str): | |
lines = file.readlines() | ||
|
||
for lineno, line in enumerate(lines, start=1): | ||
# interpret '\n' in comments as actual newlines | ||
line = line.replace("\\n", "\n") | ||
|
||
line = line.strip() | ||
|
||
# add other error codes to check if #INCLUDE is specified | ||
|
@@ -90,9 +93,7 @@ def test_eval(test: str, path: str): | |
|
||
# add command-line args if specified with #ARGS | ||
elif reg_match := re.search(r"(?<=ARGS).*", line): | ||
for arg in reg_match.group().split(" "): | ||
if arg.strip(): | ||
parsed_args.append(arg.strip()) | ||
parsed_args.append(reg_match.group().strip()) | ||
|
||
# skip commented out lines | ||
if not line or line[0] == "#": | ||
|
@@ -444,16 +445,17 @@ def test_200_options(capsys: pytest.CaptureFixture[str]): | |
om.parse_args(args=[f"--trio200-blocking-calls={arg}"]) | ||
) | ||
out, err = capsys.readouterr() | ||
assert not out | ||
assert not out, out | ||
assert all(word in err for word in (str(i), arg, "->")) | ||
|
||
|
||
def test_from_config_file(tmp_path: Path): | ||
def _test_trio200_from_config_common(tmp_path: Path) -> str: | ||
tmp_path.joinpath(".flake8").write_text( | ||
""" | ||
[flake8] | ||
trio200-blocking-calls = | ||
sync_fns.*->the_async_equivalent, | ||
other -> async, | ||
sync_fns.* -> the_async_equivalent, | ||
select = TRIO200 | ||
""" | ||
) | ||
|
@@ -465,12 +467,42 @@ async def foo(): | |
sync_fns.takes_a_long_time() | ||
""" | ||
) | ||
return ( | ||
"./example.py:5:5: TRIO200 User-configured blocking sync call sync_fns.* " | ||
"in async function, consider replacing with the_async_equivalent.\n" | ||
) | ||
|
||
|
||
def test_200_from_config_flake8_internals( | ||
tmp_path: Path, capsys: pytest.CaptureFixture[str] | ||
): | ||
# abuse flake8 internals to avoid having to use subprocess | ||
# which breaks breakpoints and hinders debugging | ||
# TODO: fixture (?) to change working directory | ||
|
||
err_msg = _test_trio200_from_config_common(tmp_path) | ||
# replace ./ with tmp_path/ | ||
err_msg = str(tmp_path) + err_msg[1:] | ||
|
||
from flake8.main.cli import main | ||
|
||
main( | ||
argv=[ | ||
str(tmp_path / "example.py"), | ||
"--append-config", | ||
str(tmp_path / ".flake8"), | ||
] | ||
) | ||
out, err = capsys.readouterr() | ||
assert not err | ||
assert err_msg == out | ||
Comment on lines
+476
to
+498
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. almost funny after the fact how massively the I broke this out as a separate test in case flake8 internals break, but feels like there should be a cleaner solution that doesn't rely on any internal structure at all and just emulates calling it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No specific advice sorry, but I appreciate having this test broken out! |
||
|
||
|
||
def test_200_from_config_subprocess(tmp_path: Path): | ||
err_msg = _test_trio200_from_config_common(tmp_path) | ||
res = subprocess.run(["flake8"], cwd=tmp_path, capture_output=True) | ||
assert not res.stderr | ||
assert res.stdout == ( | ||
b"./example.py:5:5: TRIO200 User-configured blocking sync call sync_fns.* " | ||
b"in async function, consider replacing with the_async_equivalent.\n" | ||
) | ||
assert res.stdout == err_msg.encode("ascii") | ||
|
||
|
||
@pytest.mark.fuzz | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
This type stub file was generated by pyright. | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
"""Command-line implementation of flake8.""" | ||
|
||
def main(argv: Sequence[str] | None = ...) -> int: | ||
"""Execute the main bit of the application. | ||
|
||
This handles the creation of an instance of :class:`Application`, runs it, | ||
and then exits the application. | ||
|
||
:param argv: | ||
The arguments to be passed to the application for parsing. | ||
""" | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to handle spaces in a command line arg - this means that the name
ARGS
is misleading but that is renamed in #91 (rip me bundling changes again).This leads to some minor merge conflicts, but I'll likely rebase #91 on top of this one to fix those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good - I'll next have internet around Jan 9th, so don't panic if review is a bit delayed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gtk, I'll rebase and fix merge conflicts in it. May also split it up if I start messing with stuff in other PR's that might lead to conflicts.