Skip to content

Commit abc7a33

Browse files
camel_cate_to_snake_case macros
1 parent 0b4195b commit abc7a33

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

airbyte_cdk/sources/declarative/interpolation/macros.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import builtins
66
import datetime
7+
import re
78
import typing
89
from typing import Optional, Union
910
from urllib.parse import quote_plus
@@ -194,6 +195,10 @@ def sanitize_url(value: str) -> str:
194195
return sanitization_strategy(value)
195196

196197

198+
def camel_cate_to_snake_case(value: str) -> str:
199+
return re.sub(r'(?<!^)(?=[A-Z])', '_', value).lower()
200+
201+
197202
_macros_list = [
198203
now_utc,
199204
today_utc,
@@ -206,5 +211,6 @@ def sanitize_url(value: str) -> str:
206211
today_with_timezone,
207212
str_to_datetime,
208213
sanitize_url,
214+
camel_cate_to_snake_case,
209215
]
210216
macros = {f.__name__: f for f in _macros_list}

unit_tests/sources/declarative/interpolation/test_macros.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,28 @@ def test_sanitize_url(test_name, input_value, expected_output):
249249
sanitize_url = macros["sanitize_url"]
250250
actual_output = sanitize_url(input_value)
251251
assert actual_output == expected_output
252+
253+
254+
@pytest.mark.parametrize(
255+
"value, expected_value",
256+
[
257+
(
258+
"CamelCase",
259+
"camel_case",
260+
),
261+
(
262+
"snake_case",
263+
"snake_case",
264+
),
265+
(
266+
"CamelCasesnake_case",
267+
"camel_casesnake_case",
268+
),
269+
(
270+
"CamelCase_snake_case",
271+
"camel_case_snake_case",
272+
),
273+
],
274+
)
275+
def test_camel_cate_to_snake_case(value, expected_value):
276+
assert macros["camel_cate_to_snake_case"](value) == expected_value

0 commit comments

Comments
 (0)