Skip to content

Commit

Permalink
Merge pull request #276 from Limmen/foro
Browse files Browse the repository at this point in the history
add unit test for csle-common
  • Loading branch information
Limmen authored Aug 29, 2023
2 parents 036741a + 5696cfd commit 0cd7724
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def from_dict(d: Dict[str, Any]) -> "SystemIdentificationJobConfig":
break
except Exception:
pass
if system_model is None:
raise ValueError("could not parse system model")
obj = SystemIdentificationJobConfig(
emulation_env_name=d["emulation_env_name"], pid=d["pid"],
progress_percentage=d["progress_percentage"], emulation_statistics_id=d["emulation_statistics_id"],
Expand Down
33 changes: 33 additions & 0 deletions simulation-system/libs/csle-common/tests/test_jobs_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from csle_common.dao.emulation_action.attacker.emulation_attacker_action_id import EmulationAttackerActionId
from csle_common.dao.emulation_action.attacker.emulation_attacker_action_type import EmulationAttackerActionType
from csle_common.dao.emulation_action.defender.emulation_defender_action import EmulationDefenderAction
from csle_common.dao.jobs.system_identification_job_config import SystemIdentificationJobConfig
from csle_common.dao.system_identification.system_identification_config import SystemIdentificationConfig
from csle_common.dao.system_identification.system_model_type import SystemModelType
from csle_common.dao.training.hparam import HParam


class TestJobsDaoSuite:
Expand Down Expand Up @@ -109,3 +113,32 @@ def test_data_collection_job_config(self) -> None:
data_collection_jobs_config.to_dict())
assert (DataCollectionJobConfig.from_dict(data_collection_jobs_config.to_dict()) ==
data_collection_jobs_config)

def test_system_identification_job_config(self) -> None:
"""
Tests creation and dict conversion of the SystemIdentificationJobConfig DAO
:return: None
"""

hparams = dict()
hparams["test"] = HParam(value=1, name="test", descr="test")

system_identification_config = SystemIdentificationConfig(
model_type=SystemModelType.GAUSSIAN_MIXTURE, hparams=hparams,
output_dir="test/test", title="test", log_every=10)

system_identification_job_config = SystemIdentificationJobConfig(
emulation_env_name="test",
emulation_statistics_id=1, pid=123,
log_file_path="test/test",
system_identification_config=system_identification_config, physical_host_ip="1.1.1.1",
progress_percentage=0.5)

assert isinstance(system_identification_job_config.to_dict(), dict)
assert isinstance(SystemIdentificationJobConfig.from_dict(system_identification_job_config.to_dict()),
SystemIdentificationJobConfig)
assert (SystemIdentificationJobConfig.from_dict(system_identification_job_config.to_dict()).to_dict() ==
system_identification_job_config.to_dict())
assert (SystemIdentificationJobConfig.from_dict(system_identification_job_config.to_dict()) ==
system_identification_job_config)

0 comments on commit 0cd7724

Please sign in to comment.