Switch to ignore-regex as a simple flag

This commit is contained in:
jonmeow
2020-07-24 12:41:17 -07:00
parent 3508ed6b5f
commit 9d6f0051b2
2 changed files with 23 additions and 80 deletions

View File

@ -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