Skip to content

Commit

Permalink
✅ add test for bunch and generated parameters. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
perillaroc committed Apr 30, 2022
1 parent 206e804 commit ddc34cc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/core/test_bunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,18 @@ def test_delete_flow(simple_bunch, simple_flow_objects, simple_flow_2_objects):
assert bunch.flows == {
"flow2": flow2
}


def get_bunch(simple_bunch, simple_flow_objects, simple_flow_2_objects):
bunch = simple_bunch
flow1 = simple_flow_objects["flow1"]
flow2 = simple_flow_2_objects["flow2"]

assert flow1.get_bunch() == bunch
assert flow2.get_bunch() == bunch

task1 = simple_flow_objects["task1"]
assert task1.get_bunch() == bunch

container2 = simple_flow_2_objects["container2"]
assert container2.get_bunch() == bunch
54 changes: 54 additions & 0 deletions tests/core/test_parameter_bunch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest

from takler.core import Parameter, parameter, Bunch


@pytest.fixture
def simple_bunch_default_port(simple_flow_objects):
flow1 = simple_flow_objects["flow1"]
flow1.add_parameter("ECF_HOME", "/home/johndoe")
flow1.add_parameter("NODES", 4)
flow1.add_parameter("TIME_INTERVAL", 0.1)

container1 = simple_flow_objects["container1"]
container1.add_parameter("TASKS", 32)

task1 = simple_flow_objects["task1"]
task1.add_parameter("FLAG", True)

bunch = Bunch("nwpc_op")
bunch.add_flow(flow1)

simple_flow_objects["bunch"] = bunch

return simple_flow_objects


def test_bunch_generated_parameter(simple_bunch_default_port):
bunch = simple_bunch_default_port["bunch"]
assert bunch.find_generated_parameter(parameter.TAKLER_HOST) == \
Parameter(parameter.TAKLER_HOST, "localhost")
assert bunch.find_generated_parameter(parameter.TAKLER_PORT) == \
Parameter(parameter.TAKLER_PORT, "33083")
assert bunch.find_parent_parameter(parameter.TAKLER_HOME) == \
Parameter(parameter.TAKLER_HOME, ".")

assert bunch.find_parent_parameter("NOT_EXIST") is None


def test_task_find_bunch_parameter(simple_bunch_default_port):
task1 = simple_bunch_default_port["task1"]
assert task1.find_parent_parameter(parameter.TAKLER_PORT) == Parameter(parameter.TAKLER_PORT, "33083")
assert task1.find_parameter(parameter.TAKLER_PORT) is None


def test_container_find_bunch_parameter(simple_bunch_default_port):
container1 = simple_bunch_default_port["container1"]
assert container1.find_parent_parameter(parameter.TAKLER_HOME) == Parameter(parameter.TAKLER_HOME, ".")
assert container1.find_parameter(parameter.TAKLER_HOME) is None


def test_flow_find_bunch_parameter(simple_bunch_default_port):
flow1 = simple_bunch_default_port["flow1"]
assert flow1.find_parent_parameter(parameter.TAKLER_HOME) == Parameter(parameter.TAKLER_HOME, ".")
assert flow1.find_parameter(parameter.TAKLER_HOME) is None
33 changes: 33 additions & 0 deletions tests/core/test_parameter_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from takler.core import Parameter, parameter


@pytest.fixture
def simple_flow_objects_with_parameter(simple_flow_objects):
flow1 = simple_flow_objects["flow1"]
flow1.add_parameter("ECF_HOME", "/home/johndoe")
flow1.add_parameter("NODES", 4)
flow1.add_parameter("TIME_INTERVAL", 0.1)

container1 = simple_flow_objects["container1"]
container1.add_parameter("TASKS", 32)

task1 = simple_flow_objects["task1"]
task1.add_parameter("FLAG", True)

task1.init(task_id="1001")

return simple_flow_objects


def test_update_generated_parameter(simple_flow_objects_with_parameter):
task1 = simple_flow_objects_with_parameter["task1"]
task1.update_generated_parameters()

assert task1.find_generated_parameter(parameter.TASK) == \
Parameter(parameter.TASK, "task1")
assert task1.find_generated_parameter(parameter.TAKLER_NAME) == \
Parameter(parameter.TAKLER_NAME, "/flow1/container1/task1")
assert task1.find_generated_parameter(parameter.TAKLER_RID) == \
Parameter(parameter.TAKLER_RID, "1001")

0 comments on commit ddc34cc

Please sign in to comment.