MCPcopy Create free account
hub / github.com/codespell-project/codespell / _check_err_rep

Function _check_err_rep

codespell_lib/tests/test_dictionary.py:138–191  ·  view source on GitHub ↗
(
    err: str,
    rep: str,
    in_aspell: tuple[Optional[bool], Optional[bool]],
    fname: str,
    languages: tuple[Iterable[str], Iterable[str]],
)

Source from the content-addressed store, hash-verified

136
137
138def _check_err_rep(
139 err: str,
140 rep: str,
141 in_aspell: tuple[Optional[bool], Optional[bool]],
142 fname: str,
143 languages: tuple[Iterable[str], Iterable[str]],
144) -> None:
145 assert whitespace.search(err) is None, f"error {err!r} has whitespace"
146 assert "," not in err, f"error {err!r} has a comma"
147 assert len(rep) > 0, f"error {err}: correction {rep!r} must be non-empty"
148 assert not start_whitespace.match(rep), (
149 f"error {err}: correction {rep!r} cannot start with whitespace"
150 )
151 _check_aspell(err, f"error {err!r}", in_aspell[0], fname, languages[0])
152 prefix = f"error {err}: correction {rep!r}"
153 for regex, msg in (
154 (start_comma, "%s starts with a comma"),
155 (
156 whitespace_comma,
157 "%s contains a whitespace character followed by a comma",
158 ),
159 (
160 comma_whitespaces,
161 "%s contains a comma followed by multiple whitespace characters",
162 ),
163 (comma_without_space, "%s contains a comma *not* followed by a space"),
164 (whitespace_end, "%s has a trailing space"),
165 (single_comma, "%s has a single entry but contains a trailing comma"),
166 ):
167 assert not regex.search(rep), msg % (prefix,)
168 del msg
169 if rep.count(","):
170 assert rep.endswith(","), (
171 f'error {err}: multiple corrections must end with trailing ","'
172 )
173 reps = [r.strip() for r in rep.split(",")]
174 reps = [r for r in reps if len(r)]
175 for r in reps:
176 assert err != r.lower(), f"error {err!r} corrects to itself amongst others"
177 _check_aspell(
178 r,
179 f"error {err}: correction {r!r}",
180 in_aspell[1],
181 fname,
182 languages[1],
183 )
184
185 # aspell dictionary is case sensitive, so pass the original case into there
186 # we could ignore the case, but that would miss things like days of the
187 # week which we want to be correct
188 reps = [r.lower() for r in reps]
189 assert len(set(reps)) == len(reps), (
190 f'error {err}: corrections "{rep}" are not (lower-case) unique'
191 )
192
193
194@pytest.mark.parametrize(

Callers 3

test_error_checkingFunction · 0.85

Calls 2

_check_aspellFunction · 0.85
matchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…