@@ -60,33 +60,45 @@ def test_escape_multi_segment_path_parameter():
6060 assert _escape_multi_segment_path_parameter ("a#b" ) == "a%23b"
6161
6262
63- @pytest .mark .parametrize ("input_dict,field_name,expected_result,expected_json,description" , [
64- ({"field" : "2023-01-01T12:00:00Z" }, "field" , "timestamp_object" , "2023-01-01T12:00:00Z" , "valid timestamp" ),
65- ({}, "field" , None , None , "missing field" ),
66- ({"field" : None }, "field" , None , None , "None value" ),
67- ({"field" : "" }, "field" , None , None , "empty value" ),
68- ])
63+ @pytest .mark .parametrize (
64+ "input_dict,field_name,expected_result,expected_json,description" ,
65+ [
66+ ({"field" : "2023-01-01T12:00:00Z" }, "field" , "timestamp_object" , "2023-01-01T12:00:00Z" , "valid timestamp" ),
67+ ({}, "field" , None , None , "missing field" ),
68+ ({"field" : None }, "field" , None , None , "None value" ),
69+ ({"field" : "" }, "field" , None , None , "empty value" ),
70+ ],
71+ )
6972def test_timestamp (input_dict , field_name , expected_result , expected_json , description ):
7073 """Test _timestamp function with various input scenarios."""
7174 result = _timestamp (input_dict , field_name )
72-
75+
7376 if expected_result is None :
7477 assert result is None
7578 else :
7679 assert isinstance (result , Timestamp )
7780 assert result .ToJsonString () == expected_json
7881
7982
80- @pytest .mark .parametrize ("input_dict,field_name,expected_length,expected_json_list,description" , [
81- ({"field" : ["2023-01-01T12:00:00Z" , "2023-01-02T12:00:00Z" ]}, "field" , 2 , ["2023-01-01T12:00:00Z" , "2023-01-02T12:00:00Z" ], "valid repeated timestamps" ),
82- ({}, "field" , None , None , "missing field" ),
83- ({"field" : None }, "field" , None , None , "None value" ),
84- ({"field" : []}, "field" , None , None , "empty list" ),
85- ])
83+ @pytest .mark .parametrize (
84+ "input_dict,field_name,expected_length,expected_json_list,description" ,
85+ [
86+ (
87+ {"field" : ["2023-01-01T12:00:00Z" , "2023-01-02T12:00:00Z" ]},
88+ "field" ,
89+ 2 ,
90+ ["2023-01-01T12:00:00Z" , "2023-01-02T12:00:00Z" ],
91+ "valid repeated timestamps" ,
92+ ),
93+ ({}, "field" , None , None , "missing field" ),
94+ ({"field" : None }, "field" , None , None , "None value" ),
95+ ({"field" : []}, "field" , None , None , "empty list" ),
96+ ],
97+ )
8698def test_repeated_timestamp (input_dict , field_name , expected_length , expected_json_list , description ):
8799 """Test _repeated_timestamp function with various input scenarios."""
88100 result = _repeated_timestamp (input_dict , field_name )
89-
101+
90102 if expected_length is None :
91103 assert result is None
92104 else :
@@ -96,33 +108,39 @@ def test_repeated_timestamp(input_dict, field_name, expected_length, expected_js
96108 assert result [i ].ToJsonString () == expected_json
97109
98110
99- @pytest .mark .parametrize ("input_dict,field_name,expected_result,expected_json,description" , [
100- ({"field" : "3600s" }, "field" , "duration_object" , "3600s" , "valid duration" ),
101- ({}, "field" , None , None , "missing field" ),
102- ({"field" : None }, "field" , None , None , "None value" ),
103- ({"field" : "" }, "field" , None , None , "empty value" ),
104- ])
111+ @pytest .mark .parametrize (
112+ "input_dict,field_name,expected_result,expected_json,description" ,
113+ [
114+ ({"field" : "3600s" }, "field" , "duration_object" , "3600s" , "valid duration" ),
115+ ({}, "field" , None , None , "missing field" ),
116+ ({"field" : None }, "field" , None , None , "None value" ),
117+ ({"field" : "" }, "field" , None , None , "empty value" ),
118+ ],
119+ )
105120def test_duration (input_dict , field_name , expected_result , expected_json , description ):
106121 """Test _duration function with various input scenarios."""
107122 result = _duration (input_dict , field_name )
108-
123+
109124 if expected_result is None :
110125 assert result is None
111126 else :
112127 assert isinstance (result , Duration )
113128 assert result .ToJsonString () == expected_json
114129
115130
116- @pytest .mark .parametrize ("input_dict,field_name,expected_length,expected_json_list,description" , [
117- ({"field" : ["3600s" , "7200s" ]}, "field" , 2 , ["3600s" , "7200s" ], "valid repeated durations" ),
118- ({}, "field" , None , None , "missing field" ),
119- ({"field" : None }, "field" , None , None , "None value" ),
120- ({"field" : []}, "field" , None , None , "empty list" ),
121- ])
131+ @pytest .mark .parametrize (
132+ "input_dict,field_name,expected_length,expected_json_list,description" ,
133+ [
134+ ({"field" : ["3600s" , "7200s" ]}, "field" , 2 , ["3600s" , "7200s" ], "valid repeated durations" ),
135+ ({}, "field" , None , None , "missing field" ),
136+ ({"field" : None }, "field" , None , None , "None value" ),
137+ ({"field" : []}, "field" , None , None , "empty list" ),
138+ ],
139+ )
122140def test_repeated_duration (input_dict , field_name , expected_length , expected_json_list , description ):
123141 """Test _repeated_duration function with various input scenarios."""
124142 result = _repeated_duration (input_dict , field_name )
125-
143+
126144 if expected_length is None :
127145 assert result is None
128146 else :
@@ -132,33 +150,45 @@ def test_repeated_duration(input_dict, field_name, expected_length, expected_jso
132150 assert result [i ].ToJsonString () == expected_json
133151
134152
135- @pytest .mark .parametrize ("input_dict,field_name,expected_result,expected_json,description" , [
136- ({"field" : "path1,path2" }, "field" , "fieldmask_object" , "path1,path2" , "valid fieldmask" ),
137- ({}, "field" , None , None , "missing field" ),
138- ({"field" : None }, "field" , None , None , "None value" ),
139- ({"field" : "" }, "field" , None , None , "empty value" ),
140- ])
153+ @pytest .mark .parametrize (
154+ "input_dict,field_name,expected_result,expected_json,description" ,
155+ [
156+ ({"field" : "path1,path2" }, "field" , "fieldmask_object" , "path1,path2" , "valid fieldmask" ),
157+ ({}, "field" , None , None , "missing field" ),
158+ ({"field" : None }, "field" , None , None , "None value" ),
159+ ({"field" : "" }, "field" , None , None , "empty value" ),
160+ ],
161+ )
141162def test_fieldmask (input_dict , field_name , expected_result , expected_json , description ):
142163 """Test _fieldmask function with various input scenarios."""
143164 result = _fieldmask (input_dict , field_name )
144-
165+
145166 if expected_result is None :
146167 assert result is None
147168 else :
148169 assert isinstance (result , FieldMask )
149170 assert result .ToJsonString () == expected_json
150171
151172
152- @pytest .mark .parametrize ("input_dict,field_name,expected_length,expected_json_list,description" , [
153- ({"field" : ["path1,path2" , "path3,path4" ]}, "field" , 2 , ["path1,path2" , "path3,path4" ], "valid repeated fieldmasks" ),
154- ({}, "field" , None , None , "missing field" ),
155- ({"field" : None }, "field" , None , None , "None value" ),
156- ({"field" : []}, "field" , None , None , "empty list" ),
157- ])
173+ @pytest .mark .parametrize (
174+ "input_dict,field_name,expected_length,expected_json_list,description" ,
175+ [
176+ (
177+ {"field" : ["path1,path2" , "path3,path4" ]},
178+ "field" ,
179+ 2 ,
180+ ["path1,path2" , "path3,path4" ],
181+ "valid repeated fieldmasks" ,
182+ ),
183+ ({}, "field" , None , None , "missing field" ),
184+ ({"field" : None }, "field" , None , None , "None value" ),
185+ ({"field" : []}, "field" , None , None , "empty list" ),
186+ ],
187+ )
158188def test_repeated_fieldmask (input_dict , field_name , expected_length , expected_json_list , description ):
159189 """Test _repeated_fieldmask function with various input scenarios."""
160190 result = _repeated_fieldmask (input_dict , field_name )
161-
191+
162192 if expected_length is None :
163193 assert result is None
164194 else :
0 commit comments