@@ -74,7 +74,7 @@ def test_path_function_value_must_be_consistent():
74
74
func ('$.Variable' , 'string' )
75
75
76
76
def test_is_function_value_must_be_consistent ():
77
- is_functions = {
77
+ type_functions = {
78
78
'IsPresent' ,
79
79
'IsNull' ,
80
80
'IsString' ,
@@ -83,13 +83,110 @@ def test_is_function_value_must_be_consistent():
83
83
'IsTimestamp'
84
84
}
85
85
86
- for is_function in is_functions :
87
- func = getattr (ChoiceRule , is_function )
86
+ for type_function in type_functions :
87
+ func = getattr (ChoiceRule , type_function )
88
88
with pytest .raises (ValueError ):
89
89
func ('$.Variable' , 'string' )
90
90
with pytest .raises (ValueError ):
91
91
func ('$.Variable' , 101 )
92
92
93
+ # tox -e py37 -- -s -vv tests/unit/test_choice_rule.py::test_dynamic_comparator_serialization
94
+ def test_static_comparator_serialization ():
95
+ string_timestamp_static_comparators = {
96
+ 'StringEquals' ,
97
+ 'StringLessThan' ,
98
+ 'StringLessThanEquals' ,
99
+ 'StringGreaterThan' ,
100
+ 'StringGreaterThanEquals' ,
101
+ 'TimestampEquals' ,
102
+ 'TimestampLessThan' ,
103
+ 'TimestampGreaterThan' ,
104
+ 'TimestampLessThanEquals'
105
+ }
106
+
107
+ for string_timestamp_static_comparator in string_timestamp_static_comparators :
108
+ type_rule = getattr (ChoiceRule , string_timestamp_static_comparator )('$.input' , 'hello' )
109
+ expected_dict = {}
110
+ expected_dict ['Variable' ] = '$.input'
111
+ expected_dict [string_timestamp_static_comparator ] = 'hello'
112
+ assert type_rule .to_dict () == expected_dict
113
+
114
+ number_static_comparators = {
115
+ 'NumericEquals' ,
116
+ 'NumericLessThan' ,
117
+ 'NumericGreaterThan' ,
118
+ 'NumericLessThanEquals' ,
119
+ 'NumericGreaterThanEquals'
120
+ }
121
+
122
+ for number_static_comparator in number_static_comparators :
123
+ type_rule = getattr (ChoiceRule , number_static_comparator )('$.input' , 123 )
124
+ expected_dict = {}
125
+ expected_dict ['Variable' ] = '$.input'
126
+ expected_dict [number_static_comparator ] = 123
127
+ assert type_rule .to_dict () == expected_dict
128
+
129
+ boolean_static_comparators = {
130
+ 'BooleanEquals'
131
+ }
132
+
133
+ for boolean_static_comparator in boolean_static_comparators :
134
+ type_rule = getattr (ChoiceRule , boolean_static_comparator )('$.input' , False )
135
+ expected_dict = {}
136
+ expected_dict ['Variable' ] = '$.input'
137
+ expected_dict [boolean_static_comparator ] = False
138
+ assert type_rule .to_dict () == expected_dict
139
+
140
+ def test_dynamic_comparator_serialization ():
141
+ dynamic_comparators = {
142
+ 'StringEqualsPath' ,
143
+ 'StringLessThanPath' ,
144
+ 'StringLessThanEqualsPath' ,
145
+ 'StringGreaterThanPath' ,
146
+ 'StringGreaterThanEqualsPath' ,
147
+ 'TimestampEqualsPath' ,
148
+ 'TimestampLessThanPath' ,
149
+ 'TimestampGreaterThanPath' ,
150
+ 'TimestampLessThanEqualsPath' ,
151
+ 'NumericEqualsPath' ,
152
+ 'NumericLessThanPath' ,
153
+ 'NumericGreaterThanPath' ,
154
+ 'NumericLessThanEqualsPath' ,
155
+ 'NumericGreaterThanEqualsPath' ,
156
+ 'BooleanEqualsPath'
157
+ }
158
+
159
+ for dynamic_comparator in dynamic_comparators :
160
+ type_rule = getattr (ChoiceRule , dynamic_comparator )('$.input' , '$.input2' )
161
+ expected_dict = {}
162
+ expected_dict ['Variable' ] = '$.input'
163
+ expected_dict [dynamic_comparator ] = '$.input2'
164
+ assert type_rule .to_dict () == expected_dict
165
+
166
+ def test_type_check_comparators_serialization ():
167
+ type_comparators = {
168
+ 'IsPresent' ,
169
+ 'IsNull' ,
170
+ 'IsString' ,
171
+ 'IsNumeric' ,
172
+ 'IsBoolean' ,
173
+ 'IsTimestamp'
174
+ }
175
+
176
+ for type_comparator in type_comparators :
177
+ type_rule = getattr (ChoiceRule , type_comparator )('$.input' , True )
178
+ expected_dict = {}
179
+ expected_dict ['Variable' ] = '$.input'
180
+ expected_dict [type_comparator ] = True
181
+ assert type_rule .to_dict () == expected_dict
182
+
183
+ def test_string_matches_serialization ():
184
+ string_matches_rule = ChoiceRule .StringMatches ('$.input' , 'hello*world\\ *' )
185
+ assert string_matches_rule .to_dict () == {
186
+ 'Variable' : '$.input' ,
187
+ 'StringMatches' : 'hello*world\\ *'
188
+ }
189
+
93
190
def test_rule_serialization ():
94
191
bool_rule = ChoiceRule .BooleanEquals ('$.BooleanVariable' , True )
95
192
assert bool_rule .to_dict () == {
0 commit comments