Skip to content

Commit 37d5ad2

Browse files
Merge pull request #33 from InformaticsMatters/instance-directory
Add "instance_directory" property
2 parents ad00205 + 13e4470 commit 37d5ad2

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

tests/test_test_api_adapter.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,20 @@ def test_get_running_workflow_step_with_prior_step():
324324
def test_create_instance():
325325
# Arrange
326326
utaa = UnitTestWorkflowAPIAdapter()
327+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
328+
response = utaa.create_running_workflow(
329+
user_id="dlister",
330+
workflow_id=response["id"],
331+
project_id=TEST_PROJECT_ID,
332+
variables={},
333+
)
334+
response, _ = utaa.create_running_workflow_step(
335+
running_workflow_id=response["id"], step="step-1"
336+
)
337+
rwfs_id = response["id"]
327338

328339
# Act
329-
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
340+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
330341

331342
# Assert
332343
assert "id" in response
@@ -335,14 +346,79 @@ def test_create_instance():
335346
def test_create_and_get_instance():
336347
# Arrange
337348
utaa = UnitTestWorkflowAPIAdapter()
338-
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
349+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
350+
response = utaa.create_running_workflow(
351+
user_id="dlister",
352+
workflow_id=response["id"],
353+
project_id=TEST_PROJECT_ID,
354+
variables={},
355+
)
356+
response, _ = utaa.create_running_workflow_step(
357+
running_workflow_id=response["id"], step="step-1"
358+
)
359+
rwfs_id = response["id"]
360+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
339361
instance_id = response["id"]
340362

341363
# Act
342364
response, _ = utaa.get_instance(instance_id=instance_id)
343365

344366
# Assert
345-
assert response["running_workflow_step_id"] == "r-workflow-step-000"
367+
assert response["running_workflow_step_id"] == rwfs_id
368+
369+
370+
def test_create_instance_and_get_step_instance_directory():
371+
# Arrange
372+
utaa = UnitTestWorkflowAPIAdapter()
373+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
374+
response = utaa.create_running_workflow(
375+
user_id="dlister",
376+
workflow_id=response["id"],
377+
project_id=TEST_PROJECT_ID,
378+
variables={},
379+
)
380+
response, _ = utaa.create_running_workflow_step(
381+
running_workflow_id=response["id"], step="step-1"
382+
)
383+
rwfs_id = response["id"]
384+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
385+
i_id = response["id"]
386+
387+
# Act
388+
response, _ = utaa.get_running_workflow_step(running_workflow_step_id=rwfs_id)
389+
390+
# Assert
391+
assert "instance_directory" in response
392+
assert response["instance_directory"] == f".{i_id}"
393+
394+
395+
def test_create_instance_and_get_step_instance_directory_by_name():
396+
# Arrange
397+
utaa = UnitTestWorkflowAPIAdapter()
398+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
399+
wf_id = response["id"]
400+
response = utaa.create_running_workflow(
401+
user_id="dlister",
402+
workflow_id=wf_id,
403+
project_id=TEST_PROJECT_ID,
404+
variables={},
405+
)
406+
rwf_id = response["id"]
407+
response, _ = utaa.create_running_workflow_step(
408+
running_workflow_id=rwf_id, step="step-1"
409+
)
410+
rwfs_id = response["id"]
411+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
412+
i_id = response["id"]
413+
414+
# Act
415+
response, _ = utaa.get_running_workflow_step_by_name(
416+
running_workflow_id=rwf_id, name="step-1"
417+
)
418+
419+
# Assert
420+
assert "instance_directory" in response
421+
assert response["instance_directory"] == f".{i_id}"
346422

347423

348424
def test_get_workflow_steps_driving_this_step_when_1st_step():

tests/wapi_adapter.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def get_workflow_steps_driving_this_step(
287287
"steps": wf_response["steps"].copy(),
288288
}, 0
289289

290-
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
290+
def get_instance(self, *, instance_id: str) -> tuple[dict[str, Any], int]:
291291
UnitTestWorkflowAPIAdapter.lock.acquire()
292292
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
293293
instances = Unpickler(pickle_file).load()
@@ -377,6 +377,17 @@ def create_instance(self, *, running_workflow_step_id: str) -> dict[str, Any]:
377377

378378
with open(_INSTANCE_PICKLE_FILE, "wb") as pickle_file:
379379
Pickler(pickle_file).dump(instances)
380+
381+
# Use the instance ID as the step's instance-directory (prefixing with '.')
382+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
383+
running_workflow_step = Unpickler(pickle_file).load()
384+
assert running_workflow_step_id in running_workflow_step
385+
running_workflow_step[running_workflow_step_id][
386+
"instance_directory"
387+
] = f".{instance_id}"
388+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
389+
Pickler(pickle_file).dump(running_workflow_step)
390+
380391
UnitTestWorkflowAPIAdapter.lock.release()
381392

382393
return {"id": instance_id}

workflow/workflow_abc.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ def get_workflow_steps_driving_this_step(
334334
# }
335335
# ]
336336
# }
337-
#
338-
# Additionally, if the step has started (an instance has been created)
339-
# each entry on the array of steps will contain a "instance_directory" property
340-
# that is the directory within the Project that's the step's working directory.
341-
#
342-
# "instance_directory": ".instance-00000000-0000-0000-0000-00000000000a",
343337

344338
@abstractmethod
345339
def get_instance(self, *, instance_id: str) -> tuple[dict[str, Any], int]:

0 commit comments

Comments
 (0)