Skip to content

Commit 5641c6e

Browse files
author
Barry Barrette
committed
Adding test coverage
1 parent 4925fea commit 5641c6e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

openapi_python_client/parser/properties/enum_property.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ def values_from_list(
195195
value = cast(Union[str, int], value)
196196
if isinstance(value, int):
197197
if use_var_names:
198-
key = var_names[i].upper()
199-
output[key] = value
198+
key = var_names[i]
199+
sanitized_key = utils.snake_case(key).upper()
200+
output[sanitized_key] = value
200201
elif value < 0:
201202
output[f"VALUE_NEGATIVE_{-value}"] = value
202203
else:

tests/test_parser/test_properties/test_init.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_values_from_list(self):
352352

353353
data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces", ""]
354354

355-
result = EnumProperty.values_from_list(data, Class("ClassName", "module_name"))
355+
result = EnumProperty.values_from_list(data, Class("ClassName", "module_name"), [])
356356

357357
assert result == {
358358
"ABC": "abc",
@@ -371,7 +371,21 @@ def test_values_from_list_duplicate(self):
371371
data = ["abc", "123", "a23", "abc"]
372372

373373
with pytest.raises(ValueError):
374-
EnumProperty.values_from_list(data, Class("ClassName", "module_name"))
374+
EnumProperty.values_from_list(data, Class("ClassName", "module_name"), [])
375+
376+
def test_int_enum_var_names_extension(self):
377+
from openapi_python_client.parser.properties import EnumProperty
378+
379+
data = [-1, 1, 2]
380+
var_names = ["Negative One", "One", "Two"]
381+
382+
result = EnumProperty.values_from_list(data, Class("ClassName", "module_name"), var_names)
383+
384+
assert result == {
385+
"NEGATIVE_ONE": -1,
386+
"ONE": 1,
387+
"TWO": 2,
388+
}
375389

376390

377391
class TestLiteralEnumProperty:

0 commit comments

Comments
 (0)