Improved log and log test.
This commit is contained in:
parent
2655e2c65e
commit
7d38dab998
3 changed files with 51 additions and 20 deletions
|
@ -1,17 +1,30 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import pytest
|
||||
from wobbl_tools.text.log import Log
|
||||
|
||||
print("\n==== wobbl_tools.text.log =====")
|
||||
|
||||
test_log = Log("test_log.txt")
|
||||
test_log.clear()
|
||||
|
||||
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())
|
||||
|
||||
expected_content = \
|
||||
"[info]: Testing the log module...[0m[0m\n" \
|
||||
"[[38;5;2m[1mOK[0m]: [0mThis should be fine...[0m[0m\n" \
|
||||
"[38;5;11m[1m[WARNING]: Something happened...[0m[0m\n" \
|
||||
"[38;5;9m[1m[ERROR]: Oh shit![0m[0m\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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue