def test_parse_invalid_data() -> None: with pytest.raises(ParseError) as exc_info: parse("abc") assert str(exc_info.value) == ( "Failed to parse 'abc':\n" "- GTIN: Failed to parse 'abc' as GTIN: " "Expected 8, 12, 13, or 14 digits, got 3.\n" "- SSCC: Failed to parse 'abc' as SSCC: Expected 18 digits, got 3.\n" "- GS1: Failed to get GS1 Application Identifier from 'abc'.")
def test_parse_strips_symbology_identifier() -> None: result = parse("]E05901234123457") assert result.value == "]E05901234123457" assert result.symbology_identifier is not None assert result.symbology_identifier.value == "]E0" assert result.gtin is not None assert result.gtin.value == "5901234123457"
def test_parse_with_separator_char() -> None: result = parse("101313|15210526", separator_chars=["|"]) assert result.gs1_message is not None assert result.gs1_message.as_hri() == "(10)1313(15)210526"
def test_parse_strips_surrounding_whitespace() -> None: result = parse(" \t 5901234123457 \n ") assert result.value == "5901234123457" assert result.gtin is not None assert result.gtin.value == "5901234123457"
def test_parse(value: str, expected: ParseResult) -> None: assert parse(value) == expected