Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unit test for csle-common #276

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading