Skip to content

Commit

Permalink
initial tests for cli utils
Browse files Browse the repository at this point in the history
  • Loading branch information
markjschreiber committed Sep 19, 2024
1 parent 5e34018 commit 417feab
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
38 changes: 21 additions & 17 deletions omics/cli/run_analyzer/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

ENGINES = ["WDL", "CWL", "Nextflow"]
ENGINES = set(["WDL", "CWL", "NEXTFLOW"])

_wdl_task_regex = r"^([^-]+)(-\d+-\d+.*)?$"
_nextflow_task_regex = r"^(.+)(\s\(.+\))$"
Expand All @@ -22,7 +22,7 @@ def task_base_name(name: str, engine: str) -> str:
if m:
return m.group(1)
# Nextflow
elif engine == "Nextflow":
elif engine == "NEXTFLOW":
m = re.match(_nextflow_task_regex, name)
if m:
return m.group(1)
Expand All @@ -36,26 +36,30 @@ def task_base_name(name: str, engine: str) -> str:
return name


_sizes = {
"": 2,
"xlarge": 4,
"2xlarge": 8,
"4xlarge": 16,
"8xlarge": 32,
"12xlarge": 48,
"16xlarge": 64,
"24xlarge": 96,
}
_families = {"c": 2, "m": 4, "r": 8, "g4dn": 16, "g5": 16}


def omics_instance_weight(instance: str) -> int:
"""Compute a numeric weight for an instance to be used in sorting or finding a max or min"""
sizes = {
"": 2,
"x": 4,
"2x": 8,
"4x": 16,
"8x": 32,
"12x": 48,
"16x": 64,
"24x": 96,
}
families = {"c": 2, "m": 4, "r": 8, "g4dn": 16, "g5": 16}
print(instance)
# remove the "omics." from the string
instance.replace("omics.", "")
instance = instance.replace("omics.", "")
# split the instance into family and size
parts = instance.split(".")
print(parts)
fam = parts[0]
size = parts[1] if len(parts) > 1 else ""
size = parts[1]

ccount = sizes[size]
weight = ccount * families[fam]
ccount = _sizes[size]
weight = ccount * _families[fam]
return weight
Empty file added tests/cli/__init__.py
Empty file.
Empty file.
37 changes: 37 additions & 0 deletions tests/cli/run_analyzer/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest

import omics.cli.run_analyzer.utils as utils


class TestRunAnalyzerUtils(unittest.TestCase):
def test_engine_names(self):
self.assertEqual(utils.ENGINES, set(["CWL", "WDL", "NEXTFLOW"]))

def test_task_base_name(self):
# CWL
self.assertEqual(utils.task_base_name("test", "CWL"), "test")
self.assertEqual(utils.task_base_name("test_1", "CWL"), "test")
self.assertEqual(utils.task_base_name("test_again_1", "CWL"), "test_again")
# WDL
self.assertEqual(utils.task_base_name("test", "WDL"), "test")
self.assertEqual(utils.task_base_name("test-01-1234", "WDL"), "test")
self.assertEqual(utils.task_base_name("test_again-10-2345", "WDL"), "test_again")
# Nextflow
self.assertEqual(utils.task_base_name("test", "NEXTFLOW"), "test")
self.assertEqual(utils.task_base_name("TEST:MODULE:FOO", "NEXTFLOW"), "TEST:MODULE:FOO")
self.assertEqual(
utils.task_base_name("TEST:MODULE:FOO (input1)", "NEXTFLOW"), "TEST:MODULE:FOO"
)

def test_task_base_name_invalid_engine(self):
self.assertRaises(ValueError, utils.task_base_name, "test", "INVALID")

def test_omics_instance_weight(self):
def _weight(instance):
return utils.omics_instance_weight(instance)

self.assertTrue(_weight("omics.c.2xlarge") < _weight("omics.c.4xlarge"))
self.assertTrue(_weight("omics.c.4xlarge") < _weight("omics.m.4xlarge"))
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"))

0 comments on commit 417feab

Please sign in to comment.