#2716 Initial Implementation + Initial Tests and updated changelog and sphinx documentation.
This commit is contained in:
@@ -9,6 +9,9 @@ io_settings:
|
||||
save_pcap_logs: true
|
||||
save_sys_logs: true
|
||||
sys_log_level: WARNING
|
||||
agent_log_level: INFO
|
||||
save_agent_logs: true
|
||||
write_agent_log_to_terminal: True
|
||||
|
||||
|
||||
game:
|
||||
|
||||
@@ -35,3 +35,7 @@ def test_io_settings():
|
||||
assert env.io.settings.save_step_metadata is False
|
||||
|
||||
assert env.io.settings.write_sys_log_to_terminal is False # false by default
|
||||
|
||||
assert env.io.settings.save_agent_logs is True
|
||||
assert env.io.settings.agent_log_level is LogLevel.INFO
|
||||
assert env.io.settings.write_agent_log_to_terminal is True # Set to True by the config file.
|
||||
|
||||
137
tests/unit_tests/_primaite/_game/_agent/test_agent_log.py
Normal file
137
tests/unit_tests/_primaite/_game/_agent/test_agent_log.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from primaite import PRIMAITE_CONFIG
|
||||
from primaite.game.agent.agent_log import AgentLog
|
||||
from primaite.simulator import LogLevel, SIM_OUTPUT
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def override_dev_mode_temporarily():
|
||||
"""Temporarily turn off dev mode for this test."""
|
||||
primaite_dev_mode = PRIMAITE_CONFIG["developer_mode"]["enabled"]
|
||||
PRIMAITE_CONFIG["developer_mode"]["enabled"] = False
|
||||
yield # run tests
|
||||
PRIMAITE_CONFIG["developer_mode"]["enabled"] = primaite_dev_mode
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def agentlog() -> AgentLog:
|
||||
return AgentLog(agent_name="test_agent")
|
||||
|
||||
|
||||
def test_debug_agent_log_level(agentlog, capsys):
|
||||
"""Test that the debug log level logs debug agent logs and above."""
|
||||
SIM_OUTPUT.agent_log_level = LogLevel.DEBUG
|
||||
SIM_OUTPUT.write_agent_log_to_terminal = True
|
||||
|
||||
test_string = str(uuid4())
|
||||
|
||||
agentlog.debug(msg=test_string, time_step=0)
|
||||
agentlog.info(msg=test_string, time_step=0)
|
||||
agentlog.warning(msg=test_string, time_step=0)
|
||||
agentlog.error(msg=test_string, time_step=0)
|
||||
agentlog.critical(msg=test_string, time_step=0)
|
||||
|
||||
captured = "".join(capsys.readouterr())
|
||||
|
||||
assert test_string in captured
|
||||
assert "DEBUG" in captured
|
||||
assert "INFO" in captured
|
||||
assert "WARNING" in captured
|
||||
assert "ERROR" in captured
|
||||
assert "CRITICAL" in captured
|
||||
|
||||
|
||||
def test_info_agent_log_level(agentlog, capsys):
|
||||
"""Test that the debug log level logs debug agent logs and above."""
|
||||
SIM_OUTPUT.agent_log_level = LogLevel.INFO
|
||||
SIM_OUTPUT.write_agent_log_to_terminal = True
|
||||
|
||||
test_string = str(uuid4())
|
||||
|
||||
agentlog.debug(msg=test_string, time_step=0)
|
||||
agentlog.info(msg=test_string, time_step=0)
|
||||
agentlog.warning(msg=test_string, time_step=0)
|
||||
agentlog.error(msg=test_string, time_step=0)
|
||||
agentlog.critical(msg=test_string, time_step=0)
|
||||
|
||||
captured = "".join(capsys.readouterr())
|
||||
|
||||
assert test_string in captured
|
||||
assert "DEBUG" not in captured
|
||||
assert "INFO" in captured
|
||||
assert "WARNING" in captured
|
||||
assert "ERROR" in captured
|
||||
assert "CRITICAL" in captured
|
||||
|
||||
|
||||
def test_warning_agent_log_level(agentlog, capsys):
|
||||
"""Test that the debug log level logs debug agent logs and above."""
|
||||
SIM_OUTPUT.agent_log_level = LogLevel.WARNING
|
||||
SIM_OUTPUT.write_agent_log_to_terminal = True
|
||||
|
||||
test_string = str(uuid4())
|
||||
|
||||
agentlog.debug(msg=test_string, time_step=0)
|
||||
agentlog.info(msg=test_string, time_step=0)
|
||||
agentlog.warning(msg=test_string, time_step=0)
|
||||
agentlog.error(msg=test_string, time_step=0)
|
||||
agentlog.critical(msg=test_string, time_step=0)
|
||||
|
||||
captured = "".join(capsys.readouterr())
|
||||
|
||||
assert test_string in captured
|
||||
assert "DEBUG" not in captured
|
||||
assert "INFO" not in captured
|
||||
assert "WARNING" in captured
|
||||
assert "ERROR" in captured
|
||||
assert "CRITICAL" in captured
|
||||
|
||||
|
||||
def test_error_agent_log_level(agentlog, capsys):
|
||||
"""Test that the debug log level logs debug agent logs and above."""
|
||||
SIM_OUTPUT.agent_log_level = LogLevel.ERROR
|
||||
SIM_OUTPUT.write_agent_log_to_terminal = True
|
||||
|
||||
test_string = str(uuid4())
|
||||
|
||||
agentlog.debug(msg=test_string, time_step=0)
|
||||
agentlog.info(msg=test_string, time_step=0)
|
||||
agentlog.warning(msg=test_string, time_step=0)
|
||||
agentlog.error(msg=test_string, time_step=0)
|
||||
agentlog.critical(msg=test_string, time_step=0)
|
||||
|
||||
captured = "".join(capsys.readouterr())
|
||||
|
||||
assert test_string in captured
|
||||
assert "DEBUG" not in captured
|
||||
assert "INFO" not in captured
|
||||
assert "WARNING" not in captured
|
||||
assert "ERROR" in captured
|
||||
assert "CRITICAL" in captured
|
||||
|
||||
|
||||
def test_critical_agent_log_level(agentlog, capsys):
|
||||
"""Test that the debug log level logs debug agent logs and above."""
|
||||
SIM_OUTPUT.agent_log_level = LogLevel.CRITICAL
|
||||
SIM_OUTPUT.write_agent_log_to_terminal = True
|
||||
|
||||
test_string = str(uuid4())
|
||||
|
||||
agentlog.debug(msg=test_string, time_step=0)
|
||||
agentlog.info(msg=test_string, time_step=0)
|
||||
agentlog.warning(msg=test_string, time_step=0)
|
||||
agentlog.error(msg=test_string, time_step=0)
|
||||
agentlog.critical(msg=test_string, time_step=0)
|
||||
|
||||
captured = "".join(capsys.readouterr())
|
||||
|
||||
assert test_string in captured
|
||||
assert "DEBUG" not in captured
|
||||
assert "INFO" not in captured
|
||||
assert "WARNING" not in captured
|
||||
assert "ERROR" not in captured
|
||||
assert "CRITICAL" in captured
|
||||
Reference in New Issue
Block a user