get_project_root()Path('/home/jelle/code/hopsa')
get_project_root ()
Get the project root directory from either notebook or module context
get_project_name ()
Remove special characters from names, convert to lowercase, and remove leading and trailing whitespace. Especially convenient to create filenames and foldernames that are compatible with most operating systems, but can also be used to sanitize names for other purposes.
sanitize_name (name:str)
Remove special characters from names, convert to lowercase, and remove leading and trailing whitespace.
"""Test basic sanitization cases"""
test_eq(sanitize_name("My Test Name"), "my_test_name")
test_eq(sanitize_name(" Trim Me "), "trim_me")
test_eq(sanitize_name("UPPER CASE"), "upper_case")
"""Test with special characters"""
test_eq(sanitize_name("File@Name#123"), "file_name_123")
test_eq(sanitize_name("user@domain.com"), "user_domain_com")
test_eq(sanitize_name("test$%^&*()name"), "test_name")
"""Test with emoticons and unicode characters"""
test_eq(sanitize_name("Happy 😊 Face"), "happy_face")
test_eq(sanitize_name("Thumbs 👍 Up"), "thumbs_up")
test_eq(sanitize_name("Café "), "cafe")
test_eq(sanitize_name("Mötörhead"), "motorhead")
"""Test with multiple spaces and various whitespace characters"""
test_eq(sanitize_name("Too Many Spaces"), "too_many_spaces")
test_eq(sanitize_name("New\nLine"), "new_line")
test_eq(sanitize_name("Tab\tSeparated"), "tab_separated")
"""Test edge cases and empty inputs"""
test_eq(sanitize_name(""), "")
test_eq(sanitize_name(" "), "")
test_eq(sanitize_name("!@#$%^"), "")
test_eq(sanitize_name("123"), "123")
test_eq(sanitize_name("a"), "a")