def test_anonymize_too_many_digits(ip, exp, test_file, capsys): f = test_file(ip) main([str(f), '--anonymize', '25']) with open(f) as x: assert x.read() == exp captured = capsys.readouterr() assert ( '\u001b[33mWARNING: anonymize is set larger than 4. ' 'IPv4 will be rewritten to 0.0.0.0\u001b[0m\n' ) in captured.out assert ( '\u001b[33mWARNING: anonymize is set larger than 8. ' 'IPv6 will be rewritten to 0:0:0:0:0:0:0:0\u001b[0m\n' ) in captured.out
def test_anonymize_ipv4_default(ip, exp, test_file): f = test_file(ip) main([str(f), '--anonymize']) with open(f) as x: assert x.read() == exp
def test_error_file_not_found(): with pytest.raises(Exception): main(['not_existing_file.log'])
def test_specific_log_nr(tmpdir): f = tmpdir.join('test.log.7') f.write('foo,1.2.3.4,bar\n') main([str(f)[:-2], '--log-nr', '7']) with open(f) as x: assert x.read() == 'foo,-,bar\n'
def test_replace_ipv6(ip, test_file): f = test_file(ip) main([str(f)]) with open(f) as x: assert x.read() == '-'
def test_dry_run(test_file): test_str = 'foo,bar,10.20.30.40,baz\n' f = test_file(test_str) main([str(f), '--dry-run']) with open(f) as x: assert x.read() == test_str
def test_show_version(): with pytest.raises(SystemExit): main(['--version'])
def test_show_help(): with pytest.raises(SystemExit): main(['--help'])
def test_anonymize_ipv6_multiple_digits(ip, exp, test_file): f = test_file(ip) main([str(f), '--anonymize', '2']) with open(f) as x: assert x.read() == exp