feat(title): add pascal_to_title function and corresponding tests

This commit is contained in:
2026-08-24 12:14:02 +02:00
committed by Jan Wyzula
parent 8926bebe06
commit c8e01a38f4
2 changed files with 20 additions and 1 deletions
+14
View File
@@ -16,6 +16,20 @@ def pascal_to_snake(name: str) -> str:
return s2.lower()
def pascal_to_title(name: str) -> str:
"""
Convert PascalCase to a space-separated title.
Args:
name (str): The name to be converted.
Returns:
str: The converted name.
"""
s1 = re.sub(r"([a-z0-9])([A-Z])", r"\1 \2", name)
return re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1 \2", s1)
def sanitize_namespace(namespace: str | None) -> str | None:
"""
Clean user-provided namespace labels for filesystem compatibility.
+6 -1
View File
@@ -1,4 +1,4 @@
from bec_widgets.utils.name_utils import pascal_to_snake, sanitize_namespace
from bec_widgets.utils.name_utils import pascal_to_snake, pascal_to_title, sanitize_namespace
def test_pascal_to_snake():
@@ -6,6 +6,11 @@ def test_pascal_to_snake():
assert pascal_to_snake("BECStatusWidget") == "bec_status_widget"
def test_pascal_to_title():
assert pascal_to_title("DigitalTwin") == "Digital Twin"
assert pascal_to_title("BECStatusWidget") == "BEC Status Widget"
def test_sanitize_namespace():
assert sanitize_namespace("scan 1 / user") == "scan_1_user"
assert sanitize_namespace(" beamline.state-1 ") == "beamline.state-1"