# 915 - Fixed issue in conftest.py where session_path and timestamp_str were not being passed to Primaite.

- Also now logging all test outputs to temp directory.
This commit is contained in:
Chris McCarthy
2023-06-07 22:57:37 +01:00
parent 273876873e
commit 02e37e5096

View File

@@ -1,5 +1,7 @@
# Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence. # Crown Copyright (C) Dstl 2022. DEFCON 703. Shared in confidence.
import tempfile
import time import time
from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import Union from typing import Union
@@ -9,14 +11,38 @@ ACTION_SPACE_NODE_VALUES = 1
ACTION_SPACE_NODE_ACTION_VALUES = 1 ACTION_SPACE_NODE_ACTION_VALUES = 1
def _get_temp_session_path(session_timestamp: datetime) -> Path:
"""
Get a temp directory session path the test session will output to.
:param session_timestamp: This is the datetime that the session started.
:return: The session directory path.
"""
date_dir = session_timestamp.strftime("%Y-%m-%d")
session_dir = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S")
session_path = Path(tempfile.gettempdir()) / "primaite" / date_dir / session_dir
session_path.mkdir(exist_ok=True, parents=True)
return session_path
def _get_primaite_env_from_config( def _get_primaite_env_from_config(
training_config_path: Union[str, Path], lay_down_config_path: Union[str, Path] training_config_path: Union[str, Path],
lay_down_config_path: Union[str, Path]
): ):
"""Takes a config path and returns the created instance of Primaite.""" """Takes a config path and returns the created instance of Primaite."""
session_timestamp: datetime = datetime.now()
session_path = _get_temp_session_path(session_timestamp)
timestamp_str = session_timestamp.strftime("%Y-%m-%d_%H-%M-%S")
env = Primaite( env = Primaite(
training_config_path=training_config_path, training_config_path=training_config_path,
lay_down_config_path=lay_down_config_path, lay_down_config_path=lay_down_config_path,
transaction_list=[], transaction_list=[],
session_path=session_path,
timestamp_str=timestamp_str,
) )
config_values = env.config_values config_values = env.config_values
config_values.num_steps = env.episode_steps config_values.num_steps = env.episode_steps