@ -18,6 +18,7 @@
""" Test Task class function. """
""" Test Task class function. """
import logging
import logging
import re
import re
from typing import Set
from unittest . mock import PropertyMock , patch
from unittest . mock import PropertyMock , patch
import pytest
import pytest
@ -26,13 +27,79 @@ from pydolphinscheduler.core.process_definition import ProcessDefinition
from pydolphinscheduler . core . task import Task , TaskRelation
from pydolphinscheduler . core . task import Task , TaskRelation
from pydolphinscheduler . exceptions import PyResPluginException
from pydolphinscheduler . exceptions import PyResPluginException
from pydolphinscheduler . resources_plugin import Local
from pydolphinscheduler . resources_plugin import Local
from tests . testing . task import Task as t estTask
from tests . testing . task import Task as T estTask
from tests . testing . task import TaskWithCode
from tests . testing . task import TaskWithCode
TEST_TASK_RELATION_SET = set ( )
TEST_TASK_RELATION_SET = set ( )
TEST_TASK_RELATION_SIZE = 0
TEST_TASK_RELATION_SIZE = 0
@pytest . mark . parametrize (
" addition, ignore, expect " ,
[
(
set ( ) ,
set ( ) ,
{
" local_params " ,
" resource_list " ,
" dependence " ,
" wait_start_timeout " ,
" condition_result " ,
} ,
) ,
(
set ( ) ,
{ " dependence " , " condition_result " , " not_exists " } ,
{
" local_params " ,
" resource_list " ,
" wait_start_timeout " ,
} ,
) ,
(
{
" not_exists_1 " ,
" not_exists_2 " ,
} ,
set ( ) ,
{
" not_exists_1 " ,
" not_exists_2 " ,
" local_params " ,
" resource_list " ,
" dependence " ,
" wait_start_timeout " ,
" condition_result " ,
} ,
) ,
# test addition and ignore conflict to see behavior
(
{
" not_exists " ,
} ,
{ " condition_result " , " not_exists " } ,
{
" not_exists " ,
" local_params " ,
" resource_list " ,
" dependence " ,
" wait_start_timeout " ,
} ,
) ,
] ,
)
def test__get_attr ( addition : Set , ignore : Set , expect : Set ) :
""" Test task function `_get_attr`. """
task = TestTask (
name = " test-get-attr " ,
task_type = " test " ,
)
task . _task_custom_attr = addition
task . _task_ignore_attr = ignore
assert task . _get_attr ( ) == expect
@pytest . mark . parametrize (
@pytest . mark . parametrize (
" attr, expect " ,
" attr, expect " ,
[
[
@ -74,7 +141,7 @@ TEST_TASK_RELATION_SIZE = 0
)
)
def test_property_task_params ( mock_resource , mock_user_name , attr , expect ) :
def test_property_task_params ( mock_resource , mock_user_name , attr , expect ) :
""" Test class task property. """
""" Test class task property. """
task = t estTask(
task = T estTask(
" test-property-task-params " ,
" test-property-task-params " ,
" test-task " ,
" test-task " ,
* * attr ,
* * attr ,
@ -184,8 +251,8 @@ def test_two_tasks_shift(shift: str):
Here we test both ` >> ` and ` << ` bit operator .
Here we test both ` >> ` and ` << ` bit operator .
"""
"""
upstream = t estTask( name = " upstream " , task_type = shift )
upstream = T estTask( name = " upstream " , task_type = shift )
downstream = t estTask( name = " downstream " , task_type = shift )
downstream = T estTask( name = " downstream " , task_type = shift )
if shift == " << " :
if shift == " << " :
downstream << upstream
downstream << upstream
elif shift == " >> " :
elif shift == " >> " :
@ -221,10 +288,10 @@ def test_tasks_list_shift(dep_expr: str, flag: str):
" downstream " : " upstream " ,
" downstream " : " upstream " ,
}
}
task_type = " dep_task_and_tasks "
task_type = " dep_task_and_tasks "
task = t estTask( name = " upstream " , task_type = task_type )
task = T estTask( name = " upstream " , task_type = task_type )
tasks = [
tasks = [
t estTask( name = " downstream1 " , task_type = task_type ) ,
T estTask( name = " downstream1 " , task_type = task_type ) ,
t estTask( name = " downstream2 " , task_type = task_type ) ,
T estTask( name = " downstream2 " , task_type = task_type ) ,
]
]
# Use build-in function eval to simply test case and reduce duplicate code
# Use build-in function eval to simply test case and reduce duplicate code