|
|
@ -1,22 +1,36 @@
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import pytest
|
|
|
|
import pytest
|
|
|
|
from calculate.scripts.scripts import Var, Task, Static, TaskError, Done,\
|
|
|
|
from calculate.scripts.scripts import Var, Task, Static, TaskError, Done,\
|
|
|
|
DoneAny, Success, SuccessAny, Failed,\
|
|
|
|
DoneAny, Success, SuccessAny, Failed,\
|
|
|
|
FailedAny, Block, For, While, Until,\
|
|
|
|
FailedAny, Block, For, While, Until,\
|
|
|
|
Handler, Script, Run, ScriptError,\
|
|
|
|
Handler, Script, Run, ScriptError,\
|
|
|
|
ActionError
|
|
|
|
ActionError, ScriptLauncher, RunTemplate
|
|
|
|
from calculate.variables.datavars import Namespace, Variable, IntegerType,\
|
|
|
|
from calculate.variables.datavars import Namespace, Variable, IntegerType,\
|
|
|
|
StringType, BooleanType, ListType,\
|
|
|
|
StringType, BooleanType, ListType,\
|
|
|
|
HashType
|
|
|
|
HashType
|
|
|
|
|
|
|
|
from calculate.variables.loader import Datavars
|
|
|
|
from calculate.utils.io_module import IOModule
|
|
|
|
from calculate.utils.io_module import IOModule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.tasks
|
|
|
|
TESTFILES_PATH = os.path.join(os.getcwd(), 'tests/scripts/testfiles')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.scripts
|
|
|
|
class TestTasks():
|
|
|
|
class TestTasks():
|
|
|
|
|
|
|
|
def test_to_make_testfiles(self):
|
|
|
|
|
|
|
|
shutil.copytree(os.path.join(TESTFILES_PATH, 'var.backup'),
|
|
|
|
|
|
|
|
os.path.join(TESTFILES_PATH, 'var'),
|
|
|
|
|
|
|
|
symlinks=True)
|
|
|
|
|
|
|
|
shutil.copytree(os.path.join(TESTFILES_PATH, 'etc.backup'),
|
|
|
|
|
|
|
|
os.path.join(TESTFILES_PATH, 'etc'),
|
|
|
|
|
|
|
|
symlinks=True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_arguments_of_the_Var_objects_are_correct_and_they_are_called_with_datavars_namespace_and_script_namespace_arguments__this_objects_can_be_used_for_different_checks(self):
|
|
|
|
def test_if_arguments_of_the_Var_objects_are_correct_and_they_are_called_with_datavars_namespace_and_script_namespace_arguments__this_objects_can_be_used_for_different_checks(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
|
datavars = Namespace.datavars
|
|
|
|
datavars = Namespace.datavars
|
|
|
|
script_namespace = Script.make_script_variables('test_script', [],
|
|
|
|
script_namespace = ScriptLauncher.make_script_variables('test_script',
|
|
|
|
datavars)
|
|
|
|
[], datavars)
|
|
|
|
with Namespace('os'):
|
|
|
|
with Namespace('os'):
|
|
|
|
Variable('var_1', source='value', type=StringType)
|
|
|
|
Variable('var_1', source='value', type=StringType)
|
|
|
|
|
|
|
|
|
|
|
@ -103,13 +117,15 @@ class TestTasks():
|
|
|
|
def action(output, arg1):
|
|
|
|
def action(output, arg1):
|
|
|
|
return f'os.var = {arg1}'
|
|
|
|
return f'os.var = {arg1}'
|
|
|
|
|
|
|
|
|
|
|
|
Script('test_script'
|
|
|
|
script = Script('test_script'
|
|
|
|
).tasks(
|
|
|
|
).tasks(
|
|
|
|
Task(id='task',
|
|
|
|
Task(id='task',
|
|
|
|
name="Task",
|
|
|
|
name="Task",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=["os.var"])
|
|
|
|
args=["os.var"])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
)
|
|
|
|
|
|
|
|
launcher = script.make_launcher(IOModule(), datavars, None)
|
|
|
|
|
|
|
|
launcher()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -139,7 +155,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('static_value'), "os.var_1"],
|
|
|
|
args=[Static('static_value'), "os.var_1"],
|
|
|
|
when=(Var('os.var_2') & Var('os.var_3')))
|
|
|
|
when=(Var('os.var_2') & Var('os.var_3')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -166,7 +182,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value')],
|
|
|
|
args=[Static('value')],
|
|
|
|
when=~Var('os.linux.var_1'))
|
|
|
|
when=~Var('os.linux.var_1'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' not in datavars.scripts.test_script
|
|
|
|
assert 'task' not in datavars.scripts.test_script
|
|
|
@ -191,7 +207,7 @@ class TestTasks():
|
|
|
|
args=[Static('value')],
|
|
|
|
args=[Static('value')],
|
|
|
|
essential=False,
|
|
|
|
essential=False,
|
|
|
|
when=Var('os.linux.var_1'))
|
|
|
|
when=Var('os.linux.var_1'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -222,7 +238,7 @@ class TestTasks():
|
|
|
|
args=[Static('value')],
|
|
|
|
args=[Static('value')],
|
|
|
|
essential=True,
|
|
|
|
essential=True,
|
|
|
|
when=Var('os.linux.var_1'))
|
|
|
|
when=Var('os.linux.var_1'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_some_essential_tasks_with_conditions_and_some_conditions_uses_done_to_check_if_tasks_from_Done_or_DoneAny_arguments_were_completed__the_script_executes_tasks_which_done_condition_is_fulfilled(self):
|
|
|
|
def test_if_script_object_is_created_with_some_essential_tasks_with_conditions_and_some_conditions_uses_done_to_check_if_tasks_from_Done_or_DoneAny_arguments_were_completed__the_script_executes_tasks_which_done_condition_is_fulfilled(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -267,7 +283,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_4')],
|
|
|
|
args=[Static('value_4')],
|
|
|
|
when=DoneAny('task_1', 'task_3'))
|
|
|
|
when=DoneAny('task_1', 'task_3'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_3' not in datavars.scripts.test_script
|
|
|
|
assert 'task_3' not in datavars.scripts.test_script
|
|
|
@ -345,7 +361,7 @@ class TestTasks():
|
|
|
|
args=[Static('value_10')],
|
|
|
|
args=[Static('value_10')],
|
|
|
|
when=(Var('os.linux.var_1') &
|
|
|
|
when=(Var('os.linux.var_1') &
|
|
|
|
SuccessAny('task_3', 'task_4')))
|
|
|
|
SuccessAny('task_3', 'task_4')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_4' not in datavars.scripts.test_script
|
|
|
|
assert 'task_4' not in datavars.scripts.test_script
|
|
|
@ -425,7 +441,7 @@ class TestTasks():
|
|
|
|
args=[Static('value_9')],
|
|
|
|
args=[Static('value_9')],
|
|
|
|
when=(Var('os.linux.var_1') &
|
|
|
|
when=(Var('os.linux.var_1') &
|
|
|
|
FailedAny('task_2', 'task_3')))
|
|
|
|
FailedAny('task_2', 'task_3')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert not datavars.scripts.test_script.task_2.success
|
|
|
|
assert not datavars.scripts.test_script.task_2.success
|
|
|
@ -457,7 +473,7 @@ class TestTasks():
|
|
|
|
name="Task 1",
|
|
|
|
name="Task 1",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var'])
|
|
|
|
args=['os.linux.var'])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_essential_task_having_set_parameter_containing_a_string_with_path_to_an_existing_variable__the_task_s_execution_result_will_be_set_to_the_variable_from_set_parameter(self):
|
|
|
|
def test_if_script_object_is_created_with_essential_task_having_set_parameter_containing_a_string_with_path_to_an_existing_variable__the_task_s_execution_result_will_be_set_to_the_variable_from_set_parameter(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -480,7 +496,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
set='os.linux.var_2')
|
|
|
|
set='os.linux.var_2')
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -510,7 +526,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
set=['os.var_1', 'os.linux.var_2'])
|
|
|
|
set=['os.var_1', 'os.linux.var_2'])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -541,7 +557,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
set=('os.var_1', 'os.linux.var_2'))
|
|
|
|
set=('os.var_1', 'os.linux.var_2'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -571,7 +587,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var_1', 'os.linux.var_2'],
|
|
|
|
args=['os.linux.var_1', 'os.linux.var_2'],
|
|
|
|
set={'field_1': 'os.var_1', 'field_2': 'os.var_2'})
|
|
|
|
set={'field_1': 'os.var_1', 'field_2': 'os.var_2'})
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
|
assert 'task' in datavars.scripts.test_script
|
|
|
@ -596,7 +612,7 @@ class TestTasks():
|
|
|
|
name="Task",
|
|
|
|
name="Task",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var_1'])
|
|
|
|
args=['os.linux.var_1'])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_essential_task_having_action_function_with_a_return_type_annotation_and_set_parameter_containing_variable_of_the_different_type__the_task_fails_to_set_returned_value_to_this_variable(self):
|
|
|
|
def test_if_script_object_is_created_with_essential_task_having_action_function_with_a_return_type_annotation_and_set_parameter_containing_variable_of_the_different_type__the_task_fails_to_set_returned_value_to_this_variable(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -618,7 +634,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
args=['os.linux.var_1'],
|
|
|
|
set='os.linux.var_2')
|
|
|
|
set='os.linux.var_2')
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_plain_block_of_correct_tasks__the_script_will_be_executed_successfully(self):
|
|
|
|
def test_if_script_object_is_created_with_plain_block_of_correct_tasks__the_script_will_be_executed_successfully(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -641,7 +657,7 @@ class TestTasks():
|
|
|
|
name="Task 2",
|
|
|
|
name="Task 2",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')]))
|
|
|
|
args=[Static('value_2')]))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -671,7 +687,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
when=Var('os.linux.var_1'))
|
|
|
|
when=Var('os.linux.var_1'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -699,7 +715,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
when=~Var('os.linux.var_1'))
|
|
|
|
when=~Var('os.linux.var_1'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'task_3' not in datavars.scripts.test_script
|
|
|
|
assert 'task_3' not in datavars.scripts.test_script
|
|
|
|
assert 'task_4' not in datavars.scripts.test_script
|
|
|
|
assert 'task_4' not in datavars.scripts.test_script
|
|
|
@ -735,7 +751,7 @@ class TestTasks():
|
|
|
|
name="Task 3",
|
|
|
|
name="Task 3",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('rescue_value')]))
|
|
|
|
args=[Static('rescue_value')]))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -777,7 +793,7 @@ class TestTasks():
|
|
|
|
action=action_2,
|
|
|
|
action=action_2,
|
|
|
|
args=['scripts.test_script.value']),
|
|
|
|
args=['scripts.test_script.value']),
|
|
|
|
loop=For('value', ['value_1', 'value_2', 'value_3']))
|
|
|
|
loop=For('value', ['value_1', 'value_2', 'value_3']))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
for l_value, r_value in zip(output, expected):
|
|
|
|
for l_value, r_value in zip(output, expected):
|
|
|
|
assert l_value == r_value
|
|
|
|
assert l_value == r_value
|
|
|
@ -818,7 +834,7 @@ class TestTasks():
|
|
|
|
action=action_2,
|
|
|
|
action=action_2,
|
|
|
|
args=['scripts.test_script.value']),
|
|
|
|
args=['scripts.test_script.value']),
|
|
|
|
loop=For('value', 'os.linux.var_1'))
|
|
|
|
loop=For('value', 'os.linux.var_1'))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
for l_value, r_value in zip(output, expected):
|
|
|
|
for l_value, r_value in zip(output, expected):
|
|
|
|
assert l_value == r_value
|
|
|
|
assert l_value == r_value
|
|
|
@ -851,7 +867,7 @@ class TestTasks():
|
|
|
|
set={'counter': 'os.counter',
|
|
|
|
set={'counter': 'os.counter',
|
|
|
|
'output': 'os.output'}),
|
|
|
|
'output': 'os.output'}),
|
|
|
|
loop=While(Var('os.counter') < Var('os.ceiling')))
|
|
|
|
loop=While(Var('os.counter') < Var('os.ceiling')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert datavars.os.output == expected
|
|
|
|
assert datavars.os.output == expected
|
|
|
|
|
|
|
|
|
|
|
@ -893,7 +909,7 @@ class TestTasks():
|
|
|
|
args=['os.counter', 'os.ceiling'],
|
|
|
|
args=['os.counter', 'os.ceiling'],
|
|
|
|
set='os.flag'),
|
|
|
|
set='os.flag'),
|
|
|
|
loop=While(~Var('os.flag')))
|
|
|
|
loop=While(~Var('os.flag')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert datavars.os.output == expected
|
|
|
|
assert datavars.os.output == expected
|
|
|
|
|
|
|
|
|
|
|
@ -920,7 +936,7 @@ class TestTasks():
|
|
|
|
set={'counter': 'os.counter',
|
|
|
|
set={'counter': 'os.counter',
|
|
|
|
'output': 'os.output'}),
|
|
|
|
'output': 'os.output'}),
|
|
|
|
loop=Until(Var('os.flag')))
|
|
|
|
loop=Until(Var('os.flag')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert datavars.os.output == ['counter = 0']
|
|
|
|
assert datavars.os.output == ['counter = 0']
|
|
|
|
|
|
|
|
|
|
|
@ -962,7 +978,7 @@ class TestTasks():
|
|
|
|
args=['os.counter', 'os.ceiling'],
|
|
|
|
args=['os.counter', 'os.ceiling'],
|
|
|
|
set='os.flag'),
|
|
|
|
set='os.flag'),
|
|
|
|
loop=Until(~Var('os.flag')))
|
|
|
|
loop=Until(~Var('os.flag')))
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert datavars.os.output == expected
|
|
|
|
assert datavars.os.output == expected
|
|
|
|
|
|
|
|
|
|
|
@ -994,7 +1010,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')])
|
|
|
|
args=[Static('value_2')])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_2' in datavars.scripts.test_script
|
|
|
|
assert 'task_2' in datavars.scripts.test_script
|
|
|
@ -1047,7 +1063,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_8')])
|
|
|
|
args=[Static('value_8')])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1112,7 +1128,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_8')])
|
|
|
|
args=[Static('value_8')])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1177,7 +1193,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_8')])
|
|
|
|
args=[Static('value_8')])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1242,7 +1258,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_8')])
|
|
|
|
args=[Static('value_8')])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1311,7 +1327,7 @@ class TestTasks():
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_8')])
|
|
|
|
args=[Static('value_8')])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1340,6 +1356,16 @@ class TestTasks():
|
|
|
|
Script('test_script',
|
|
|
|
Script('test_script',
|
|
|
|
args=['arg1', 'arg_2'],
|
|
|
|
args=['arg1', 'arg_2'],
|
|
|
|
).tasks(
|
|
|
|
).tasks(
|
|
|
|
|
|
|
|
Handler('handler_1',
|
|
|
|
|
|
|
|
Task(id='task_7',
|
|
|
|
|
|
|
|
name="Task 7",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=[Static('value_7')]),
|
|
|
|
|
|
|
|
Task(id='task_8',
|
|
|
|
|
|
|
|
name="Task 8",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=[Static('value_8')])
|
|
|
|
|
|
|
|
),
|
|
|
|
Task(id='task_1',
|
|
|
|
Task(id='task_1',
|
|
|
|
name="Task 1",
|
|
|
|
name="Task 1",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
@ -1366,18 +1392,8 @@ class TestTasks():
|
|
|
|
Task(id='task_6',
|
|
|
|
Task(id='task_6',
|
|
|
|
name="Task 6",
|
|
|
|
name="Task 6",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_6')]),
|
|
|
|
args=[Static('value_6')])
|
|
|
|
Handler('handler_1',
|
|
|
|
).make_launcher(IOModule(), datavars, None)(True, False)
|
|
|
|
Task(id='task_7',
|
|
|
|
|
|
|
|
name="Task 7",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=[Static('value_7')]),
|
|
|
|
|
|
|
|
Task(id='task_8',
|
|
|
|
|
|
|
|
name="Task 8",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=[Static('value_8')])
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
).initialize(IOModule(), datavars, None)(True, False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1411,7 +1427,7 @@ class TestTasks():
|
|
|
|
name="Task",
|
|
|
|
name="Task",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
@ -1448,7 +1464,7 @@ class TestTasks():
|
|
|
|
name="Task",
|
|
|
|
name="Task",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
@ -1485,7 +1501,7 @@ class TestTasks():
|
|
|
|
name="Task",
|
|
|
|
name="Task",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
@ -1527,7 +1543,7 @@ class TestTasks():
|
|
|
|
name="Task 3",
|
|
|
|
name="Task 3",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_3')]),
|
|
|
|
args=[Static('value_3')]),
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
@ -1573,7 +1589,7 @@ class TestTasks():
|
|
|
|
name="Task 3",
|
|
|
|
name="Task 3",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_3')]),
|
|
|
|
args=[Static('value_3')]),
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_any_number_of_tasks_and_Run_object_is_used_to_run_other_script_with_excess_number_of_variables_as_its_arguments__the_outer_script_interrupts_its_execution_with_error(self):
|
|
|
|
def test_if_script_object_is_created_with_any_number_of_tasks_and_Run_object_is_used_to_run_other_script_with_excess_number_of_variables_as_its_arguments__the_outer_script_interrupts_its_execution_with_error(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -1607,7 +1623,7 @@ class TestTasks():
|
|
|
|
name="Task 3",
|
|
|
|
name="Task 3",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_3')]),
|
|
|
|
args=[Static('value_3')]),
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_any_number_of_tasks_and_two_Run_objects_that_are_used_to_run_the_same_scripts_with_different_arguments__the_outer_script_runs_script_from_Run_objects_two_times_with_different_arguments(self):
|
|
|
|
def test_if_script_object_is_created_with_any_number_of_tasks_and_two_Run_objects_that_are_used_to_run_the_same_scripts_with_different_arguments__the_outer_script_runs_script_from_Run_objects_two_times_with_different_arguments(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -1637,7 +1653,7 @@ class TestTasks():
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
args=[Static('value_2')]),
|
|
|
|
Run(script_1, namespace='os',
|
|
|
|
Run(script_1, namespace='os',
|
|
|
|
args=[Static(13)])
|
|
|
|
args=[Static(13)])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
@ -1681,7 +1697,7 @@ class TestTasks():
|
|
|
|
name="Task 2",
|
|
|
|
name="Task 2",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_2')])
|
|
|
|
args=[Static('value_2')])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_any_number_of_tasks_and_not_essential_Run_object_is_used_to_run_other_failing_script__the_outer_script_skips_failing_script_and_continues_to_execute_its_own_tasks(self):
|
|
|
|
def test_if_script_object_is_created_with_any_number_of_tasks_and_not_essential_Run_object_is_used_to_run_other_failing_script__the_outer_script_skips_failing_script_and_continues_to_execute_its_own_tasks(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -1719,7 +1735,7 @@ class TestTasks():
|
|
|
|
name="Task 3",
|
|
|
|
name="Task 3",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=[Static('value_3')])
|
|
|
|
args=[Static('value_3')])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'task_1' in datavars.scripts.test_script_1
|
|
|
|
assert 'task_1' in datavars.scripts.test_script_1
|
|
|
|
assert not datavars.scripts.test_script_1.task_1.success
|
|
|
|
assert not datavars.scripts.test_script_1.task_1.success
|
|
|
@ -1748,11 +1764,10 @@ class TestTasks():
|
|
|
|
name="Task 1",
|
|
|
|
name="Task 1",
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.var_1'])
|
|
|
|
args=['os.var_1'])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_script_object_is_created_with_not_essential_task_which_action_raises_ActionError_exception_or_an_exception_inheriting_it__the_outer_script_skips_failing_task(self):
|
|
|
|
def test_if_script_object_is_created_with_not_essential_task_which_action_raises_ActionError_exception_or_an_exception_inheriting_it__the_outer_script_skips_failing_task(self):
|
|
|
|
Namespace.reset()
|
|
|
|
Namespace.reset()
|
|
|
@ -1776,7 +1791,7 @@ class TestTasks():
|
|
|
|
essential=False,
|
|
|
|
essential=False,
|
|
|
|
action=action,
|
|
|
|
action=action,
|
|
|
|
args=['os.var_1'])
|
|
|
|
args=['os.var_1'])
|
|
|
|
).initialize(IOModule(), datavars, None)()
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
|
assert 'task_1' in datavars.scripts.test_script
|
|
|
@ -1797,18 +1812,19 @@ class TestTasks():
|
|
|
|
def action(arg1):
|
|
|
|
def action(arg1):
|
|
|
|
return f'value = {arg1}'
|
|
|
|
return f'value = {arg1}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tasks_1 = [Task(id='task_1',
|
|
|
|
|
|
|
|
name="Task 1",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=['.var_1'],
|
|
|
|
|
|
|
|
when=Var('scripts.test_script_1.arg')),
|
|
|
|
|
|
|
|
Task(id='task_2',
|
|
|
|
|
|
|
|
name="Task 2",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=['.var_1'],
|
|
|
|
|
|
|
|
when=~Var('scripts.test_script_1.arg'))]
|
|
|
|
script_1 = Script('test_script_1',
|
|
|
|
script_1 = Script('test_script_1',
|
|
|
|
args=['arg']
|
|
|
|
args=['arg']
|
|
|
|
).tasks(Task(id='task_1',
|
|
|
|
).tasks(*tasks_1)
|
|
|
|
name="Task 1",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=['.var_1'],
|
|
|
|
|
|
|
|
when=Var('scripts.test_script_1.arg')),
|
|
|
|
|
|
|
|
Task(id='task_2',
|
|
|
|
|
|
|
|
name="Task 2",
|
|
|
|
|
|
|
|
action=action,
|
|
|
|
|
|
|
|
args=['.var_1'],
|
|
|
|
|
|
|
|
when=~Var('scripts.test_script_1.arg')))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Script('test_script_2',
|
|
|
|
Script('test_script_2',
|
|
|
|
).tasks(Task(id='task_1',
|
|
|
|
).tasks(Task(id='task_1',
|
|
|
@ -1831,7 +1847,7 @@ class TestTasks():
|
|
|
|
when=Var('.linux.var_4')),
|
|
|
|
when=Var('.linux.var_4')),
|
|
|
|
Run(script_1, namespace='os', args=[False],
|
|
|
|
Run(script_1, namespace='os', args=[False],
|
|
|
|
when=Var('.linux.var_4'))
|
|
|
|
when=Var('.linux.var_4'))
|
|
|
|
).initialize(IOModule(), datavars, datavars.os)()
|
|
|
|
).make_launcher(IOModule(), datavars, datavars.os)()
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_1' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
|
assert 'test_script_2' in datavars.scripts
|
|
|
@ -1852,3 +1868,53 @@ class TestTasks():
|
|
|
|
|
|
|
|
|
|
|
|
assert 'task_2' in datavars.scripts.test_script_1
|
|
|
|
assert 'task_2' in datavars.scripts.test_script_1
|
|
|
|
assert datavars.scripts.test_script_1.task_2.result == 'value = 1349'
|
|
|
|
assert datavars.scripts.test_script_1.task_2.result == 'value = 1349'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_templates_using_script(self):
|
|
|
|
|
|
|
|
datavars = Datavars(variables_path=os.path.join(TESTFILES_PATH,
|
|
|
|
|
|
|
|
'variables'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Script('test_script',
|
|
|
|
|
|
|
|
).tasks(RunTemplate(id="templates_1",
|
|
|
|
|
|
|
|
action='action_1',
|
|
|
|
|
|
|
|
package="test-category/test-package",
|
|
|
|
|
|
|
|
chroot_path=TESTFILES_PATH,
|
|
|
|
|
|
|
|
root_path="/etc"),
|
|
|
|
|
|
|
|
).make_launcher(IOModule(), datavars, None)()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
|
|
|
|
assert 'templates_1' in datavars.scripts.test_script
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert datavars.scripts.test_script.templates_1.get_hash() ==\
|
|
|
|
|
|
|
|
{"changed": {os.path.join(TESTFILES_PATH,
|
|
|
|
|
|
|
|
'etc/dir_0'): 'N',
|
|
|
|
|
|
|
|
os.path.join(TESTFILES_PATH,
|
|
|
|
|
|
|
|
'etc/dir_0/file_0'): 'N'},
|
|
|
|
|
|
|
|
"skipped": []}
|
|
|
|
|
|
|
|
assert os.path.exists(os.path.join(TESTFILES_PATH, 'etc/dir_0/file_0'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_run_templates_using_script_and_namespace_is_set(self):
|
|
|
|
|
|
|
|
datavars = Datavars(variables_path=os.path.join(TESTFILES_PATH,
|
|
|
|
|
|
|
|
'variables'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Script('test_script',
|
|
|
|
|
|
|
|
).tasks(RunTemplate(id="templates_1",
|
|
|
|
|
|
|
|
action='action_2',
|
|
|
|
|
|
|
|
package="test-category/test-package",
|
|
|
|
|
|
|
|
chroot_path=TESTFILES_PATH,
|
|
|
|
|
|
|
|
root_path="/etc"),
|
|
|
|
|
|
|
|
).make_launcher(IOModule(), datavars, datavars.os)()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert 'test_script' in datavars.scripts
|
|
|
|
|
|
|
|
assert 'templates_1' in datavars.scripts.test_script
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert datavars.scripts.test_script.templates_1.get_hash() ==\
|
|
|
|
|
|
|
|
{"changed": {os.path.join(TESTFILES_PATH,
|
|
|
|
|
|
|
|
'etc/dir_1'): 'N',
|
|
|
|
|
|
|
|
os.path.join(TESTFILES_PATH,
|
|
|
|
|
|
|
|
'etc/dir_1/file_0'): 'N'},
|
|
|
|
|
|
|
|
"skipped": []}
|
|
|
|
|
|
|
|
assert os.path.exists(os.path.join(TESTFILES_PATH, 'etc/dir_1/file_0'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_for_removing_testfiles(self):
|
|
|
|
|
|
|
|
shutil.rmtree(os.path.join(TESTFILES_PATH, 'var'))
|
|
|
|
|
|
|
|
shutil.rmtree(os.path.join(TESTFILES_PATH, 'etc'))
|
|
|
|