mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-27 03:33:24 +00:00
import helper from source
This commit is contained in:
@@ -119,22 +119,3 @@ def to_snake_case(string: str) -> str:
|
||||
.replace(" ", "_")
|
||||
.replace("__", "_")
|
||||
)
|
||||
|
||||
|
||||
def to_camel_case(string: str):
|
||||
"""Convert a string to camel case.
|
||||
|
||||
If all characters are lower case we return title version of the string.
|
||||
|
||||
Examples
|
||||
--------
|
||||
"close" -> "Close"
|
||||
"some_field" -> "someField"
|
||||
"""
|
||||
s_list = string.replace("-", " ").replace("_", " ").split()
|
||||
if len(string) == 0:
|
||||
return string
|
||||
result = s_list[0] + "".join(i.capitalize() for i in s_list[1:])
|
||||
if result.islower():
|
||||
return result.title()
|
||||
return result
|
||||
|
||||
@@ -6,7 +6,6 @@ from openbb_core.provider.utils.helpers import (
|
||||
get_querystring,
|
||||
get_user_agent,
|
||||
make_request,
|
||||
to_camel_case,
|
||||
to_snake_case,
|
||||
)
|
||||
|
||||
@@ -69,11 +68,3 @@ def test_to_snake_case():
|
||||
assert to_snake_case("SomeRandomString") == "some_random_string"
|
||||
assert to_snake_case("someRandomString") == "some_random_string"
|
||||
assert to_snake_case("already_snake_case") == "already_snake_case"
|
||||
|
||||
|
||||
def test_to_camel_case():
|
||||
"""Test the to_camel_case helper."""
|
||||
assert to_camel_case("some_field") == "someField"
|
||||
assert to_camel_case("alreadyCamelCase") == "alreadyCamelCase"
|
||||
assert to_camel_case("close") == "Close"
|
||||
assert not to_camel_case("")
|
||||
|
||||
Reference in New Issue
Block a user