mirror of
https://github.com/codespell-project/codespell.git
synced 2025-08-06 01:36:26 +08:00
Simplify code
The list comprehension is shorter than the map() version. I feel it is also simpler, although that is debatable. This is consistent with the previous commit.
This commit is contained in:
@ -528,7 +528,7 @@ def ask_for_word_fix(line, wrongword, misspelling, interactivity):
|
|||||||
# we ask the user which word to use
|
# we ask the user which word to use
|
||||||
|
|
||||||
r = ''
|
r = ''
|
||||||
opt = list(map(lambda x: x.strip(), misspelling.data.split(',')))
|
opt = [w.strip() for w in misspelling.data.split(',')]
|
||||||
while not r:
|
while not r:
|
||||||
print("%s Choose an option (blank for none): " % line, end='')
|
print("%s Choose an option (blank for none): " % line, end='')
|
||||||
for i in range(len(opt)):
|
for i in range(len(opt)):
|
||||||
|
@ -393,13 +393,14 @@ def test_case_handling(tmpdir, capsys):
|
|||||||
assert f.read().decode('utf-8') == 'this has an ASCII error'
|
assert f.read().decode('utf-8') == 'this has an ASCII error'
|
||||||
|
|
||||||
|
|
||||||
def test_case_handling_in_fixes(tmpdir, capsys):
|
def _helper_test_case_handling_in_fixes(tmpdir, capsys, reason):
|
||||||
"""Test that the case of fixes is similar to the mispelled word."""
|
|
||||||
d = str(tmpdir)
|
d = str(tmpdir)
|
||||||
with open(op.join(d, 'dictionary_with_reason.txt'), 'w') as f:
|
|
||||||
fix = 'adopter, adaptor'
|
with open(op.join(d, 'dictionary.txt'), 'w') as f:
|
||||||
reason = 'these are different words!'
|
if reason:
|
||||||
f.write(f'adoptor->{fix}, {reason}\n')
|
f.write('adoptor->adopter, adaptor, reason\n')
|
||||||
|
else:
|
||||||
|
f.write('adoptor->adopter, adaptor,\n')
|
||||||
dictionary_name = f.name
|
dictionary_name = f.name
|
||||||
|
|
||||||
# the mispelled word is entirely lowercase
|
# the mispelled word is entirely lowercase
|
||||||
@ -408,6 +409,9 @@ def test_case_handling_in_fixes(tmpdir, capsys):
|
|||||||
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
||||||
# all suggested fixes must be lowercase too
|
# all suggested fixes must be lowercase too
|
||||||
assert 'adopter, adaptor' in stdout
|
assert 'adopter, adaptor' in stdout
|
||||||
|
# the reason, if any, must not be modified
|
||||||
|
if reason:
|
||||||
|
assert 'reason' in stdout
|
||||||
|
|
||||||
# the mispelled word is capitalized
|
# the mispelled word is capitalized
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
@ -415,8 +419,9 @@ def test_case_handling_in_fixes(tmpdir, capsys):
|
|||||||
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
||||||
# all suggested fixes must be capitalized too
|
# all suggested fixes must be capitalized too
|
||||||
assert 'Adopter, Adaptor' in stdout
|
assert 'Adopter, Adaptor' in stdout
|
||||||
# the reason, however, must not be modified
|
# the reason, if any, must not be modified
|
||||||
assert reason in stdout
|
if reason:
|
||||||
|
assert 'reason' in stdout
|
||||||
|
|
||||||
# the mispelled word is entirely uppercase
|
# the mispelled word is entirely uppercase
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
@ -424,8 +429,9 @@ def test_case_handling_in_fixes(tmpdir, capsys):
|
|||||||
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
||||||
# all suggested fixes must be uppercase too
|
# all suggested fixes must be uppercase too
|
||||||
assert 'ADOPTER, ADAPTOR' in stdout
|
assert 'ADOPTER, ADAPTOR' in stdout
|
||||||
# the reason, however, must not be modified
|
# the reason, if any, must not be modified
|
||||||
assert reason in stdout
|
if reason:
|
||||||
|
assert 'reason' in stdout
|
||||||
|
|
||||||
# the mispelled word mixes lowercase and uppercase
|
# the mispelled word mixes lowercase and uppercase
|
||||||
with open(op.join(d, 'bad.txt'), 'w') as f:
|
with open(op.join(d, 'bad.txt'), 'w') as f:
|
||||||
@ -433,8 +439,15 @@ def test_case_handling_in_fixes(tmpdir, capsys):
|
|||||||
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
|
||||||
# all suggested fixes should be lowercase
|
# all suggested fixes should be lowercase
|
||||||
assert 'adopter, adaptor' in stdout
|
assert 'adopter, adaptor' in stdout
|
||||||
# the reason, however, must not be modified
|
# the reason, if any, must not be modified
|
||||||
assert reason in stdout
|
if reason:
|
||||||
|
assert 'reason' in stdout
|
||||||
|
|
||||||
|
|
||||||
|
def test_case_handling_in_fixes(tmpdir, capsys):
|
||||||
|
"""Test that the case of fixes is similar to the mispelled word."""
|
||||||
|
_helper_test_case_handling_in_fixes(tmpdir, capsys, reason=False)
|
||||||
|
_helper_test_case_handling_in_fixes(tmpdir, capsys, reason=True)
|
||||||
|
|
||||||
|
|
||||||
def test_context(tmpdir, capsys):
|
def test_context(tmpdir, capsys):
|
||||||
|
Reference in New Issue
Block a user