Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions cognite/client/data_classes/simulators/routine_revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class SimulatorRoutineRevision(SimulatorRoutineRevisionCore):
id (int): The unique identifier of the simulator routine revision.
external_id (str): The external ID provided by the client. Must be unique for the resource type.
simulator_external_id (str): The external ID of the simulator.
simulator_integration_external_id (str): The external ID of the simulator integration.
simulator_integration_external_id (str | None): The external ID of the simulator integration.
routine_external_id (str): The external ID of the simulator routine.
model_external_id (str): The external ID of the simulator model.
version_number (int): The version number of the simulator routine revision. Unique for each simulator routine.
Expand All @@ -619,7 +619,7 @@ def __init__(
id: int,
external_id: str,
simulator_external_id: str,
simulator_integration_external_id: str,
simulator_integration_external_id: str | None,
routine_external_id: str,
model_external_id: str,
version_number: int,
Expand Down Expand Up @@ -659,7 +659,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None =
external_id=resource["externalId"],
simulator_external_id=resource["simulatorExternalId"],
routine_external_id=resource["routineExternalId"],
simulator_integration_external_id=resource["simulatorIntegrationExternalId"],
simulator_integration_external_id=resource.get("simulatorIntegrationExternalId"),
model_external_id=resource["modelExternalId"],
data_set_id=resource["dataSetId"],
created_by_user_id=resource["createdByUserId"],
Expand Down
12 changes: 6 additions & 6 deletions cognite/client/data_classes/simulators/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SimulatorRoutineCore(WriteableCogniteResource["SimulatorRoutineWrite"], AB
Args:
external_id (str): External id of the simulator routine
model_external_id (str): External id of the associated simulator model
simulator_integration_external_id (str): External id of the associated simulator integration
simulator_integration_external_id (str | None): External id of the associated simulator integration
name (str): The name of the simulator routine
description (str | None): The description of the simulator routine
kind (Literal['long'] | None): The kind of simulator routine. Routines with kind 'long' may have more inputs/outputs, steps, and longer runtime.
Expand All @@ -40,7 +40,7 @@ def __init__(
self,
external_id: str,
model_external_id: str,
simulator_integration_external_id: str,
simulator_integration_external_id: str | None,
name: str,
description: str | None = None,
kind: Literal["long"] | None = None,
Expand All @@ -57,7 +57,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None =
return cls(
external_id=resource["externalId"],
model_external_id=resource["modelExternalId"],
simulator_integration_external_id=resource["simulatorIntegrationExternalId"],
simulator_integration_external_id=resource.get("simulatorIntegrationExternalId"),
name=resource["name"],
description=resource.get("description"),
kind=resource.get("kind"),
Expand Down Expand Up @@ -102,7 +102,7 @@ class SimulatorRoutine(SimulatorRoutineCore):
id (int): A unique id of a simulator routine
external_id (str): External id of the simulator routine
model_external_id (str): External id of the associated simulator model
simulator_integration_external_id (str): External id of the associated simulator integration
simulator_integration_external_id (str | None): External id of the associated simulator integration
name (str): The name of the simulator routine
data_set_id (int): The id of the dataset associated with the simulator routine
simulator_external_id (str): External id of the associated simulator
Expand All @@ -117,7 +117,7 @@ def __init__(
id: int,
external_id: str,
model_external_id: str,
simulator_integration_external_id: str,
simulator_integration_external_id: str | None,
name: str,
data_set_id: int,
simulator_external_id: str,
Expand Down Expand Up @@ -147,7 +147,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None =
external_id=resource["externalId"],
simulator_external_id=resource["simulatorExternalId"],
model_external_id=resource["modelExternalId"],
simulator_integration_external_id=resource["simulatorIntegrationExternalId"],
simulator_integration_external_id=resource.get("simulatorIntegrationExternalId"),
name=resource["name"],
data_set_id=resource["dataSetId"],
description=resource.get("description"),
Expand Down
6 changes: 3 additions & 3 deletions cognite/client/data_classes/simulators/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class SimulationRun(SimulationRunCore):
Args:
id (int): The id of the simulation run
simulator_external_id (str): External id of the associated simulator
simulator_integration_external_id (str): External id of the associated simulator integration
simulator_integration_external_id (str | None): External id of the associated simulator integration
model_external_id (str): External id of the associated simulator model
model_revision_external_id (str): External id of the associated simulator model revision
routine_revision_external_id (str): External id of the associated simulator routine revision
Expand All @@ -236,7 +236,7 @@ def __init__(
self,
id: int,
simulator_external_id: str,
simulator_integration_external_id: str,
simulator_integration_external_id: str | None,
model_external_id: str,
model_revision_external_id: str,
routine_revision_external_id: str,
Expand Down Expand Up @@ -338,7 +338,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None =
created_time=resource["createdTime"],
last_updated_time=resource["lastUpdatedTime"],
simulator_external_id=resource["simulatorExternalId"],
simulator_integration_external_id=resource["simulatorIntegrationExternalId"],
simulator_integration_external_id=resource.get("simulatorIntegrationExternalId"),
model_external_id=resource["modelExternalId"],
model_revision_external_id=resource["modelRevisionExternalId"],
routine_external_id=resource["routineExternalId"],
Expand Down
150 changes: 150 additions & 0 deletions tests/tests_unit/test_data_classes/test_simulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
SimulatorRoutineInputConstant,
SimulatorRoutineInputTimeseries,
SimulatorRoutineOutput,
SimulatorRoutineRevision,
SimulatorRoutineRevisionWrite,
SimulatorRoutineStage,
SimulatorRoutineStep,
SimulatorRoutineStepArguments,
)
from cognite.client.data_classes.simulators.routines import SimulatorRoutine, SimulatorRoutineList
from cognite.client.data_classes.simulators.runs import (
SimulationInput,
SimulationOutput,
SimulationRun,
SimulationRunDataItem,
SimulationRunDataList,
SimulationRunWrite,
Expand Down Expand Up @@ -489,3 +492,150 @@ def test_error_handling(self) -> None:
SimulationRunWrite(
routine_revision_external_id="routine_revision_external_id_1",
)


class TestSimulatorRoutine:
def test_load_with_simulator_integration_externalId(self) -> None:
resource = {
"id": 123,
"externalId": "routine_1",
"simulatorExternalId": "simulator_1",
"modelExternalId": "model_1",
"simulatorIntegrationExternalId": "integration_1",
"name": "Test Routine",
"dataSetId": 456,
"createdTime": 1625247600000,
"lastUpdatedTime": 1625247600000,
}

routine = SimulatorRoutine._load(resource)
assert routine.simulator_integration_external_id == "integration_1"
assert isinstance(routine, SimulatorRoutine)

def test_load_without_simulator_integration_externalId(self) -> None:
resource = {
"id": 124,
"externalId": "routine_2",
"simulatorExternalId": "simulator_2",
"modelExternalId": "model_2",
"name": "Test Routine 2",
"dataSetId": 457,
"createdTime": 1625247600000,
"lastUpdatedTime": 1625247600000,
}

routine = SimulatorRoutine._load(resource)
assert routine.simulator_integration_external_id is None
assert isinstance(routine, SimulatorRoutine)

def test_list_load_with_mixed_simulator_integration_external_ids(self) -> None:
resource_list = [
{
"id": 123,
"externalId": "routine1",
"simulatorExternalId": "simulator1",
"modelExternalId": "model1",
"simulatorIntegrationExternalId": "integration1",
"name": "Routine 1",
"dataSetId": 456,
"createdTime": 1000000,
"lastUpdatedTime": 1000001,
},
{
"id": 124,
"externalId": "routine2",
"simulatorExternalId": "simulator1",
"modelExternalId": "model1",
"name": "Routine 2",
"dataSetId": 456,
"createdTime": 1000001,
"lastUpdatedTime": 1000002,
},
]

routine_list = SimulatorRoutineList._load(resource_list)
assert len(routine_list) == 2
assert routine_list[0].simulator_integration_external_id == "integration1"
assert routine_list[1].simulator_integration_external_id is None


class TestSimulatorRoutineRevision:
def test_load_with_simulator_integration_externalId(self) -> None:
resource = {
"id": 123,
"externalId": "revision1",
"simulatorExternalId": "simulator1",
"routineExternalId": "routine1",
"simulatorIntegrationExternalId": "integration1",
"modelExternalId": "model1",
"dataSetId": 456,
"createdByUserId": "user1",
"createdTime": 1000000,
"versionNumber": 1,
}

revision = SimulatorRoutineRevision._load(resource)
assert revision.simulator_integration_external_id == "integration1"
assert isinstance(revision, SimulatorRoutineRevision)

def test_load_without_simulator_integration_externalId(self) -> None:
resource = {
"id": 123,
"externalId": "revision1",
"simulatorExternalId": "simulator1",
"routineExternalId": "routine1",
"modelExternalId": "model1",
"dataSetId": 456,
"createdByUserId": "user1",
"createdTime": 1000000,
"versionNumber": 1,
}

revision = SimulatorRoutineRevision._load(resource)
assert revision.simulator_integration_external_id is None
assert isinstance(revision, SimulatorRoutineRevision)


class TestSimulationRun:
def test_load_with_simulator_integration_externalId(self) -> None:
resource = {
"id": 123,
"createdTime": 1000000,
"lastUpdatedTime": 1000001,
"simulatorExternalId": "simulator1",
"simulatorIntegrationExternalId": "integration1",
"modelExternalId": "model1",
"modelRevisionExternalId": "model_rev1",
"routineExternalId": "routine1",
"routineRevisionExternalId": "routine_rev1",
"status": "success",
"dataSetId": 456,
"runType": "manual",
"userId": "user1",
"logId": 789,
}

run = SimulationRun._load(resource)
assert run.simulator_integration_external_id == "integration1"
assert isinstance(run, SimulationRun)

def test_load_without_simulator_integration_externalId(self) -> None:
resource = {
"id": 123,
"createdTime": 1000000,
"lastUpdatedTime": 1000001,
"simulatorExternalId": "simulator1",
"modelExternalId": "model1",
"modelRevisionExternalId": "model_rev1",
"routineExternalId": "routine1",
"routineRevisionExternalId": "routine_rev1",
"status": "success",
"dataSetId": 456,
"runType": "manual",
"userId": "user1",
"logId": 789,
}

run = SimulationRun._load(resource)
assert run.simulator_integration_external_id is None
assert isinstance(run, SimulationRun)