Skip to content

Commit f911f5f

Browse files
committed
fmt
1 parent 02c33c2 commit f911f5f

File tree

2 files changed

+108
-66
lines changed

2 files changed

+108
-66
lines changed

tests/test_fieldmask.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from databricks.sdk.common.types.fieldmask import FieldMask
44

55

6-
@pytest.mark.parametrize("input_paths,expected_result,description", [
7-
(["field1", "field2", "field3"], "field1,field2,field3", "basic list of paths"),
8-
(["single_field"], "single_field", "single path"),
9-
([], "", "empty paths list"),
10-
(["user.name", "user.email", "address.street"], "user.name,user.email,address.street", "nested field paths"),
11-
])
6+
@pytest.mark.parametrize(
7+
"input_paths,expected_result,description",
8+
[
9+
(["field1", "field2", "field3"], "field1,field2,field3", "basic list of paths"),
10+
(["single_field"], "single_field", "single path"),
11+
([], "", "empty paths list"),
12+
(["user.name", "user.email", "address.street"], "user.name,user.email,address.street", "nested field paths"),
13+
],
14+
)
1215
def test_to_json_string(input_paths, expected_result, description):
1316
"""Test ToJsonString with various path configurations."""
1417
field_mask = FieldMask()
@@ -19,13 +22,16 @@ def test_to_json_string(input_paths, expected_result, description):
1922
assert result == expected_result
2023

2124

22-
@pytest.mark.parametrize("input_string,expected_paths,description", [
23-
("field1,field2,field3", ["field1", "field2", "field3"], "basic comma-separated string"),
24-
("single_field", ["single_field"], "single field"),
25-
("", [], "empty string"),
26-
("user.name,user.email,address.street", ["user.name", "user.email", "address.street"], "nested field paths"),
27-
("field1, field2 , field3", ["field1", " field2 ", " field3"], "spaces around commas"),
28-
])
25+
@pytest.mark.parametrize(
26+
"input_string,expected_paths,description",
27+
[
28+
("field1,field2,field3", ["field1", "field2", "field3"], "basic comma-separated string"),
29+
("single_field", ["single_field"], "single field"),
30+
("", [], "empty string"),
31+
("user.name,user.email,address.street", ["user.name", "user.email", "address.street"], "nested field paths"),
32+
("field1, field2 , field3", ["field1", " field2 ", " field3"], "spaces around commas"),
33+
],
34+
)
2935
def test_from_json_string_success_cases(input_string, expected_paths, description):
3036
"""Test FromJsonString with various valid input strings."""
3137
field_mask = FieldMask()
@@ -35,12 +41,15 @@ def test_from_json_string_success_cases(input_string, expected_paths, descriptio
3541
assert field_mask.paths == expected_paths
3642

3743

38-
@pytest.mark.parametrize("invalid_input,expected_error_substring,description", [
39-
(123, "FieldMask JSON value not a string: 123", "non-string integer input"),
40-
(None, "FieldMask JSON value not a string: None", "None input"),
41-
(["field1", "field2"], "FieldMask JSON value not a string:", "list input"),
42-
({"field": "value"}, "FieldMask JSON value not a string:", "dict input"),
43-
])
44+
@pytest.mark.parametrize(
45+
"invalid_input,expected_error_substring,description",
46+
[
47+
(123, "FieldMask JSON value not a string: 123", "non-string integer input"),
48+
(None, "FieldMask JSON value not a string: None", "None input"),
49+
(["field1", "field2"], "FieldMask JSON value not a string:", "list input"),
50+
({"field": "value"}, "FieldMask JSON value not a string:", "dict input"),
51+
],
52+
)
4453
def test_from_json_string_error_cases(invalid_input, expected_error_substring, description):
4554
"""Test FromJsonString raises ValueError for invalid input types."""
4655
field_mask = FieldMask()
@@ -51,11 +60,14 @@ def test_from_json_string_error_cases(invalid_input, expected_error_substring, d
5160
assert expected_error_substring in str(exc_info.value)
5261

5362

54-
@pytest.mark.parametrize("original_paths,description", [
55-
(["user.name", "user.email", "profile.settings"], "multiple nested fields"),
56-
(["single_field"], "single field"),
57-
([], "empty paths"),
58-
])
63+
@pytest.mark.parametrize(
64+
"original_paths,description",
65+
[
66+
(["user.name", "user.email", "profile.settings"], "multiple nested fields"),
67+
(["single_field"], "single field"),
68+
([], "empty paths"),
69+
],
70+
)
5971
def test_roundtrip_conversion(original_paths, description):
6072
"""Test that ToJsonString and FromJsonString are inverse operations."""
6173
field_mask = FieldMask()

tests/test_internal.py

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)
6972
def 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+
)
8698
def 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+
)
105120
def 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+
)
122140
def 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+
)
141162
def 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+
)
158188
def 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

Comments
 (0)