Skip to content

Commit

Permalink
add tests to ensure desired behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
pedohorse committed Sep 1, 2024
1 parent 35efe2e commit 0922bea
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/nodes/test_hip_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import random
import ast
from asyncio import Event
from lifeblood.scheduler import Scheduler
from lifeblood.worker import Worker
from lifeblood.nodethings import ProcessingError
from lifeblood_testing_common.nodes_common import TestCaseBase, PseudoContext

from typing import List


class TestHipScript(TestCaseBase):
async def test_trivial(self):
async def _logic(sched: Scheduler, workers: List[Worker], done_waiter: Event, context: PseudoContext):
task = context.create_pseudo_task_with_attrs({})

node = context.create_node('hip_script', 'footest')

node.set_param_value('hip path', '/tmp/some/path/stuff.hip')
node.set_param_value('script', 'do_things()')

res = context.process_task(node, task)
script = res.invocation_job.extra_files()['work_to_do.py']
ast.parse(script)

await self._helper_test_node_with_arg_update(
_logic
)

async def test_empty_script(self):
async def _logic(sched: Scheduler, workers: List[Worker], done_waiter: Event, context: PseudoContext):
task = context.create_pseudo_task_with_attrs({})

node = context.create_node('hip_script', 'footest')

node.set_param_value('hip path', '/tmp/some/path/stuff.hip')
node.set_param_value('script', '')

res = context.process_task(node, task)
script = res.invocation_job.extra_files()['work_to_do.py']
ast.parse(script)

await self._helper_test_node_with_arg_update(
_logic
)

async def test_empty_hip_path(self):
async def _logic(sched: Scheduler, workers: List[Worker], done_waiter: Event, context: PseudoContext):
task = context.create_pseudo_task_with_attrs({})

node = context.create_node('hip_script', 'footest')

node.set_param_value('hip path', '')
node.set_param_value('script', '')

self.assertRaises(ProcessingError, context.process_task, node, task)

await self._helper_test_node_with_arg_update(
_logic
)

0 comments on commit 0922bea

Please sign in to comment.