Skip to content

Commit 0f645cc

Browse files
A-DudekKarolJagodzinski
authored andcommittedFeb 26, 2025
Fix convert_camel_case_to_snake
1 parent e03d333 commit 0f645cc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎ariadne/utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ def convert_camel_case_to_snake(graphql_name: str) -> str:
6767
i < max_index
6868
and graphql_name[i] != c
6969
and graphql_name[i + 1] == lowered_name[i + 1]
70+
and graphql_name[i + 1] != "_"
7071
)
7172
# test134 -> test_134
7273
or (c.isdigit() and not graphql_name[i - 1].isdigit())
7374
# 134test -> 134_test
74-
or (not c.isdigit() and graphql_name[i - 1].isdigit())
75+
or (
76+
not c.isdigit()
77+
and graphql_name[i] != "_"
78+
and graphql_name[i - 1].isdigit()
79+
)
7580
):
7681
python_name += "_"
7782
python_name += c

‎tests/test_camel_case_to_snake_case_convertion.py

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ def test_no_underscore_added_if_previous_character_is_an_underscore():
4242
assert convert_camel_case_to_snake("test__complexName") == "test__complex_name"
4343

4444

45+
@pytest.mark.parametrize(
46+
("test_str", "result"),
47+
[
48+
("FOO_bar", "foo_bar"),
49+
("FOO_BAR", "foo_bar"),
50+
("S3_BUCKET", "s_3_bucket"),
51+
],
52+
)
53+
def test_no_underscore_added_if_next_character_is_an_underscore(test_str, result):
54+
assert convert_camel_case_to_snake(test_str) == result
55+
56+
4557
def test_no_underscore_added_if_previous_character_is_uppercase():
4658
assert convert_camel_case_to_snake("testWithUPPERPart") == "test_with_upper_part"
4759

0 commit comments

Comments
 (0)