4
4
from dvc .dependency import ParamsDependency , loadd_from , loads_params
5
5
from dvc .dependency .param import BadParamFileError , MissingParamsError
6
6
from dvc .stage import Stage
7
+ from dvc .utils .yaml import load_yaml
7
8
8
9
PARAMS = {
9
10
"foo" : 1 ,
10
11
"bar" : 53.135 ,
11
12
"baz" : "str" ,
12
13
"qux" : None ,
13
14
}
15
+ DEFAULT_PARAMS_FILE = ParamsDependency .DEFAULT_PARAMS_FILE
14
16
15
17
16
18
def test_loads_params (dvc ):
@@ -63,15 +65,15 @@ def test_loadd_from(dvc):
63
65
def test_dumpd_with_info (dvc ):
64
66
dep = ParamsDependency (Stage (dvc ), None , PARAMS )
65
67
assert dep .dumpd () == {
66
- "path" : "params.yaml" ,
68
+ "path" : DEFAULT_PARAMS_FILE ,
67
69
"params" : PARAMS ,
68
70
}
69
71
70
72
71
73
def test_dumpd_without_info (dvc ):
72
74
dep = ParamsDependency (Stage (dvc ), None , list (PARAMS .keys ()))
73
75
assert dep .dumpd () == {
74
- "path" : "params.yaml" ,
76
+ "path" : DEFAULT_PARAMS_FILE ,
75
77
"params" : list (PARAMS .keys ()),
76
78
}
77
79
@@ -82,15 +84,16 @@ def test_read_params_nonexistent_file(dvc):
82
84
83
85
84
86
def test_read_params_unsupported_format (tmp_dir , dvc ):
85
- tmp_dir .gen ("params.yaml" , b"\0 \1 \2 \3 \4 \5 \6 \7 " )
87
+ tmp_dir .gen (DEFAULT_PARAMS_FILE , b"\0 \1 \2 \3 \4 \5 \6 \7 " )
86
88
dep = ParamsDependency (Stage (dvc ), None , ["foo" ])
87
89
with pytest .raises (BadParamFileError ):
88
90
dep .read_params ()
89
91
90
92
91
93
def test_read_params_nested (tmp_dir , dvc ):
92
94
tmp_dir .gen (
93
- "params.yaml" , yaml .dump ({"some" : {"path" : {"foo" : ["val1" , "val2" ]}}})
95
+ DEFAULT_PARAMS_FILE ,
96
+ yaml .dump ({"some" : {"path" : {"foo" : ["val1" , "val2" ]}}}),
94
97
)
95
98
dep = ParamsDependency (Stage (dvc ), None , ["some.path.foo" ])
96
99
assert dep .read_params () == {"some.path.foo" : ["val1" , "val2" ]}
@@ -103,7 +106,24 @@ def test_save_info_missing_config(dvc):
103
106
104
107
105
108
def test_save_info_missing_param (tmp_dir , dvc ):
106
- tmp_dir .gen ("params.yaml" , "bar: baz" )
109
+ tmp_dir .gen (DEFAULT_PARAMS_FILE , "bar: baz" )
107
110
dep = ParamsDependency (Stage (dvc ), None , ["foo" ])
108
111
with pytest .raises (MissingParamsError ):
109
112
dep .save_info ()
113
+
114
+
115
+ @pytest .mark .parametrize (
116
+ "param_value" ,
117
+ ["" , "false" , "[]" , "{}" , "null" , "no" , "off" ]
118
+ # we use pyyaml to load params.yaml, which only supports YAML 1.1
119
+ # so, some of the above are boolean values
120
+ )
121
+ def test_params_with_false_values (tmp_dir , dvc , param_value ):
122
+ key = "param"
123
+ dep = ParamsDependency (Stage (dvc ), DEFAULT_PARAMS_FILE , [key ])
124
+ (tmp_dir / DEFAULT_PARAMS_FILE ).write_text (f"{ key } : { param_value } " )
125
+
126
+ dep .fill_values (load_yaml (DEFAULT_PARAMS_FILE ))
127
+
128
+ with dvc .state :
129
+ assert dep .status () == {}
0 commit comments