Skip to content

The generated xid string is not always reversible via Xid.from_string #5

Description

@wonderbeyond

I've written a test case to reveal this issue.

Execute py.test to reproduce error like below:

$ py.test
====================================================== test session starts =======================================================
platform linux2 -- Python 2.7.12, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: /home/wonder/workspace/python_xid, inifile:
collected 10 items                                                                                                                

xid_test.py .........F

============================================================ FAILURES ============================================================
_______________________________________________ TestXid.test_xid_always_reversible _______________________________________________

self = <xid_test.TestXid testMethod=test_xid_always_reversible>

    def test_xid_always_reversible(self):
        for i in range(1000):
            s = Xid().string()
>           self.assertEqual(Xid.from_string(s).string(), s)

xid_test.py:50: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'xid.Xid'>, s = 'b8edi0qo1j65kvnoejvg'

    @classmethod
    def from_string(cls, s):
        # type: (str) -> Xid
        val = base32hex.b32decode(s.upper())
        value_check = [0 < x < 255 for x in val]
    
        if not all(value_check):
>           raise InvalidXid(s)
E           InvalidXid: b8edi0qo1j65kvnoejvg

xid.py:152: InvalidXid
=============================================== 1 failed, 9 passed in 0.06 seconds ===============================================

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions