#1386: added documentation + dealing with pre-commit checks

This commit is contained in:
Czar Echavez
2023-06-20 11:19:05 +01:00
parent 0ab4520904
commit db67a829d5
17 changed files with 311 additions and 192 deletions

View File

@@ -3,7 +3,7 @@ import tempfile
import time
from datetime import datetime
from pathlib import Path
from typing import Union, Final
from typing import Final, Union
import pandas as pd
@@ -30,7 +30,7 @@ def _get_temp_session_path(session_timestamp: datetime) -> Path:
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."""
session_timestamp: datetime = datetime.now()
@@ -84,7 +84,7 @@ def run_generic(env, config_values):
def compare_file_content(output_a_file_path: str, output_b_file_path: str):
"""Function used to check if output of both given files are the same"""
"""Function used to check if output of both given files are the same."""
with open(output_a_file_path) as f1:
with open(output_b_file_path) as f2:
f1_content = f1.read()
@@ -95,13 +95,15 @@ def compare_file_content(output_a_file_path: str, output_b_file_path: str):
# both files have the same content
return True
# both files have different content
print(f"{output_a_file_path} and {output_b_file_path} has different contents")
print(
f"{output_a_file_path} and {output_b_file_path} has different contents"
)
return False
def compare_transaction_file(output_a_file_path: str, output_b_file_path: str):
"""Function used to check if contents of transaction files are the same"""
"""Function used to check if contents of transaction files are the same."""
# load output a file
data_a = pd.read_csv(output_a_file_path)
@@ -109,19 +111,17 @@ def compare_transaction_file(output_a_file_path: str, output_b_file_path: str):
data_b = pd.read_csv(output_b_file_path)
# remove the time stamp column
data_a.drop('Timestamp', inplace=True, axis=1)
data_b.drop('Timestamp', inplace=True, axis=1)
data_a.drop("Timestamp", inplace=True, axis=1)
data_b.drop("Timestamp", inplace=True, axis=1)
# if the comparison is empty, both files are the same i.e. True
return data_a.compare(data_b).empty
class TestSession:
def __init__(
self,
training_config_path,
laydown_config_path
):
"""Class that contains session values."""
def __init__(self, training_config_path, laydown_config_path):
self.session_timestamp: Final[datetime] = datetime.now()
self.session_dir = _get_session_path(self.session_timestamp)
self.timestamp_str = self.session_timestamp.strftime("%Y-%m-%d_%H-%M-%S")
@@ -140,5 +140,8 @@ class TestSession:
print("Writing Session Metadata file...")
_write_session_metadata_file(
session_dir=self.session_dir, uuid="test", session_timestamp=self.session_timestamp, env=self.env
session_dir=self.session_dir,
uuid="test",
session_timestamp=self.session_timestamp,
env=self.env,
)