mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 04:07:16 +03:00
Merge pull request #644 from frsv/issue-643_fields_capitalizes_incorrectly
Change .title method to .capitalize in to_camel_case() in str_convertes.py
This commit is contained in:
commit
be1f7d72a4
|
@ -1,13 +1,13 @@
|
|||
import re
|
||||
|
||||
|
||||
# From this response in Stackoverflow
|
||||
# Adapted from this response in Stackoverflow
|
||||
# http://stackoverflow.com/a/19053800/1072990
|
||||
def to_camel_case(snake_str):
|
||||
components = snake_str.split('_')
|
||||
# We capitalize the first letter of each component except the first one
|
||||
# with the 'title' method and join them together.
|
||||
return components[0] + "".join(x.title() if x else '_' for x in components[1:])
|
||||
# with the 'capitalize' method and join them together.
|
||||
return components[0] + ''.join(x.capitalize() if x else '_' for x in components[1:])
|
||||
|
||||
|
||||
# From this response in Stackoverflow
|
||||
|
|
|
@ -16,6 +16,7 @@ def test_camel_case():
|
|||
assert to_camel_case('snakes_on_a_plane') == 'snakesOnAPlane'
|
||||
assert to_camel_case('snakes_on_a__plane') == 'snakesOnA_Plane'
|
||||
assert to_camel_case('i_phone_hysteria') == 'iPhoneHysteria'
|
||||
assert to_camel_case('field_i18n') == 'fieldI18n'
|
||||
|
||||
|
||||
def test_to_const():
|
||||
|
|
Loading…
Reference in New Issue
Block a user