"""Test utils.vector_templated_strings. Copied from https://github.com/theorchard/python-vector-utils/blob/e42e786432aa6e1a1c279d4046c0c6d8e7109756/tests/utils/test_parsers.py """ import pytest from delivery_metadata.exceptions import UnsupportedPlaceholder from delivery_metadata.utils import vector_templated_strings @pytest.mark.parametrize( "pattern, skip_timestamp, expected", [ ( "{upc}_{cd(2)}_{track_id(3)}_FULL.flac", False, "2341234121341_01_001_FULL.flac", ), ( "{upc}_{cd}_{track_id}_FULL.flac", False, "2341234121341_1_1_FULL.flac", ), ( "[MD5]{upc}_{cd}_{track_id}.flac", False, "bfd4b3ed623c137c96efd3e78d11262a", ), ( "[CRC+]{upc}_{cd}_{track_id}", False, "2656581267", ), ( "[CRC]{upc}_{cd}_{track_id}", False, "-1638386029", ), ( "{upc(-6,3)}/{upc(14)}", False, "121/02341234121341", ), ( "{identifier_timestamp}", True, "{identifier_timestamp}", ), ], ) def test_process_string(pattern: str, skip_timestamp: bool, expected: str) -> None: """Test process_string function.""" replacements: dict[str, str | int] = { "upc": 2341234121341, "cd": 1, "track_id": 1, "something": "else", } assert ( vector_templated_strings.process_string(pattern, replacements, skip_timestamp) == expected ) def test_get_signed_int() -> None: """Test get_signed_int function.""" assert vector_templated_strings._get_signed_int(23452) == 23452 def test_get_signed_int_out_of_range() -> None: """Test get_signed_int function.""" assert vector_templated_strings._get_signed_int(3425353232) == -869614064 def test__parse_vars_with_exception() -> None: with pytest.raises(UnsupportedPlaceholder) as exc: vector_templated_strings._parse_vars(["{new_placeholder}"], {}) assert str(exc.value) == "new_placeholder not supported"