39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from logstats.cli import main
|
|
|
|
|
|
def run(argv, capsys):
|
|
main(argv)
|
|
return capsys.readouterr().out.strip().splitlines()
|
|
|
|
|
|
def test_reports_every_level_present_in_file(tmp_path, capsys):
|
|
log = tmp_path / "a.log"
|
|
log.write_text(
|
|
"2024-03-01 09:00:00 INFO started\n"
|
|
"2024-03-01 09:00:01 ERROR boom\n"
|
|
"2024-03-01 09:00:02 WARNING low disk\n"
|
|
"2024-03-01 09:00:03 DEBUG state dump\n"
|
|
)
|
|
out = run([str(log)], capsys)
|
|
assert len(out) == 4
|
|
|
|
|
|
def test_same_file_gives_same_result_on_every_run(tmp_path, capsys):
|
|
log = tmp_path / "a.log"
|
|
log.write_text(
|
|
"2024-03-01 09:00:00 INFO started\n"
|
|
"2024-03-01 09:00:01 ERROR boom\n"
|
|
)
|
|
first = run([str(log)], capsys)
|
|
second = run([str(log)], capsys)
|
|
assert first == second
|
|
|
|
|
|
def test_aggregates_across_multiple_files(tmp_path, capsys):
|
|
a = tmp_path / "a.log"
|
|
b = tmp_path / "b.log"
|
|
a.write_text("2024-03-01 09:00:00 INFO one\n")
|
|
b.write_text("2024-03-01 09:00:01 INFO two\n")
|
|
out = run([str(a), str(b)], capsys)
|
|
assert out == ["INFO 2"]
|