U af'@sLddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z ddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd l mZejdejedGdddejZGdddejZGdddejZGdddejZGdddejZGdddejZedkrHe dS)N) defaultdict)patch)UUID)uuid4)cli)decode)encode) get_alphabet)random) set_alphabet ShortUUID)uuidz/../..c@s4eZdZddZddZddZddZd d Zd S) LegacyShortUUIDTestcCs|dttkodkn|dttdkoBdkn|dttdkohdkn|dttdkodkndSNzhttp://www.example.com/zHTTP://www.example.com/z example.com/) assertTruelenr)selfrI/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/shortuuid/test_shortuuid.pytest_generations$&&z#LegacyShortUUIDTest.test_generationcCstd}|t|ddSNz&{3b1f8b40-222c-4a6e-b77e-779d5a94e21c}CXc85b4rqinB7s5J52TRYb)r assertEqualrrurrr test_encodingsz!LegacyShortUUIDTest.test_encodingcCstd}|td|dSr)rrrrrrr test_decoding!sz!LegacyShortUUIDTest.test_decodingcCst}d}t|||ttd||t|tttd|dttkohdknt}||tt |t}||t t|| t td| t tdt|| t ddd dS) N0101010101010101t11111111cSst|S)Nr )xrrr=z3LegacyShortUUIDTest.test_alphabet..0) r r rsetrrrrrr assertRaises ValueError)rZbackup_alphabetalphabetrrrr test_alphabet%s $z!LegacyShortUUIDTest.test_alphabetcCs:|ttdtddD]}|tt||qdS)Nd)rrr range)rirrr test_random?szLegacyShortUUIDTest.test_randomN)__name__ __module__ __qualname__rrrr.r4rrrrrs rc@s<eZdZddZddZddZddZd d Zd d Zd S)ClassShortUUIDTestcCst}|dt|ko$dkn|dt|dkoLdkn|dt|dkotdkn|dt|dkodkndSr)r rrrrsurrrrFs &((z"ClassShortUUIDTest.test_generationcCs$t}td}|||ddSr)r rrrrr:rrrrrMsz ClassShortUUIDTest.test_encodingcCs$t}td}||d|dSr)r rrrr;rrrrRsz ClassShortUUIDTest.test_decodingcCsRt}tdD]}|t|dqtddD]}|t|||q2dS)Nr/r0r1)r r2rrr )rr:r3rrrr4Ws  zClassShortUUIDTest.test_randomcCsd}t|}t}||||d||||t|td|dt|kordkn|dt|kodknt}||| | ||}||| | || t |jd| t |jddS) Nr r!r"r#rrr$r%) r rr r r*rrrrrrr+r,)rr-su1su2rrrrr._s &&z ClassShortUUIDTest.test_alphabetcCs~t}||dtjtjtjd}t|}||dd}t|}||dt}||jddddS)Nr/z+/r ) num_bytes )r rZencoded_lengthstringascii_uppercaseascii_lowercasedigits)rr=Zbase64_alphabetr>Zbinary_alphabetZsu3Zsu4rrrtest_encoded_lengthvsz&ClassShortUUIDTest.test_encoded_lengthN) r5r6r7rrrr4r.rGrrrrr8Es r8c@s$eZdZddZddZddZdS)ShortUUIDPaddingTestcCsBt}t}tdd}||}||}|t|t|dSNr)int)r rrrrrrr: random_uidZ smallest_uidencoded_randomZ encoded_smallrrr test_paddings    z!ShortUUIDPaddingTest.test_paddingcCsRt}t}tdd}||}||}||||||||dSrI)r rrrrrrKrrrrs   z"ShortUUIDPaddingTest.test_decodingc Cst}d}tt}t|D]>}t}||}|t|d7<||}|||q|t|dt t | }||||dS)Nr<r0) r rrJr2rrrrrnextiterkeys) rr:Znum_iterationsZ uid_lengthscountrLrMZdecoded_randomZ uid_lengthrrrtest_consistencys   z%ShortUUIDPaddingTest.test_consistencyN)r5r6r7rNrrSrrrrrHs  rHc@seZdZddZdS)EncodingEdgeCasesTestcCsZt}|t|jg|t|ji|t|jd|t|jd|t|jddSN)*gE@)r r+r,rrr9rrrtest_decode_dicts z&EncodingEdgeCasesTest.test_decode_dictNr5r6r7rXrrrrrTsrTc@seZdZddZdS)DecodingEdgeCasesTestcCsZt}|t|jg|t|ji|t|jd|t|jd|t|jddSrU)r r+r,rr9rrrrXs z&DecodingEdgeCasesTest.test_decode_dictNrYrrrrrZsrZc@s<eZdZedddZedddZedddZdS) CliTestzshortuuid.cli.printcCs2tg||jdd}|t|ddS)Nrr/)rZ assert_called call_argsrrrZ mock_printZterminal_outputrrr$test_shortuuid_command_produces_uuidsz,CliTest.test_shortuuid_command_produces_uuidcCs*tddg|jdd}||ddS)Nr$3b1f8b40-222c-4a6e-b77e-779d5a94e21crrrr\rr]rrrtest_encode_commands zCliTest.test_encode_commandcCs*tddg|jdd}||ddS)Nrrrr_r`r]rrrtest_decode_commands zCliTest.test_decode_commandN)r5r6r7rr^rarbrrrrr[s   r[__main__)!osrCsysunittest collectionsrZ unittest.mockrrrrZ shortuuid.clirZshortuuid.mainrrr r r r pathinsertabspath__file__ZTestCaserr8rHrTrZr[r5mainrrrrs0            /D)