1
1
import pytest
2
2
from dplutils import cli
3
+ from dplutils .pipeline import PipelineTask
3
4
4
5
5
6
TEST_ARGV = [
6
7
'' ,
7
8
'--set-context' , 'ctx=ctx-value' ,
8
9
'--set-config' , 'a.b.c=[1,2,3]' ,
10
+ '--set-config' , 'a.b.x=99' ,
9
11
'--set-config' , 'x.y=1' ,
10
12
'--set-config' , 'l.m=string' ,
11
13
]
@@ -19,15 +21,7 @@ def sys_argv(monkeypatch):
19
21
def test_get_argparser_adds_default_arguments (sys_argv ):
20
22
args = cli .get_argparser ().parse_args ()
21
23
assert args .set_context == ['ctx=ctx-value' ]
22
- assert args .set_config == ['a.b.c=[1,2,3]' , 'x.y=1' , 'l.m=string' ]
23
-
24
-
25
- def test_config_from_args (sys_argv ):
26
- args = cli .get_argparser ().parse_args ()
27
- config = cli .config_dict_from_args (args )
28
- assert config ['a' ]['b' ]['c' ] == [1 , 2 , 3 ]
29
- assert config ['x' ]['y' ] == 1
30
- assert config ['l' ]['m' ] == 'string'
24
+ assert args .set_config == ['a.b.c=[1,2,3]' , 'a.b.x=99' , 'x.y=1' , 'l.m=string' ]
31
25
32
26
33
27
def test_pipeline_set_config_from_args_no_args (monkeypatch , dummy_executor ):
@@ -38,9 +32,24 @@ def test_pipeline_set_config_from_args_no_args(monkeypatch, dummy_executor):
38
32
def test_run_with_cli_helper (monkeypatch , dummy_executor , tmp_path ):
39
33
assert len (list (tmp_path .glob ('*.parquet' ))) == 0
40
34
monkeypatch .setattr (
41
- 'sys.argv' ,
42
- ['' , '-o' , str (tmp_path ), '--set-context' , 'ctxvar=value' , '--set-config' , 'task1.num_cpus=2' ])
35
+ 'sys.argv' , [
36
+ '' ,
37
+ '-o' ,
38
+ str (tmp_path ),
39
+ '--set-context' , 'ctxvar=value' ,
40
+ '--set-config' , 'task1.num_cpus=2' ,
41
+ '--set-config' , 'task1.batch_size=10' ,
42
+ '--set-config' , 'task_kw.kwargs.a=[1,2]' ,
43
+ '--set-config' , 'task_kw.kwargs.b=99' ,
44
+ ])
45
+ def task_with_kwargs (indf , a = None , b = None ):
46
+ return indf
47
+ # patch in kwargs task to test kwarg setting via dotted notation
48
+ dummy_executor .graph .add_edge (dummy_executor .graph .task_map ['task2' ], PipelineTask ('task_kw' , task_with_kwargs ))
43
49
cli .cli_run (dummy_executor )
44
50
assert dummy_executor .ctx ['ctxvar' ] == 'value'
45
51
assert dummy_executor .tasks_idx ['task1' ].num_cpus == 2
52
+ assert dummy_executor .tasks_idx ['task1' ].batch_size == 10
53
+ assert dummy_executor .tasks_idx ['task_kw' ].kwargs ['a' ] == [1 ,2 ]
54
+ assert dummy_executor .tasks_idx ['task_kw' ].kwargs ['b' ] == 99
46
55
assert len (list (tmp_path .glob ('*.parquet' ))) == 10
0 commit comments