Exemplo n.º 1
0
def test_planner_plan_with_several_args():
    complex_plan = {
        "A": [{
            "depends": ["C arg:argument_to_C arg2:argument_to_C_2", "D"]
        }],
        "B": [{
            "depends": ["A"]
        }],
        "C": [{
            "run": "{arg} {arg2}"
        }],
        "D": [{
            "sleep": 1
        }],
    }
    plan = Planner(YAMLParser("none")._build_tasks(complex_plan)).plan("B")
    task_c = Task(
        "C arg:argument_to_C arg2:argument_to_C_2",
        run="argument_to_C argument_to_C_2",
    )
    task_d = Task("D", sleep=1)
    task_a = Task("A", depends=[task_c, task_d])
    task_b = Task("B", depends=[task_a])
    assert plan == [
        task_c,
        task_d,
        task_a,
        task_b,
    ]
Exemplo n.º 2
0
def test_planner_simple_plan_():
    simple_plan = {
        "E": [{
            "sleep": 1
        }],
        "A": [{
            "depends": ["C", "D", "E"]
        }],
        "C": [{
            "depends": ["E"]
        }],
        "D": [{
            "sleep": 1
        }],
    }
    plan = Planner(YAMLParser("none")._build_tasks(simple_plan)).plan("A")
    task_e = Task("E", sleep=1)
    task_c = Task("C", depends=[task_e])
    task_d = Task("D", sleep=1)
    task_a = Task("A", depends=[task_c, task_d, task_e])
    assert plan == [
        task_e,
        task_c,
        task_d,
        task_a,
    ]
Exemplo n.º 3
0
def test_planner_plan_with_args():
    complex_plan = {
        "A": [{
            "depends": ["C arg:argument_to_C", "D"]
        }],
        "B": [{
            "depends": ["A"]
        }],  # I'm forcing it to be always a list here
        "C": [{
            "run": "{arg}"
        }],
        "D": [{
            "sleep": 1
        }],
    }
    plan = Planner(YAMLParser("none")._build_tasks(complex_plan)).plan("B")
    task_d = Task("D", sleep=1)
    task_c = Task("C arg:argument_to_C", run="argument_to_C")
    task_a = Task("A", depends=[task_c, task_d])
    task_b = Task("B", depends=[task_a])
    assert plan == [
        task_c,
        task_d,
        task_a,
        task_b,
    ]
Exemplo n.º 4
0
def test_double_interpolate_task_(parameter):
    dic = {"name": "C", parameter: "{arg1} {arg2}"}
    task = Task(**dic)
    args = ["arg1:argument_to_C", "arg2:argument_to_C_2"]
    task.with_args(args)
    print(task)
    assert getattr(task, parameter) == "argument_to_C argument_to_C_2"
    assert task.name == "C arg1:argument_to_C arg2:argument_to_C_2"
Exemplo n.º 5
0
 def _get_depends(self, task_def) -> Optional[List[Task]]:
     _depends = self._find_section(task_def, "depends")
     if _depends is None:
         return None
     if isinstance(_depends, List):
         if all([isinstance(dependency, str) for dependency in _depends]):
             return [Task(name=name) for name in _depends]
     raise Exception(
         "Depends section should only contain an array of strings (if only one dependency, break it as an array)"
     )
Exemplo n.º 6
0
 def _build_tasks(self, parsed_yaml: Dict[str, Any]) -> Dict[str, Task]:
     task_dict = {}
     for task_name, task_def in parsed_yaml.items():
         run: Optional[str] = self._get_run(task_def)
         sleep: Optional[str] = self._get_sleep(task_def)
         message: Optional[str] = self._get_message(task_def)
         depends: Optional[List[Task]] = self._get_depends(task_def)
         condition: Optional[str] = self._get_condition(task_def)
         task = Task(task_name, run, depends, message, sleep, condition)
         task_dict[task_name] = task
     return task_dict
Exemplo n.º 7
0
def test_builds_a_task():
    """Note that testing the parser is... horrible, since the parsing of arguments
and dependencies is deferred to the actual evaluation of the plan. So, better
to just test it as part of the Planner tests, where it is used as well"""
    plan = {
        "A": [{
            "depends": ["C arg:argument_to_C arg2:argument_to_C_2", "D"]
        }],
        "B": [{
            "depends": ["A"]
        }],
        "C": [{
            "run": "{arg} {arg2}"
        }],
        "D": [{
            "sleep": 1
        }],
    }

    parsed = YAMLParser("none")._build_tasks(plan)
    print(parsed)
    task_c = Task(
        "C",
        run="{arg} {arg2}",
    )
    task_c_ = Task("C arg:argument_to_C arg2:argument_to_C_2", )
    task_d = Task("D", sleep=1)
    task_d_ = Task("D")
    task_a = Task("A", depends=[task_c_, task_d_])
    task_a_ = Task("A")
    task_b = Task("B", depends=[task_a_])
    assert parsed == {
        "C": task_c,
        "D": task_d,
        "A": task_a,
        "B": task_b,
    }
Exemplo n.º 8
0
def test_args_dict():
    sample = ["arg1:item1", "arg2:item2"]
    assert Task._args_dict(sample) == {"arg1": "item1", "arg2": "item2"}