Skip to content

Commit

Permalink
Fix new ruff errors reported by CI (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos authored Apr 24, 2023
1 parent 9e383bc commit ca016c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
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

0 comments on commit ca016c1

Please sign in to comment.