chore: import upstream snapshot with attribution
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""
|
||||
Test interaction of logging with configuration system.
|
||||
"""
|
||||
|
||||
import io
|
||||
import logging
|
||||
import re
|
||||
|
||||
from invokeai.app.services.config import InvokeAIAppConfig
|
||||
from invokeai.backend.util.logging import LOG_FORMATTERS, InvokeAILogger
|
||||
|
||||
|
||||
# test formatting
|
||||
# Would prefer to use the capfd/capsys fixture here, but it is broken
|
||||
# when used with the logging module: https://github.com/pytest-dev/pytest/issue
|
||||
def test_formatting():
|
||||
logger = InvokeAILogger.get_logger()
|
||||
stream = io.StringIO()
|
||||
handler = logging.StreamHandler(stream)
|
||||
handler.setFormatter(LOG_FORMATTERS["plain"]())
|
||||
logger.addHandler(handler)
|
||||
logger.info("test1")
|
||||
output = stream.getvalue()
|
||||
assert re.search(r"\[InvokeAI\]::INFO --> test1$", output)
|
||||
|
||||
handler.setFormatter(LOG_FORMATTERS["legacy"]())
|
||||
logger.info("test2")
|
||||
output = stream.getvalue()
|
||||
assert re.search(r">> test2$", output)
|
||||
|
||||
|
||||
# test independence of two loggers with different names
|
||||
def test_independence():
|
||||
logger1 = InvokeAILogger.get_logger()
|
||||
logger2 = InvokeAILogger.get_logger("Test")
|
||||
assert logger1.name == "InvokeAI"
|
||||
assert logger2.name == "Test"
|
||||
assert logger1.level == logging.INFO
|
||||
assert logger2.level == logging.INFO
|
||||
logger2.setLevel(logging.DEBUG)
|
||||
assert logger1.level == logging.INFO
|
||||
assert logger2.level == logging.DEBUG
|
||||
|
||||
|
||||
# test that the logger is returned from two similar get_logger() calls
|
||||
def test_retrieval():
|
||||
logger1 = InvokeAILogger.get_logger()
|
||||
logger2 = InvokeAILogger.get_logger()
|
||||
logger3 = InvokeAILogger.get_logger("Test")
|
||||
assert logger1 == logger2
|
||||
assert logger1 != logger3
|
||||
|
||||
|
||||
# test that the configuration is used to set the initial logging level
|
||||
def test_config():
|
||||
config = InvokeAIAppConfig(log_level="debug")
|
||||
logger1 = InvokeAILogger.get_logger("DebugTest", config=config)
|
||||
assert logger1.level == logging.DEBUG
|
||||
Reference in New Issue
Block a user