mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-09-04 07:40:42 +02:00
feat(title): add pascal_to_title function and corresponding tests
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user