Skip to content

Commit

Permalink
adds mocked tests for get_engine function
Browse files Browse the repository at this point in the history
  • Loading branch information
markjschreiber committed Sep 19, 2024
1 parent d4c644d commit 1f7cb9b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
7 changes: 3 additions & 4 deletions omics/cli/run_analyzer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
_cwl_task_regex = r"^(^\D+)(_\d+)?$"


def get_engine(workflow_arn, session) -> str:
"""Get the engine name for the workflow_arn"""
omics = session.client("omics")
def get_engine(workflow_arn: str, client) -> str:
"""Get the engine name for the workflow_arn using the omics client"""
id = workflow_arn.split("/")[-1]
return omics.get_workflow(id)["engine"]
return client.get_workflow(id=id)["engine"]


def task_base_name(name: str, engine: str) -> str:
Expand Down
38 changes: 38 additions & 0 deletions tests/cli/run_analyzer/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import unittest

import botocore
from botocore.stub import Stubber

import omics.cli.run_analyzer.utils as utils


Expand Down Expand Up @@ -35,3 +38,38 @@ def _weight(instance):
self.assertTrue(_weight("omics.m.4xlarge") < _weight("omics.r.4xlarge"))
self.assertTrue(_weight("omics.r.4xlarge") < _weight("omics.g4dn.4xlarge"))
self.assertTrue(_weight("omics.r.4xlarge") < _weight("omics.g5.4xlarge"))

def test_get_engine_with_workflow_arn(self):
session = botocore.session.get_session()
region = "us-west-2"
omics = session.create_client(
"omics",
region,
aws_access_key_id="foo",
aws_secret_access_key="bar",
)
stubber = Stubber(omics)
workflow_arn = "arn:aws:omics:us-east-1:123456789012:workflow/9876"
stubber.add_response(
"get_workflow",
{
"arn": workflow_arn,
"id": "9876",
"status": "ACTIVE",
"type": "PRIVATE",
"name": "hello",
"engine": "WDL",
"main": "main.wdl",
"digest": "sha256:367f76a49c1e6f412a6fb319fcc7061d78ad612d06a9b8ef5b5e5f2e17a32e6f",
"parameterTemplate": {
"param": {"description": "desc"},
},
"creationTime": "2024-04-19T14:38:56.492330+00:00",
"statusMessage": "status",
"tags": {},
},
{"id": "9876"},
)
stubber.activate()
self.assertEqual(utils.get_engine(workflow_arn, client=omics), "WDL")
stubber.deactivate()

0 comments on commit 1f7cb9b

Please sign in to comment.