import pytest from src.backend.utils import strings @pytest.mark.parametrize( "string,expected", [ ("This is a test", "This is a test"), ("This is a test ", "This is a test "), (" This is a test", " This is a test"), (" This is a test ", " This is a test "), ], ) def test_remove_multispace(string, expected): assert strings.remove_multispace(string) == expected class TestCapitalizeTitle: @pytest.mark.parametrize( "string,expected", [ ("test", "Test"), ("", ""), ("test string", "Test String"), ("test-string", "Test-String"), ("test-STring", "Test-String"), ], ) def test_capitalize_title(self, string, expected): assert strings.capitalize_title(string) == expected @pytest.mark.parametrize( "string,expected", [ ("test STRING", "Test STRING"), ("TESt striNg", "TESt StriNg"), ("test-STring", "Test-STring"), ], ) def test_capitalize_title_keep_casing(self, string, expected): assert strings.capitalize_title(string, keep_casing=True) == expected @pytest.mark.parametrize( "string,ignore_words,expected", [ ("test sTRING ok", ["ok", "sTRING"], "Test sTRING ok"), ("test sTRING ok", ["ok", ""], "Test String ok"), ], ) def test_capitalize_title_ignore_words(self, string, ignore_words, expected): assert strings.capitalize_title(string, ignore_words=ignore_words) == expected @pytest.mark.parametrize( "string,expected", [ ("", ""), (" ", " "), ("iTunes", "i_tunes"), ("iTunesSearch", "i_tunes_search"), ("OneTwoThree", "one_two_three"), ("oneTwoThree fourFive", "one_two_three four_five"), ], ) def test_snake_case(string, expected): assert strings.snake_case(string) == expected @pytest.mark.parametrize( "mapping,expected", [ ({"testKey": "testValue"}, {"test_key": "testValue"}), ( {"testKey": {"testKey": "testValue"}}, {"test_key": {"test_key": "testValue"}}, ), ( {"testKey": [{"testKey": "testValue"}]}, {"test_key": [{"test_key": "testValue"}]}, ), ], ) def test_snake_case_mapping(mapping, expected): assert strings.snake_case_mapping(mapping) == expected @pytest.mark.parametrize( "number,max_precision,expected", [ (3.0, 0, "3"), (3.0, -1, "3"), (3.14159, 2, "3.14"), (3.14159, 5, "3.14159"), (3.14159, 0, "3"), ], ) def test_var_precision(number, max_precision, expected): assert strings.var_precision(number, max_precision) == expected @pytest.mark.parametrize( "number,expected", [ (100, "100"), (99.9, "99.9"), (9.999, "10.0"), (1000, "1.0K"), (1000000, "1.0M"), (100.0, "100"), (1000.0, "1.0K"), (1000000.0, "1.0M"), ("100", "100"), ("1000", "1.0K"), ("1000000", "1.0M"), ("100.0", "100"), ("1000.0", "1.0K"), ("1000000.0", "1.0M"), (1000000000, NotImplementedError), ], ) def test_shorten_number(number, expected): if isinstance(expected, str): assert strings.shorten_number(number) == expected else: with pytest.raises(expected): strings.shorten_number(number) @pytest.mark.parametrize( "string,expected", [ ("Café", "Cafe"), ("âêîôû", "aeiou"), ("ç ñ", "ç ñ"), ("äëï öü", "aei ou"), ("áéíóú", "aeiou"), ("àèìòù", "aeiou"), ("ãõ", "ao"), ("å", "a"), ("ÁÉÍÓÚ", "AEIOU"), ("ÀÈÌÒÙ", "AEIOU"), ("ÃÕ", "AO"), ("Å", "A"), ], ) def test_remove_accents(string, expected): assert strings.remove_accents(string) == expected