def test_decode(salt, alphabet, min_length, hashid): alphabet = str(alphabet) salt = str(salt) hashid = str(hashid) hashids = Hashids(salt=salt, alphabet=alphabet, min_length=min_length) hashids_cffi = HashidsCFFI(salt=salt, alphabet=alphabet, min_length=min_length) hashid_decoded_numbers = hashids.decode(hashid) # TODO: Add overflow checks the to C library # These cases causes integer overflow assume(all((number <= MAX_ULONGLONG for number in hashid_decoded_numbers)) or (hashid_decoded_numbers == ())) assert hashid_decoded_numbers == hashids_cffi.decode(hashid)
def bench(): h = HashidsCFFI(min_length=min_length) h.decode(hashid)
def test_only_one_valid(self): h = Hashids(min_length=6) assert h.decode(h.encode(1)[:-1] + '0') == ()
def test_alphabet_with_two_standard_separators(self, numbers, hashid): h = Hashids( alphabet='abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890uC') assert h.decode(hashid) == numbers
def test_all_parameters(self, numbers, hashid): h = Hashids('arbitrary salt', 16, 'abcdefghijklmnopqrstuvwxyz') assert h.decode(hashid) == numbers
def test_min_length(self, numbers, hashid): h = Hashids(min_length=25) assert h.decode(hashid) == numbers
def test_alphabet(self, numbers, hashid): h = Hashids( alphabet= '!"#%&\',-/0123456789:;<=>ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~' ) assert h.decode(hashid) == numbers
def test_salt(self, numbers, hashid): h = Hashids(salt='Arbitrary string') assert h.decode(hashid) == numbers
def test_multiple_numbers(self, numbers, hashid): h = Hashids() assert h.decode(hashid) == numbers
def test_single_number(self, numbers, hashid): h = Hashids() assert h.decode(hashid) == numbers