f _WW@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.2Zvalue1)1Zkey1Zkey2selfr r +/usr/lib64/python3.10/test/mapping_tests.py _referencesz#BasicTestMappingProtocol._referencecCs|S)zReturn an empty mapping object) type2testr r r r _empty_mappingsz'BasicTestMappingProtocol._empty_mappingcCs&|}|D]\}}|||<q|S)zKReturn a mapping object with the value contained in data dictionary)ritems)r dataxkeyvaluer r r _full_mappings z&BasicTestMappingProtocol._full_mappingcOsftjj|g|Ri|||_|j\}}||i|_|j\}}||i|_||j|<dSN) unittestTestCase__init__r copy referencepopitemother inmapping)r argskwrrr r r 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)NrcsSrr r )dknownkeyr r 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__) assertTruehasattrlistset)iterZlstrefrr r r check_iterandlistHsz=BasicTestMappingProtocol.test_read..check_iterandlist)rdictrrr assertEqualr)rkeys assertRaisesKeyErrorlenassertIn assertNotInZassertNotEqualfailr+valuesnextget)r pZp1rrkr- knownvaluer )r!r"r r 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)NcsSrr r rr:r r r#dr$z5BasicTestMappingProtocol.test_write..i)rrrr/r0r1r2updater.r)rr8r+r setdefaultpopr5r)r rrr!r"r<defaultr r>r test_write[sD        z#BasicTestMappingProtocol.test_writecCs|||dSr)r/rr r r r test_constructorsz)BasicTestMappingProtocol.test_constructorcCsJ|| ||j|t|du|t|jdudS)NFT)r'rrboolr r r r test_bools z"BasicTestMappingProtocol.test_boolcCsr|}|t|g|j}|t|jd||t|jd|| t |jddSNr) rr/r)r0rr4rr5rr1 TypeErrorr r!r r r test_keyss z"BasicTestMappingProtocol.test_keyscCs0|}|t|g|t|jddSr)rr/r)r7r1rHrIr r r test_valuessz$BasicTestMappingProtocol.test_valuescCs0|}|t|g|t|jddSr)rr/r)rr1rHrIr r r test_itemssz#BasicTestMappingProtocol.test_itemscCs|}|t|ddSrG)rr/r3rIr r r test_lensz!BasicTestMappingProtocol.test_lencCsD|j}||t|jdt|jd|t|jdSrG) rr/r)rr0r7r1rH __getitem__rIr r r 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)rr!r  outerselfr r rszEBasicTestMappingProtocol.test_update..SimpleUserDict.__init__cSs |jSrr!r0r r r r r0szABasicTestMappingProtocol.test_update..SimpleUserDict.keyscSs |j|Srr!r ir r r rNszHBasicTestMappingProtocol.test_update..SimpleUserDict.__getitem__N__name__ __module__ __qualname__rr0rNr rQr r SimpleUserDicts r[c@s eZdZdS)z1BasicTestMappingProtocol.test_update..ExcNrXrYrZr r r r Excr$r]cseZdZfddZdS)=BasicTestMappingProtocol.test_update..FailingUserDictcsdSrr r r]r r r0sBBasicTestMappingProtocol.test_update..FailingUserDict.keysN)rXrYrZr0r r_r r FailingUserDictsracs eZdZfddZddZdS)r^csGfddd}|S)Ncs(eZdZddZddZfddZdS)UBasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonItercSs d|_dSNrrVr r r r rs^BasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonIter.__init__cSs|Srr r r r r r&s^BasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonIter.__iter__cs|jrd|_dSdS)Nrardr r_r r r%s^BasicTestMappingProtocol.test_update..FailingUserDict.keys..BogonIter.__next__NrXrYrZrr&r%r r_r r BogonItersrjr r rjr_r r r0s r`cSs|Srr r rr r r rNsIBasicTestMappingProtocol.test_update..FailingUserDict.__getitem__NrXrYrZr0rNr r_r r ras cs eZdZddZfddZdS)r^cSsGddd}|S)Nc@s$eZdZddZddZddZdS)rbcSstd|_dS)Nrg)ordrVr r r r rsrecSs|Srr r r r r r&srfcSs2|jtdkr*t|j}|jd7_|StdS)Nzr)rVrochr StopIteration)r Zrtnr r r r%s  rhNrir r r r rjsrjr rkr r r r0s r`csdSrr rlr_r r rNsrmNrnr r_r r ras cs eZdZddZfddZdS)z4BasicTestMappingProtocol.test_update..badseqcSs|Srr r r r r r&sz=BasicTestMappingProtocol.test_update..badseq.__iter__cs dSrr r r_r r r%sz=BasicTestMappingProtocol.test_update..badseq.__next__NrXrYrZr&r%r r_r r badseqsrtr)rr?rr/r)rr1rHAttributeErrorclearsortedr Exceptionobject ValueError)r r!r[Zi1Zi2rartr )r]rRr 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) rr'r9r)rr0r/rrr7r1rHrIr r r test_gets""""z!BasicTestMappingProtocol.test_getcCs|}|t|jdSr)rr1rHr@rIr r r test_setdefaultsz(BasicTestMappingProtocol.test_setdefaultcCs*|}|t|j|t|jddSNrP)rr1r2rrHrIr r r test_popitem sz%BasicTestMappingProtocol.test_popitemcCsz|}t|jd\}}|||<|t|jt|jd| |||| t |d|t|j|dSrG) rr)rrr1r2rArr0r/r3r r!r;vr r r test_pop%sz!BasicTestMappingProtocol.test_pop)rXrYrZrr rrrr=rCrDrFrJrKrLrMrOr{r|r}rrr r r r rs& 0*arc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!S)"TestMappingProtocolcCs@t||||u||jdddddddS)Nrrry)rrDr'rr/rr r r r rD2s z$TestMappingProtocol.test_constructorcCsdt||| ||ddi|t|du|t|ddidudS)NrrFT)rrFr'rrrEr r r r rF7s  zTestMappingProtocol.test_boolcCsft||}|t|g|ddd}|}|d||d||d|dS)Nrrrgbrgrc) rrJrr/r)r0rr4r5)r r!r;r r r rJ>s   zTestMappingProtocol.test_keyscCs2t||ddi}|t|dgdS)Nrr)rrKrr/r)r7rIr r r rKHs zTestMappingProtocol.test_valuescCs2t||ddi}|t|dgdS)Nrrrr)rrLrr/r)rrIr r r rLMs zTestMappingProtocol.test_itemscCsv|}|d||d|v|d|v|ddd}|d||d||d||t|jdS)Nrgrrrrr)rr5r'rr4r1rH __contains__rIr r r test_containsSs    z!TestMappingProtocol.test_containscCs.t||ddd}|t|ddS)Nrrr)rrMrr/r3rIr r r rM_s zTestMappingProtocol.test_lencCst||ddd}||dd||ddd|d<d|d<||dd||dd|d=||ddd |t|jdS) Nrrrrgrrr)rgr)rrOrr/r1rHrNrIr r r rOds z TestMappingProtocol.test_getitemcCs:|dddd}|||i|t|jddSNrrrr)rrvr/r1rHrIr r r 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)rrrp)rr)rrrrr)rr)rrrrc@s$eZdZddZddZddZdS)z7TestMappingProtocol.test_update..SimpleUserDictcSsdddd|_dSrrTr r r r rsz@TestMappingProtocol.test_update..SimpleUserDict.__init__cSs |jSrrSr r r r r0sz.SimpleUserDict.keyscSs |j|SrrTrUr r r rNszCTestMappingProtocol.test_update..SimpleUserDict.__getitem__NrWr r r r r[sr[)rr{rr?r/rrrv)r r!r[r r r 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)rgrr)rrrcss dVdSrcr r r r r gsz,TestMappingProtocol.test_fromkeys..grrc@s eZdZdS)z3TestMappingProtocol.test_fromkeys..dictlikeNr\r r r r dictliker$rrgc@seZdZddZdS)z1TestMappingProtocol.test_fromkeys..mydictcSstSr collectionsUserDictclsr r r __new__sz9TestMappingProtocol.test_fromkeys..mydict.__new__NrXrYrZrr r r r mydictsrabrc@s eZdZdS)z.TestMappingProtocol.test_fromkeys..ExcNr\r r r r r]r$r]cseZdZfddZdS)z3TestMappingProtocol.test_fromkeys..baddict1cs dSrr )r rkwargsr_r r rsz.baddict1.__init__N)rXrYrZrr r_r r baddict1srcs eZdZddZfddZdS)z1TestMappingProtocol.test_fromkeys..BadSeqcSs|Srr r r r r r&sz:TestMappingProtocol.test_fromkeys..BadSeq.__iter__cs dSrr r r_r r r%sz:TestMappingProtocol.test_fromkeys..BadSeq.__next__Nrsr r_r r BadSeqsrcseZdZfddZdS)z3TestMappingProtocol.test_fromkeys..baddict2cs dSrr )r rrr_r r __setitem__sz?TestMappingProtocol.test_fromkeys..baddict2.__setitem__N)rXrYrZrr r_r r baddict2sr)r/rfromkeysrr'r1rH __class__typeassertIsInstancerrr.rxry) r r!rrrudrrrr r_r test_fromkeyss6 z!TestMappingProtocol.test_fromkeyscCsh|dddd}||dddd|}||||||j|t|jddSr)rr/rrrrr1rHrIr r r test_copys zTestMappingProtocol.test_copycCst||}||ddu||ddd|ddd}||ddu||ddd||dd||ddddS)Nrrrrrrg)rr|rr'r9r/rrIr r r r|s zTestMappingProtocol.test_getcCst||}||ddu|dg||ddu|dgd||ddd|dgd|t|dddS)NZkey0rrrrr)rr}rr'r@appendr/r3rIr r r r}s  z#TestMappingProtocol.test_setdefaultc Cst|dD]}tdD]}d|}|}|}t|D]$}||t|<|dkr>||t|<q>|dkrt|}t|D]\}|\}}} ||t||\} } } || t| | |dko| | k q|| | | | qqdS)N)r rr) rrrangerreprrrr/intr') r copymodeZlog2sizesizergrrVkavataZkbZvbtbr r r rs(      z TestMappingProtocol.test_popitemcCsNt||}d\}}||||||||<|||d|dS)N)rdefr)rrrr/rArr r r r s  zTestMappingProtocol.test_popN)rXrYrZrDrFrJrKrLrrMrOrr{rrr|r}rrr r r r r1s   ./  rc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)TestHashMappingProtocolcst|GdddtGfdddt}|}d||<|t|jdGfdddt}|}|}d||<d |_||j|dS) Nc@s eZdZdS)z1TestHashMappingProtocol.test_getitem..ExcNr\r r r r r]r$r]cs eZdZfddZddZdS)z3TestHashMappingProtocol.test_getitem..BadEqcs dSrr r rr_r r __eq__sz:TestHashMappingProtocol.test_getitem..BadEq.__eq__cSsdS)Nr r r r r __hash__!sz.BadEq.__hash__NrXrYrZrrr r_r r BadEqs rrPcseZdZdZfddZdS)z5TestHashMappingProtocol.test_getitem..BadHashFcs|jrndSdSr~r6r r_r r r*sz>TestHashMappingProtocol.test_getitem..BadHash.__hash__NrXrYrZr6rr r_r r BadHash(srT) rrOrxryrr1r2rNr6)r rr!rrr r_r rOs  z$TestHashMappingProtocol.test_getitemcCsJt|Gddd|j}|d}||ddd||tjdS)Nc@seZdZddZdS)z5TestHashMappingProtocol.test_fromkeys..mydictcSstSrrrr r r r9sz=TestHashMappingProtocol.test_fromkeys..mydict.__new__Nrr r r r r8srrr)rrrrr/rrr)r rrr r r r6s   z%TestHashMappingProtocol.test_fromkeyscs^t|GdddtGfdddt}|}|}d||<d|_||j|dS)Nc@s eZdZdS)z-TestHashMappingProtocol.test_pop..ExcNr\r r r r r]Br$r]cseZdZdZfddZdS)z1TestHashMappingProtocol.test_pop..BadHashFcs|jrndSdSr~rr r_r r rFsz:TestHashMappingProtocol.test_pop..BadHash.__hash__Nrr r_r r rDsrrPT)rrrxryrr6r1rAr rr!rr r_r r?s z TestHashMappingProtocol.test_popcCs`|}d|d<z8d}|D]*}d||d<|dkr<|d|d7}qWntyZYn0dS)Nrrz7changing dict size during iteration doesn't raise Error)rr6 RuntimeError)r r!countrVr r r 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@s eZdZdS)z.TestHashMappingProtocol.test_repr..ExcNr\r r r r r]hr$r]cseZdZfddZdS)z2TestHashMappingProtocol.test_repr..BadReprcs dSrr r r_r r __repr__ksz;TestHashMappingProtocol.test_repr..BadRepr.__repr__N)rXrYrZrr r_r r BadReprjsr)rr/rrxryrr1)r r!rr r_r test_repr_sz!TestHashMappingProtocol.test_reprcCsD|}ttdD]}|}|}||d<q|tt|dS)Nrr)rrsysgetrecursionlimitr1RecursionErrorr)r r!rVZd0r r r test_repr_deepqs  z&TestHashMappingProtocol.test_repr_deepcs|||||ddi|ddiGdddtGfdddt|di|ddi|fdd|fd ddS) Nrrc@s eZdZdS)z,TestHashMappingProtocol.test_eq..ExcNr\r r r r r]~r$r]cs eZdZfddZddZdS)z/TestHashMappingProtocol.test_eq..BadCmpcs dSrr rr_r r rsz6TestHashMappingProtocol.test_eq..BadCmp.__eq__cSsdSrcr r r r r rsz8TestHashMappingProtocol.test_eq..BadCmp.__hash__Nrr r_r r BadCmps rcs dkSrcr r )rr r r#r$z1TestHashMappingProtocol.test_eq..cskSrr r )d1d2r r r#r$)r/rrrxryr1r r )rr]rrr test_eqys zTestHashMappingProtocol.test_eqcs`t|GdddtGfdddt}|}|}d||<d|_||j|gdS)Nc@s eZdZdS)z4TestHashMappingProtocol.test_setdefault..ExcNr\r r r r r]r$r]cseZdZdZfddZdS)z8TestHashMappingProtocol.test_setdefault..BadHashFcs|jrndSdSr~rr r_r r rszATestHashMappingProtocol.test_setdefault..BadHash.__hash__Nrr r_r r rsrrPT)rr}rxryrr6r1r@rr r_r r}s z'TestHashMappingProtocol.test_setdefaultN) rXrYrZrOrrrrrrr}r r r r rs  r)rrrrrrrr r r r s,h