First commit

This commit is contained in:
2026-07-06 06:00:10 +06:00
commit 68696fa4d2
32 changed files with 1085 additions and 0 deletions

View File

@ -0,0 +1,38 @@
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"]