Skip to content

Commit

Permalink
fix(helpers): hot fix for to_snake_case func - added cyrillic support
Browse files Browse the repository at this point in the history
  • Loading branch information
akimrx committed Mar 20, 2024
1 parent bf40ed9 commit f5c7bd0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def test_validate_resource(resource, attribute, low, expected):
@pytest.mark.parametrize(
"text, expected",
[
("русскаястрока", "русскаястрока"),
("РусскийВерблюд", "русский_верблюд"),
("Русские пробелы", "русские_пробелы"),
("РусскийДлинныйВерблюдПлюсЧисло1", "русский_длинный_верблюд_плюс_число_1"),
("singlestring", "singlestring"),
("camelCase", "camel_case"),
("longCamelCase", "long_camel_case"),
("longCamelCaseWithNumber1", "long_camel_case_with_number_1"),
Expand Down
2 changes: 1 addition & 1 deletion tracker_exporter/_meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "1.0.1"
version = "1.0.2"
url = "https://github.com/akimrx/yandex-tracker-exporter"
download_url = "https://pypi.org/project/tracker-exporter/"
appname = "yandex_tracker_exporter"
Expand Down
9 changes: 5 additions & 4 deletions tracker_exporter/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ def to_snake_case(text: str) -> str:
if text.strip() == "":
return text.strip()

text = re.sub(r"(?<=[a-z])(?=[A-Z])", "_", text)
text = re.sub(r"(?<=[a-z])(?=\d)", "_", text)
text = re.sub(r"(?<=\d)(?=[a-z])", "_", text)
text = re.sub(r"[^a-zA-Z0-9_]", "_", text)
text = re.sub(r"(?<=[a-zа-яё])(?=[A-ZА-ЯЁ])", "_", text)
text = re.sub(r"(?<=[a-zа-яё])(?=\d)", "_", text)
text = re.sub(r"(?<=\d)(?=[a-zа-яё])", "_", text)
text = re.sub(r"[^a-zA-Zа-яёА-ЯЁ0-9_]", "_", text)


return text.lower()

Expand Down

0 comments on commit f5c7bd0

Please sign in to comment.