Skip to content

Commit 754d50a

Browse files
committed
Add test for duplicate values in Enum
1 parent 75c437a commit 754d50a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

openapi_python_client/openapi_parser/properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def values_from_list(l: List[str]) -> Dict[str, str]:
296296
else:
297297
key = f"VALUE_{i}"
298298
if key in output:
299-
raise AssertionError(f"Duplicate key {key} in Enum")
299+
raise ValueError(f"Duplicate key {key} in Enum")
300300
output[key] = value
301301

302302
return output

tests/test_openapi_parser/test_properties.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ def test_values_from_list(self):
295295
"VALUE_3": "1bc",
296296
}
297297

298+
def test_values_from_list_duplicate(self):
299+
from openapi_python_client.openapi_parser.properties import EnumProperty
300+
301+
data = ["abc", "123", "a23", "abc"]
302+
303+
with pytest.raises(ValueError):
304+
EnumProperty.values_from_list(data)
305+
298306
def test_get_all_enums(self, mocker):
299307
from openapi_python_client.openapi_parser import properties
300308

0 commit comments

Comments
 (0)