Esempio n. 1
0
def test_from_str_raises_when_not_128_bits(valid_bytes_48):
    """
    Assert that :func:`~ulid.api.from_str` raises a :class:`~ValueError` when given bytes
    that is not 128 bit in length.
    """
    value = base32.encode(valid_bytes_48)
    with pytest.raises(ValueError) as ex:
        api.from_str(value)
    assert ex.match(STR_SIZE_EXC_REGEX)
Esempio n. 2
0
def test_github_issue_61():
    """
    Assert that :func:`~ulid.api.from_str` will raise a :class:`~ValueError` when given a string
    that contains values not in the Base32 character set.

    In this example, the main character to test is "u" and "U".

    Issue: https://github.com/ahawker/ulid/issues/61
    """
    for s in ('01BX73KC0TNH409RTFD1uXKM00', '01BX73KC0TNH409RTFD1UXKM00'):
        with pytest.raises(ValueError):
            api.from_str(s)
Esempio n. 3
0
def test_from_str_returns_ulid_instance(valid_bytes_128):
    """
    Assert that :func:`~ulid.api.from_str` returns a new :class:`~ulid.ulid.ULID` instance
    from the given bytes.
    """
    value = base32.encode(valid_bytes_128)
    instance = api.from_str(value)
    assert isinstance(instance, ulid.ULID)
    assert instance.bytes == valid_bytes_128
Esempio n. 4
0
def test_github_issue_58():
    """
    Assert that :func:`~ulid.api.from_str` can properly decode strings that
    contain Base32 "translate" characters.

    Base32 "translate" characters are: "iI, lL, oO".

    Issue: https://github.com/ahawker/ulid/issues/58
    """
    value = '01BX73KC0TNH409RTFD1JXKmO0'
    instance = api.from_str(value)
    assert instance.str == '01BX73KC0TNH409RTFD1JXKM00'