import logging
import pytest

from psi_utils.logger import Logger


class TestLogger_UnitTests:

    @pytest.mark.unit
    def test_logger(self):
        # Test init, _set_level(), and get_logger()
        logger = Logger()
        assert logger.get_logger().level == logging.DEBUG
        logger = Logger(level="info")
        assert logger.get_logger().level == logging.INFO
        logger = Logger(level="warning")
        assert logger.get_logger().level == logging.WARNING
        logger = Logger(level="error")
        assert logger.get_logger().level == logging.ERROR
        logger = Logger(level="critical")
        assert logger.get_logger().level == logging.CRITICAL
        logger = Logger(level="none")
        assert logger.get_logger().level == logging.NOTSET
        logger._set_level("info")

        # Test log_it
        @logger.log_it
        def test_fn():
            pass

        test_fn()

        # Test __repr__
        assert str(logger) == "<class 'psi_utils.logger.Logger'>"

        # Test __getitem__()
        assert logger["_level"] == "info"
