def test_strings_with_latin_chars(self): test_cases = [ ("", ""), ("???", ""), ("using-Hyphen", "using_hyphen"), ("en–dash", "endash"), # unicode non-letter characters stripped (" em—dash ", "emdash"), # unicode non-letter characters stripped ( "horizontal―BAR", "horizontalbar", ), # unicode non-letter characters stripped ("Hello world", "hello_world"), ("Hello_world", "hello_world"), ("Hellö wörld", "hello_world"), ("Hello world", "hello_world"), (" Hello world ", "hello_world"), ("Hello, world!", "hello_world"), ("Hello*world", "helloworld"), ( "Screenshot_2020-05-29 Screenshot(1).png", "screenshot_2020_05_29_screenshot1png", ), ] for (original, expected_result) in test_cases: self.assertEqual(safe_snake_case(original), expected_result)
def test_strings_with__non_latin_chars(self): test_cases = [ ('Straßenbahn Straßenbahn', 'straxdfenbahn_straxdfenbahn'), ('Сп орт!', 'u0421u043f_u043eu0440u0442'), ] for (original, expected_result) in test_cases: self.assertEqual(safe_snake_case(original), expected_result)
def test_strings_with_latin_chars(self): test_cases = [ ('', ''), ('???', ''), ('using-Hyphen', 'using_hyphen'), ('en–dash', 'endash'), # unicode non-letter characters stripped (' em—dash ', 'emdash'), # unicode non-letter characters stripped ('horizontal―BAR', 'horizontalbar'), # unicode non-letter characters stripped ('Hello world', 'hello_world'), ('Hello_world', 'hello_world'), ('Hellö wörld', 'hello_world'), ('Hello world', 'hello_world'), (' Hello world ', 'hello_world'), ('Hello, world!', 'hello_world'), ('Hello*world', 'helloworld'), ('Screenshot_2020-05-29 Screenshot(1).png', 'screenshot_2020_05_29_screenshot1png') ] for (original, expected_result) in test_cases: self.assertEqual(safe_snake_case(original), expected_result)
def get_field_clean_name(label): """ Converts a user entered field label to a template and JSON safe ascii value to be used as the internal key (clean name) for the field. """ return safe_snake_case(label)