f _WWc@sNddlZddlZddlZGdddejZGdddeZGdddeZdS)Nc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%ZdS)&BasicTestMappingProtocolNcCs ddddS)z^Return a dictionary of values which are invariant by storage in the object under test.Z2Zvalue1)Z1Zkey1Zkey2selfrr+/usr/lib64/python3.10/test/mapping_tests.py _referencesz#BasicTestMappingProtocol._referencecCs|S)zReturn an empty mapping object) type2testrrrr _empty_mappingsz'BasicTestMappingProtocol._empty_mappingcCs&|}|D]\}}|||<q|S)zKReturn a mapping object with the value contained in data dictionary)r items)rZdataxkeyvaluerrr _full_mappings z&BasicTestMappingProtocol._full_mappingcOsftjj|g|Ri|||_|j\}}||i|_|j\}}||i|_||j|<dSN) unittestTestCase__init__r copy referencepopitemother inmapping)rargsZkwrrrrr rs  z!BasicTestMappingProtocol.__init__cs }t|}j|ur(|}jD]\}}||q2tjd t fddt |dt t jjD]} |qjD]} |q|||||r dsdfdd}|ttj|ttj|ttj|ttjtt\}}ttj\}||||| dS)NrcsSrrr)dknownkeyrr 6z4BasicTestMappingProtocol.test_read..z#Empty mapping must compare to Falsez!Full mapping must compare to TruecsVt|dt|dt|}t|t|koJt|kndS)N__next____iter__) assertTrueZhasattrlistZset)iterZlstZrefrrrr check_iterandlistHsz=BasicTestMappingProtocol.test_read..check_iterandlist)r dictrrr assertEqualr#rkeys assertRaisesKeyErrorlenassertIn assertNotInZassertNotEqualfailr$valuesnextget)rpZp1rrkr% knownvaluer)rrrr test_read+sJ        z"BasicTestMappingProtocol.test_readcs||jD] \}|<||q|jD] =|tfddq>||j|t|jt }|||t|j| |j}t t |\}t t |j \}}||||||||||||||||||||||||t|j|d}|||<||||||||||||||\}|||||j||tjdS)NcsSrrrrr2rr rdrz5BasicTestMappingProtocol.test_write..i)r rr r'r(r)r*updater&r#rr0r$r setdefaultpopr-r)rrr rrr4Zdefaultrr6r test_write[sD        z#BasicTestMappingProtocol.test_writecCs|||dSr)r'r rrrr test_constructorz)BasicTestMappingProtocol.test_constructorcCsJ|| ||j|t|du|t|jdudS)NFT)r"r rboolrrrr test_bools z"BasicTestMappingProtocol.test_boolcCsr|}|t|g|j}|t|jd||t|jd|| t |jddSNr) r r'r#r(rr,rr-rr) TypeErrorrrrrr test_keyss z"BasicTestMappingProtocol.test_keyscC0|}|t|g|t|jddSr)r r'r#r/r)r@rArrr test_valuesz$BasicTestMappingProtocol.test_valuescCrCr)r r'r#r r)r@rArrr test_itemsrEz#BasicTestMappingProtocol.test_itemscCs|}|t|ddSr?)r r'r+rArrr test_lenz!BasicTestMappingProtocol.test_lencCsD|j}||t|jdt|jd|t|jdSr?) rr'r#rr(r/r)r@ __getitem__rArrr test_getitems z%BasicTestMappingProtocol.test_getitemcs|}||j|t|t|j|}|||||}||j|t|t|j|}||j|t|t|j|ttf|jd|Gfddd}| ||t |}t |j }|||Gdddt |}Gfddd}||j|| Gfddd}||j|Gfd dd}||j||}Gfd d d t }||j||t|jd gdS) N*cs(eZdZfddZddZddZdS)z.SimpleUserDictcs j|_dSr)rrr outerselfrr rr<zEBasicTestMappingProtocol.test_update..SimpleUserDict.__init__cS |jSrrr(rrrr r(r<zABasicTestMappingProtocol.test_update..SimpleUserDict.keyscS |j|Srrrirrr rIr<zHBasicTestMappingProtocol.test_update..SimpleUserDict.__getitem__N__name__ __module__ __qualname__rr(rIrrLrr SimpleUserDicts rXc@ eZdZdS)z1BasicTestMappingProtocol.test_update..ExcNrUrVrWrrrr Excrr[ceZdZfddZdS)=BasicTestMappingProtocol.test_update..FailingUserDictcdSrrrr[rr r(r<BBasicTestMappingProtocol.test_update..FailingUserDict.keysN)rUrVrWr(rr_rr FailingUserDictrac eZdZfddZddZdS)r]csGfddd}|S)Ncs(eZdZddZddZfddZdS)UBasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonItercSs d|_dSNrrSrrrr rr<^BasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonIter.__init__cS|Srrrrrr r!r<^BasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonIter.__iter__cs|jrd|_dSdS)Nrarfrr_rr r s^BasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonIter.__next__NrUrVrWrr!r rr_rr BogonIterrmrrrmr_rr r(s r`cSs|Srrrrrrr rIr<IBasicTestMappingProtocol.test_update..FailingUserDict.__getitem__NrUrVrWr(rIrr_rr ras c eZdZddZfddZdS)r]cSsGddd}|S)Nc@$eZdZddZddZddZdS)rdcSstd|_dS)Nrj)ordrSrrrr rr<rgcSrhrrrrrr r!r<ricSs2|jtdkr*t|j}|jd7_|StdS)Nzr)rSruZchrZ StopIteration)rZrtnrrr r s  rkNrlrrrr rmrnrmrrorrr r(s r`cr^rrrpr_rr rIr<rqNrrrr_rr ras crs)z4BasicTestMappingProtocol.test_update..badseqcSrhrrrrrr r!r<z=BasicTestMappingProtocol.test_update..badseq.__iter__c dSrrrr_rr r r<z=BasicTestMappingProtocol.test_update..badseq.__next__NrUrVrWr!r rr_rr badseqryr)r r7rr'r#r r)r@ZAttributeErrorclearZsortedr ExceptionobjectZ ValueError)rrrXZi1Zi2raryr)r[rMr test_updatesB    z$BasicTestMappingProtocol.test_updatecCs|}||t|jddu||t|jddd|j}||t|jddu||t|jddd||t|jdt|j d||t|jddt|j d| t |j| t |jddddS)Nrr) r r"r1r#rr(r'rrr/r)r@rArrr test_gets""""z!BasicTestMappingProtocol.test_getcCs|}|t|jdSr)r r)r@r8rArrr test_setdefaultrHz(BasicTestMappingProtocol.test_setdefaultcCs*|}|t|j|t|jddSNrK)r r)r*rr@rArrr test_popitem sz%BasicTestMappingProtocol.test_popitemcCsz|}t|jd\}}|||<|t|jt|jd| |||| t |d|t|j|dSr?) r r#rr r)r*r9rr(r'r+rrr3Zvrrr test_pop%sz!BasicTestMappingProtocol.test_pop)rUrVrWr r r rrr5r:r;r>rBrDrFrGrJr~rrrrrrrr rs& 0*arc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!S)"TestMappingProtocolcCs@t||||u||jdddddddS)Nrrry)rr;r"r r'r rrrr r;2s z$TestMappingProtocol.test_constructorcCsdt||| ||ddi|t|du|t|ddidudS)NrrFT)rr>r"r rr=rrrr r>7s  zTestMappingProtocol.test_boolcCsft||}|t|g|ddd}|}|d||d||d|dS)Nrrrjbrjrc) rrBr r'r#r(rr,r-)rrr3rrr rB>s   zTestMappingProtocol.test_keyscCs2t||ddi}|t|dgdS)Nrr)rrDrr'r#r/rArrr rDHs zTestMappingProtocol.test_valuescCs2t||ddi}|t|dgdS)Nrrrr)rrFrr'r#r rArrr rFMs zTestMappingProtocol.test_itemscCsv|}|d||d|v|d|v|ddd}|d||d||d||t|jdS)Nrjrrrrr)r r-r"rr,r)r@Z __contains__rArrr test_containsSs    z!TestMappingProtocol.test_containscCs.t||ddd}|t|ddS)Nrrr)rrGrr'r+rArrr rG_s zTestMappingProtocol.test_lencCst||ddd}||dd||ddd|d<d|d<||dd||dd|d=||ddd |t|jdS) Nrrrrjrrr)rjr)rrJrr'r)r@rIrArrr rJds z TestMappingProtocol.test_getitemcCs:|dddd}|||i|t|jddSNrrrr)rr{r'r)r@rArrr test_clearrs zTestMappingProtocol.test_clearcCst||}|ddi|ddi|dddd||dddd|||dddd|}|jdd|jdd|jdddd ||dddd |}|d d g||ddd |}|jd d gddd ||ddd |dd d}||dd dd||dd d ddGddd}|||||dddddS)Nrdrrr)r)r)rrrv)rr)rrrrri)rr)rrrrc@rt)z7TestMappingProtocol.test_update..SimpleUserDictcSsdddd|_dSrrQrrrr rr<z@TestMappingProtocol.test_update..SimpleUserDict.__init__cSrNrrOrrrr r(r<z.SimpleUserDict.keyscSrPrrQrRrrr rIr<zCTestMappingProtocol.test_update..SimpleUserDict.__getitem__NrTrrrr rXrnrX)rr~r r7r'rr r{)rrrXrrr r~ys4    zTestMappingProtocol.test_updatec s ||jddddd|}||d|u||ddddd||ddddd||gidd}|||ddi|tijdGd d d |j}||d d di||d d di||d j|u||d j|u|t|d |uGd d d |j}|d}||ddd| |t j |tt jGdddt Gfddd|j}||jdgGfdddt}||jj|Gfddd|j}||jdgdS)Nabc)rjrr)rrrcss dVdSrerrrrr gr<z,TestMappingProtocol.test_fromkeys..grrc@rY)z3TestMappingProtocol.test_fromkeys..dictlikeNrZrrrr dictlikerrrjc@eZdZddZdS)z1TestMappingProtocol.test_fromkeys..mydictcStSr collectionsUserDictZclsrrr __new__r<z9TestMappingProtocol.test_fromkeys..mydict.__new__NrUrVrWrrrrr mydictrbrabrc@rY)z.TestMappingProtocol.test_fromkeys..ExcNrZrrrr r[rr[cr\)z3TestMappingProtocol.test_fromkeys..baddict1crwrr)rrZkwargsr_rr rr<z.baddict1.__init__N)rUrVrWrrr_rr baddict1rbrcrs)z1TestMappingProtocol.test_fromkeys..BadSeqcSrhrrrrrr r!r<z:TestMappingProtocol.test_fromkeys..BadSeq.__iter__crwrrrr_rr r r<z:TestMappingProtocol.test_fromkeys..BadSeq.__next__Nrxrr_rr BadSeqrzrcr\)z3TestMappingProtocol.test_fromkeys..baddict2crwrr)rrrr_rr __setitem__r<z?TestMappingProtocol.test_fromkeys..baddict2.__setitem__N)rUrVrWrrr_rr baddict2rbr)r'r fromkeysr r"r)r@ __class__ZtypeassertIsInstancerrr&r|r}) rrrrrudrrrrr_r test_fromkeyss6 z!TestMappingProtocol.test_fromkeyscCsh|dddd}||dddd|}||||||j|t|jddSr)rr'rr rrr)r@rArrr test_copys zTestMappingProtocol.test_copycCst||}||ddu||ddd|ddd}||ddu||ddd||dd||ddddS)Nrrrrrrj)rrr r"r1r'rrArrr rs zTestMappingProtocol.test_getcCst||}||ddu|dg||ddu|dgd||ddd|dgd|t|dddS)NZkey0rrrrr)rrr r"r8Zappendr'r+rArrr rs  z#TestMappingProtocol.test_setdefaultc Cst|dD]}tdD]}d|}|}|}t|D]$}||t|<|dkr>||t|<q>|dkrt|}t|D]\}|\}}} ||t||\} } } || t| | |dko| | k q|| | | | qqdS)N)iri rr) rrranger reprrrr'Zintr") rZcopymodeZlog2sizeZsizerjrrSZkaZvaZtaZkbZvbZtbrrr rs(      z TestMappingProtocol.test_popitemcCsNt||}d\}}||||||||<|||d|dS)N)rZdefr)rrr r'r9rrrr r s  zTestMappingProtocol.test_popN)rUrVrWr;r>rBrDrFrrGrJrr~rrrrrrrrrr r1s   ./  rc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)TestHashMappingProtocolcst|GdddtGfdddt}|}d||<|t|jdGfdddt}|}|}d||<d |_||j|dS) Nc@rY)z1TestHashMappingProtocol.test_getitem..ExcNrZrrrr r[rr[crc)z3TestHashMappingProtocol.test_getitem..BadEqcrwrrrrr_rr __eq__r<z:TestHashMappingProtocol.test_getitem..BadEq.__eq__cSdS)Nirrrrr __hash__!r<z.BadEq.__hash__NrUrVrWrrrr_rr BadEq rrKiceZdZdZfddZdS)z5TestHashMappingProtocol.test_getitem..BadHashFc|jrndSdSrr.rr_rr r*z>TestHashMappingProtocol.test_getitem..BadHash.__hash__NrUrVrWr.rrr_rr BadHash(rT) rrJr|r}r r)r*rIr.)rrrrrrr_r rJs  z$TestHashMappingProtocol.test_getitemcCsJt|Gddd|j}|d}||ddd||tjdS)Nc@r)z5TestHashMappingProtocol.test_fromkeys..mydictcSrrrrrrr r9r<z=TestHashMappingProtocol.test_fromkeys..mydict.__new__Nrrrrr r8rbrrr)rrr rr'rrr)rrrrrr r6s   z%TestHashMappingProtocol.test_fromkeyscs^t|GdddtGfdddt}|}|}d||<d|_||j|dS)Nc@rY)z-TestHashMappingProtocol.test_pop..ExcNrZrrrr r[Brr[cr)z1TestHashMappingProtocol.test_pop..BadHashFcrrrrr_rr rFrz:TestHashMappingProtocol.test_pop..BadHash.__hash__Nrrr_rr rDrrrKT)rrr|r}r r.r)r9rrrrrr_r r? z TestHashMappingProtocol.test_popcCs`|}d|d<z8d}|D]*}d||d<|dkr<|d|d7}qWntyZYn0dS)Nrrz7changing dict size during iteration doesn't raise Error)r r.Z RuntimeError)rrZcountrSrrr test_mutatingiterationRs   z.TestHashMappingProtocol.test_mutatingiterationcs|}|t|dd|d<|t|d|}||d<|t|dGdddtGfdd d t}|d|i}|t|dS) Nz{}rrz{1: 2}z {1: {...}}c@rY)z.TestHashMappingProtocol.test_repr..ExcNrZrrrr r[hrr[cr\)z2TestHashMappingProtocol.test_repr..BadReprcrwrrrr_rr __repr__kr<z;TestHashMappingProtocol.test_repr..BadRepr.__repr__N)rUrVrWrrr_rr BadReprjrbr)r r'rr|r}rr))rrrrr_r test_repr_sz!TestHashMappingProtocol.test_reprcCsD|}ttdD]}|}|}||d<q|tt|dS)Nrr)r rsysZgetrecursionlimitr)ZRecursionErrorr)rrrSZd0rrr test_repr_deepqs  z&TestHashMappingProtocol.test_repr_deepcs|||||ddi|ddiGdddtGfdddt|di|ddi|fdd|fd ddS) Nrrc@rY)z,TestHashMappingProtocol.test_eq..ExcNrZrrrr r[~rr[crc)z/TestHashMappingProtocol.test_eq..BadCmpcrwrrrr_rr rr<z6TestHashMappingProtocol.test_eq..BadCmp.__eq__cSrrerrrrr rr<z8TestHashMappingProtocol.test_eq..BadCmp.__hash__Nrrr_rr BadCmprrcs dkSrerr)rrr rrz1TestHashMappingProtocol.test_eq..cskSrrr)d1d2rr rr)r'r rr|r}r)rr)rr[rrr test_eqys zTestHashMappingProtocol.test_eqcs`t|GdddtGfdddt}|}|}d||<d|_||j|gdS)Nc@rY)z4TestHashMappingProtocol.test_setdefault..ExcNrZrrrr r[rr[cr)z8TestHashMappingProtocol.test_setdefault..BadHashFcrrrrr_rr rrzATestHashMappingProtocol.test_setdefault..BadHash.__hash__Nrrr_rr rrrrKT)rrr|r}r r.r)r8rrr_r rrz'TestHashMappingProtocol.test_setdefaultN) rUrVrWrJrrrrrrrrrrr rs  r)rrrrrrrrrrr Zs,h