Skip to content

Commit

Permalink
Add basic tests. Closes #2 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
umesh-timalsina authored Mar 29, 2023
1 parent 2c53804 commit 28d1387
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chimerapy_orchestrator/models/pipeline_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Config:

class WorkerConfig(BaseModel):
name: str = Field(..., description="The name of the worker.")
id: Optional[str] = Field(default=None, description="The id of the worker.")
id: str = Field(default=None, description="The id of the worker.")

remote: bool = Field(
default=False,
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions chimerapy_orchestrator/tests/base_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest


class BaseTest:
@pytest.fixture
def initdir(self, tmpdir):
return tmpdir.chdir()
40 changes: 40 additions & 0 deletions chimerapy_orchestrator/tests/data/dummy_pipeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"workers": {
"manager_ip": "localhost",
"manager_port": 8000,
"instances": [
{
"name": "worker1",
"remote": true,
"id": "1235"
},
{
"name": "worker2",
"id": "1234"
}
]
},
"nodes": [
{
"registry_name": "MyCustomNode",
"name": "node1",
"kwargs": {
"param1": 1,
"param2": "abc"
}
},
"node2"
],
"adj": [
["node1", "node2"]
],
"manager_config": {
"logdir": "/tmp/logs",
"port": 8000
},
"mappings": {
"worker1": ["node1"],
"1234": ["node2"]
},
"discover_nodes_from": ["my_module"]
}
Empty file.
56 changes: 56 additions & 0 deletions chimerapy_orchestrator/tests/models/test_pipeline_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json

import pytest

from chimerapy_orchestrator.models.pipeline_config import (
ChimeraPyPipelineConfig,
)
from chimerapy_orchestrator.tests.base_test import BaseTest
from chimerapy_orchestrator.tests.utils import get_test_file_path


class TestPipelineConfig(BaseTest):
@pytest.fixture(scope="class")
def dummy_pipeline_config(self) -> ChimeraPyPipelineConfig:
with get_test_file_path("dummy_pipeline.json").open() as f:
return ChimeraPyPipelineConfig.parse_obj(json.load(f))

def test_worker_config(self, dummy_pipeline_config):
assert dummy_pipeline_config.workers.manager_ip == "localhost"
assert dummy_pipeline_config.workers.manager_port == 8000

assert dummy_pipeline_config.workers.instances[0].remote
assert dummy_pipeline_config.workers.instances[0].name == "worker1"
assert dummy_pipeline_config.workers.instances[0].id == "1235"

assert not dummy_pipeline_config.workers.instances[1].remote
assert dummy_pipeline_config.workers.instances[1].name == "worker2"
assert dummy_pipeline_config.workers.instances[1].id == "1234"

assert len(dummy_pipeline_config.workers.instances) == 2

def test_nodes_config(self, dummy_pipeline_config):
assert len(dummy_pipeline_config.nodes) == 2
assert dummy_pipeline_config.nodes[0].name == "node1"
assert dummy_pipeline_config.nodes[0].registry_name == "MyCustomNode"
assert dummy_pipeline_config.nodes[0].kwargs == {
"param1": 1,
"param2": "abc",
}
assert dummy_pipeline_config.nodes[1].name == "node2"
assert dummy_pipeline_config.nodes[1].registry_name == "node2"
assert dummy_pipeline_config.nodes[1].kwargs == {}

def test_adj_config(self, dummy_pipeline_config):
assert len(dummy_pipeline_config.adj) == 1
assert dummy_pipeline_config.adj[0] == ("node1", "node2")

def test_mappings_config(self, dummy_pipeline_config):
assert len(dummy_pipeline_config.mappings) == 2
assert dummy_pipeline_config.mappings["worker1"] == ["node1"]
assert dummy_pipeline_config.mappings["1234"] == ["node2"]

def test_manager_config(self, dummy_pipeline_config):
manager = dummy_pipeline_config.manager_config
assert manager.port == 8000
assert str(manager.logdir) == "/tmp/logs"
6 changes: 6 additions & 0 deletions chimerapy_orchestrator/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path


def get_test_file_path(file_name: str) -> Path:
"""Get the path to a test file"""
return Path(__file__).parent / "data" / file_name
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ dependencies = [
'pydantic'
]

[project.optional-dependencies]
test = [
'pytest',
'coveralls',
'pre-commit'
]

[project.urls]
homepath = "https://github.com/oele-isis-vanderbilt/ChimeraPyOrchestrator"
documentation = "https://github.com/oele-isis-vanderbilt/ChimeraPyOrchestrator"
Expand Down

0 comments on commit 28d1387

Please sign in to comment.