wobbl_tools/tests/text/test_log.py

31 lines
849 B
Python
Raw Permalink Normal View History

2025-01-13 17:00:02 +01:00
#!/usr/bin/python3
2025-01-13 18:00:54 +01:00
import pytest
2025-01-13 17:00:02 +01:00
from wobbl_tools.text.log import Log
print("\n==== wobbl_tools.text.log =====")
test_log = Log("test_log.txt")
2025-01-13 18:00:54 +01:00
test_log.clear()
2025-01-13 17:00:02 +01:00
test_log.write("Testing the log module...")
test_log.write("This should be fine...", "ok")
test_log.write("Something happened...", "warning")
test_log.write("Oh shit!", "error")
print("Logfile contents:")
print(test_log.read())
2025-01-13 18:00:54 +01:00
expected_content = \
"[info]: Testing the log module...\n" \
"[OK]: This should be fine...\n" \
"[WARNING]: Something happened...\n" \
"[ERROR]: Oh shit!\n"
assert test_log.read() == expected_content
without_file = Log()
with pytest.raises(FileNotFoundError, match="You didn't specify a log path at the log instance definition."):
without_file.read()