Skip to content

Commit

Permalink
Remove to_const function (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimbo authored Jun 25, 2020
1 parent 4b70186 commit a1fc368
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 15 deletions.
5 changes: 0 additions & 5 deletions graphene/utils/str_converters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
from unidecode import unidecode


# Adapted from this response in Stackoverflow
Expand All @@ -16,7 +15,3 @@ def to_camel_case(snake_str):
def to_snake_case(name):
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()


def to_const(string):
return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()
10 changes: 1 addition & 9 deletions graphene/utils/tests/test_str_converters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
from ..str_converters import to_camel_case, to_const, to_snake_case
from ..str_converters import to_camel_case, to_snake_case


def test_snake_case():
Expand All @@ -17,11 +17,3 @@ def test_camel_case():
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():
assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"


def test_to_const_unicode():
assert to_const("Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def run_tests(self):
"graphql-core>=3.1.0b1,<4",
"graphql-relay>=3.0,<4",
"aniso8601>=8,<9",
"unidecode>=1.1.1,<2",
],
tests_require=tests_require,
extras_require={"test": tests_require, "dev": dev_requires},
Expand Down

1 comment on commit a1fc368

@sbhatm1213
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jkimbo

The to_const method is being used in converter.py too.
So, now there's an import error : ImportError: cannot import name 'to_const' from 'graphene.utils.str_converters' .
I'm temporarily copying this re.sub(r"[\W|^]+", "_", unidecode(string)).upper() in place of to_const call .
What's the permanent fix ?

Please sign in to comment.