A Python library for interacting and working with the Woop blockchain.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pywiki/tests/logging-pyhmy/test_logging.py

32 lines
994 B

import os
import pytest
from pyhmy import logging
def test_basic_logger():
if os.path.exists(f"{os.getcwd()}/logs/pytest.log"):
os.remove(f"{os.getcwd()}/logs/pytest.log")
logger = logging.ControlledLogger("pytest", "logs/")
assert os.path.exists(f"{os.getcwd()}/logs/pytest.log")
logger.info("test info")
logger.debug("test debug")
logger.error("test error")
logger.warning("test warning")
with open(f"{os.getcwd()}/logs/pytest.log", 'r') as f:
log_file_contents = f.readlines()
assert not log_file_contents
logger.write()
with open(f"{os.getcwd()}/logs/pytest.log", 'r') as f:
log_file_contents = f.readlines()
for line in log_file_contents:
if "INFO" in line:
assert "test info" in line
if "DEBUG" in line:
assert "test debug" in line
if "WARNING" in line:
assert "test warning" in line
if "ERROR" in line:
assert "test error" in line