Skip to content
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

Fix new ruff errors reported by CI #2834

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def run_codespell(
"""Run codespell."""
args = tuple(str(arg) for arg in args)
proc = subprocess.run(
["codespell", "--count", *args], cwd=cwd, capture_output=True, encoding="utf-8"
["codespell", "--count", *args], # noqa: S603, S607
cwd=cwd,
capture_output=True,
encoding="utf-8",
)
count = int(proc.stderr.split("\n")[-2])
return count
Expand Down
43 changes: 17 additions & 26 deletions codespell_lib/tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
if os.getenv("REQUIRE_ASPELL", "false").lower() == "true":
raise RuntimeError(
"Cannot run complete tests without aspell when "
"REQUIRE_ASPELL=true. Got error during import:\n{}".format(exp)
f"REQUIRE_ASPELL=true. Got error during import:\n{exp}"
)
warnings.warn(
"aspell not found, but not required, skipping aspell tests. Got "
"error during import:\n{}".format(exp),
f"error during import:\n{exp}",
stacklevel=2,
)

Expand Down Expand Up @@ -277,10 +277,9 @@ def test_dictionary_looping(
for line in fid:
err, rep = line.split("->")
err = err.lower()
assert err not in this_err_dict, "error {!r} already exists in {}".format(
err,
short_fname,
)
assert (
err not in this_err_dict
), f"error {err:!r} already exists in {short_fname}"
rep = rep.rstrip("\n")
reps = [r.strip() for r in rep.lower().split(",")]
reps = [r for r in reps if len(r)]
Expand All @@ -289,38 +288,31 @@ def test_dictionary_looping(
for err in this_err_dict:
for r in this_err_dict[err]:
assert r not in this_err_dict, (
"error {}: correction {} is an error itself in the same "
"dictionary file {}".format(err, r, short_fname)
f"error {err}: correction {r} is an error itself "
f"in the same dictionary file {short_fname}"
)
pair = (short_fname, short_fname)
assert pair not in global_pairs
global_pairs.add(pair)
for other_fname, other_err_dict in global_err_dicts.items():
# error duplication (eventually maybe we should just merge?)
for err in this_err_dict:
assert (
err not in other_err_dict
), "error {!r} in dictionary {} already exists in dictionary {}".format(
err,
short_fname,
other_fname,
assert err not in other_err_dict, (
f"error {err:!r} in dictionary {short_fname} "
f"already exists in dictionary {other_fname}"
)
# 2. check corrections in this dict against other dicts (upper)
pair = (short_fname, other_fname)
if pair not in allowed_dups:
for err in this_err_dict:
assert (
err not in other_err_dict
), "error {!r} in dictionary {} already exists in dictionary {}".format(
err,
short_fname,
other_fname,
assert err not in other_err_dict, (
f"error {err:!r} in dictionary {short_fname} "
f"already exists in dictionary {other_fname}"
)
for r in this_err_dict[err]:
assert r not in other_err_dict, (
"error %s: correction %s from dictionary %s is an "
"error itself in dictionary %s"
% (err, r, short_fname, other_fname)
f"error {err}: correction {r} from dictionary {short_fname} "
f"is an error itself in dictionary {other_fname}"
)
assert pair not in global_pairs
global_pairs.add(pair)
Expand All @@ -330,9 +322,8 @@ def test_dictionary_looping(
for err in other_err_dict:
for r in other_err_dict[err]:
assert r not in this_err_dict, (
"error %s: correction %s from dictionary %s is an "
"error itself in dictionary %s"
% (err, r, other_fname, short_fname)
f"error {err}: correction {r} from dictionary {other_fname} "
f"is an error itself in dictionary {short_fname}"
)
assert pair not in global_pairs
global_pairs.add(pair)
Expand Down