Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wonderbeyond opened this issue Nov 28, 2017 · 1 comment

Comments

@wonderbeyond
Copy link
Contributor

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 ===============================================
@dwin
Copy link

dwin commented Dec 8, 2019

Also seeing this issue.

============= 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 = 'bnmndnb24smglu325fvg'

    @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           xid.InvalidXid: bnmndnb24smglu325fvg

xid.py:159: InvalidXid
========================= 1 failed, 9 passed in 0.12s ==========================
##[error]Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants