File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -67,11 +67,15 @@ 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
72- or (c .isdigit () and not graphql_name [i - 1 ].isdigit ())
73+ or (
74+ c .isdigit ()
75+ and not graphql_name [i - 1 ].isdigit ()
76+ )
7377 # 134test -> 134_test
74- or (not c .isdigit () and graphql_name [i - 1 ].isdigit ())
78+ or (not c .isdigit () and graphql_name [i ] != "_" and graphql_name [ i - 1 ].isdigit ())
7579 ):
7680 python_name += "_"
7781 python_name += c
Original file line number Diff line number Diff 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+
4557def test_no_underscore_added_if_previous_character_is_uppercase ():
4658 assert convert_camel_case_to_snake ("testWithUPPERPart" ) == "test_with_upper_part"
4759
You can’t perform that action at this time.
0 commit comments