@ -24,6 +24,9 @@ import pytest
from pydolphinscheduler . core . task import Task , TaskRelation
from pydolphinscheduler . core . task import Task , TaskRelation
from tests . testing . task import Task as testTask
from tests . testing . task import Task as testTask
TEST_TASK_RELATION_SET = set ( )
TEST_TASK_RELATION_SIZE = 0
@pytest . mark . parametrize (
@pytest . mark . parametrize (
" attr, expect " ,
" attr, expect " ,
@ -66,6 +69,45 @@ def test_property_task_params(attr, expect):
assert expect == task . task_params
assert expect == task . task_params
@pytest . mark . parametrize (
" pre_code, post_code, expect " ,
[
( 123 , 456 , hash ( " 123 -> 456 " ) ) ,
( 12345678 , 987654321 , hash ( " 12345678 -> 987654321 " ) ) ,
] ,
)
def test_task_relation_hash_func ( pre_code , post_code , expect ) :
""" Test TaskRelation magic function :func:`__hash__`. """
task_param = TaskRelation ( pre_task_code = pre_code , post_task_code = post_code )
assert hash ( task_param ) == expect
@pytest . mark . parametrize (
" pre_code, post_code, size_add " ,
[
( 123 , 456 , 1 ) ,
( 123 , 456 , 0 ) ,
( 456 , 456 , 1 ) ,
( 123 , 123 , 1 ) ,
( 456 , 123 , 1 ) ,
( 0 , 456 , 1 ) ,
( 123 , 0 , 1 ) ,
] ,
)
def test_task_relation_add_to_set ( pre_code , post_code , size_add ) :
""" Test TaskRelation with different pre_code and post_code add to set behavior.
Here we use global variable to keep set of : class : ` TaskRelation ` instance and the number we expect
of the size when we add a new task relation to exists set .
"""
task_relation = TaskRelation ( pre_task_code = pre_code , post_task_code = post_code )
TEST_TASK_RELATION_SET . add ( task_relation )
# hint python interpreter use global variable instead of local's
global TEST_TASK_RELATION_SIZE
TEST_TASK_RELATION_SIZE + = size_add
assert len ( TEST_TASK_RELATION_SET ) == TEST_TASK_RELATION_SIZE
def test_task_relation_to_dict ( ) :
def test_task_relation_to_dict ( ) :
""" Test TaskRelation object function to_dict. """
""" Test TaskRelation object function to_dict. """
pre_task_code = 123
pre_task_code = 123
@ -79,10 +121,10 @@ def test_task_relation_to_dict():
" conditionType " : 0 ,
" conditionType " : 0 ,
" conditionParams " : { } ,
" conditionParams " : { } ,
}
}
task_param = TaskRelation (
task_relation = TaskRelation (
pre_task_code = pre_task_code , post_task_code = post_task_code
pre_task_code = pre_task_code , post_task_code = post_task_code
)
)
assert task_param . get_define ( ) == expect
assert task_relation . get_define ( ) == expect
def test_task_get_define ( ) :
def test_task_get_define ( ) :