mirror of
https://github.com/codespell-project/codespell.git
synced 2025-08-06 01:36:26 +08:00
Switch to ignore-regex as a simple flag
This commit is contained in:
@ -464,75 +464,14 @@ def test_ignore_regex_flag(tmpdir, capsys):
|
||||
assert code == EX_USAGE
|
||||
assert 'usage:' in stdout
|
||||
|
||||
# Empty regex matches everything.
|
||||
with open(op.join(d, 'flag.txt'), 'w') as f:
|
||||
f.write('# Please see http://example.com/abandonned for info\n')
|
||||
# Non-matching regex results in nothing being ignored.
|
||||
assert cs.main(f.name, '--ignore-regex=^$') == 1
|
||||
|
||||
# Custom ignore.
|
||||
with open(op.join(d, 'flag.txt'), 'w') as f:
|
||||
f.write('abandonned\n')
|
||||
# A word can be ignored.
|
||||
assert cs.main(f.name, '--ignore-regex=abandonned') == 0
|
||||
|
||||
|
||||
def test_uri(tmpdir, capsys):
|
||||
"""Test ignore regex functionality for URIs."""
|
||||
d = str(tmpdir)
|
||||
|
||||
# Ignoring text in path.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see http://example.com/abandonned for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Test a different protocol.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see https://example.com/abandonned for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Ignoring text in path ending with /.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see http://example.com/abandonned/ for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Ignoring text in domain.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see http://abandonned.com/example for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Ignoring text in anchor.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see http://example.com/ex#abandonned for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Typo because there's no protocol.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see example.com/abandonned for info\n')
|
||||
assert cs.main(f.name) == 1
|
||||
|
||||
# Typo because there aren't enough domain parts.
|
||||
with open(op.join(d, 'uri.txt'), 'w') as f:
|
||||
f.write('# Please see http://abandonned for info\n')
|
||||
assert cs.main(f.name) == 1
|
||||
|
||||
|
||||
def test_email(tmpdir, capsys):
|
||||
"""Test ignore regex functionality for emails."""
|
||||
d = str(tmpdir)
|
||||
|
||||
# Ignoring text in username.
|
||||
with open(op.join(d, 'email.txt'), 'w') as f:
|
||||
f.write('# Please contact abandonned@example.com for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Ignoring text in domain.
|
||||
with open(op.join(d, 'email.txt'), 'w') as f:
|
||||
f.write('# Please contact example@abandonned.com for info\n')
|
||||
assert cs.main(f.name) == 0
|
||||
|
||||
# Typo because there's no TLD for an email.
|
||||
with open(op.join(d, 'email.txt'), 'w') as f:
|
||||
f.write('# Please contact abandonned@example for info\n')
|
||||
assert cs.main(f.name) == 1
|
||||
# Ignoring part of the word can result in odd behavior.
|
||||
assert cs.main(f.name, '--ignore-regex=nn') == 0
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
Reference in New Issue
Block a user