First commit
This commit is contained in:
38
part2-logstats/tests/test_cli.py
Normal file
38
part2-logstats/tests/test_cli.py
Normal 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"]
|
||||
Reference in New Issue
Block a user