o ]Lb@sddlmZddlZddlmZmZddlmZddlm Z m Z ddl m Z ddl mZGd d d ejZGd d d eZGd ddeZGdddeZddZddZddZdS))absolute_importN)hexnullrev)getattr)errormdiff) repository) storageutilc@s&eZdZeejddsejjZdSdS) basetestcaseassertRaisesRegexFN)__name__ __module__ __qualname__runittestTestCaseassertRaisesRegexpr rr;/usr/lib/python3/dist-packages/mercurial/testing/storage.pyr s r c@s0eZdZdZddZddZddZdd Zd S) ifileindextestszGeneric tests for the ifileindex interface. All file storage backends for index data should conform to the tests in this class. Use ``makeifileindextests()`` to create an instance of this type. c Cs|}|t|dd|t|gdt|}|t t|Wdn1s.wY|| d|| d|| t || |j || d|| d|t| gt| }|t t|Wdn1swY|t|j ddg|| |j |j |j f||t t t f|tj | dWdn1swYtd d D]!}|t krq|t ||Wdn1swYq|||j t ||t |j |tj |dWdn 1swYtd d D]%}|t kr2q)|t ||Wdn 1sHwYq)|||j |j ||t |j ||t|j |j ||d t |j |tj |d Wdn 1swY|tj|t|j dd Wdn 1swY|tj |dWdn 1swY|tj |dWdn 1swY|tj |dWdn 1s wY|tj |dWdn 1s'wYtd d D]%}|t kr:q1|t ||Wdn 1sPwYq1||t t td d D]%}|t krnqe|t ||Wdn 1swYqe||t td d D]%}|t krq|t ||Wdn 1swYq|t||j |j g|t|t|ggWdn 1swY|t|t gg|||j g|||j |j g||d|j g|j g|||j |j g|j g|||j g|tj|dWddS1sNwYdS)Nrs&new file store has 0 length by defaultsiter yields nothing by default0saaaaaaaaaaaaaaaaaaaastart%dsbadvalue -21s&11111111111111111111111111111111111111) _makefilefn assertEquallenlistiter assertRaises StopIterationnext assertFalsehasnodernullidrevsparents parentrevsr LookupErrorrange IndexErrorrevnodelookuprlinkrev iscensoredcommonancestorsheads ValueError descendantsheadschildren)selffgenr,irrr testempty)s                            $zifileindextests.testemptyc Cs|}|}|dd|d|j|j}Wdn1swY|t|d|t|dgt|}|t|d| t  t|Wdn1sUwY| | || | t|| | t| | |j| | |dd| | t|dd|t|dg|t|jddg|t|jdddg|t|jdddg|t|jdddg|t|ddg|t|ddddg|t|ddgd ||||j|jf||dttf| tj |d Wdn 1s,wY| t |dWdn 1sGwY|||d| tj |d Wdn 1slwY||d|| t |dWdn 1swY||||||d|||d |j||d |||t||| tj|t|ddWdn 1swY| tj |d Wdn 1swY| tj |dWdn 1swY| tj |dWdn 1s6wY| tj |dWdn 1sRwY||dd| t |dWdn 1svwY| |d| t |dWdn 1swY|t|dgg|||g||||g||j|gd|g| tj|jd gdWdn 1swY|||gdS)NinitialrrrrstoprrrBrrrrr )r!_maketransactionfnaddr+r"r#r$r%r(r&r' assertTruer*r)rrr,r-r.rr/r1r2r3r4r5r6r9r:r;)r<r=trr3r>rrrtestsinglerevisions                 z"ifileindextests.testsinglerevisionc Csd}|d}d|d}|}|*}||d|d|j|j}||d|d||j}||d|d||j}Wdn1sAwY|t|d|t|gdt|} |t| d|t| d|t| d| t  t| Wdn1swY|t| gd|t| dgd|t| dddg|t| ddg|t| dg|t|j dd ddg|t|j dd gd|t|j dd gd|t| ddgd |t| ddddg|t| ddddg|| ||j|jf|| |||jf|| |||jf|| dttf|| ddtf|| ddtf|||d|||d|||d| tj |d Wdn 1swY||d|||d|||d|| t |dWdn 1swY||||||d|||d |||t||||||||d|||d |||t||||dd||dd||dd| t |dWdn 1sNwY||d||d||d| t |dWdn 1swY||||jg|||||g|||||g|||||g|||||g|||||g|t|dgddg|t|dgdg|t|ddgddg|||g||||g||||g||||g||j|gd ||g||j|gd ||g||j||gd ||g| tj|jd gd Wdn 1sZwY||||g||||g|||gdS)Nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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|d |t|dggd|t|dgdg|t|dgg|t|dgd g|t|ddggd|t|ddgdd g|||||g||||||g||||g||||g||||g||||g||||g||j|gd||||g||j|gd||||g|| ||||g|| ||g|| |g|| ||g|| |g|| |gdS)Nrrr rB2r3rP45r)rBrrPr\rrC) r!rHrIr+r"r#r$r9r:r;) r<r=rKrUrVrWnode3node4node5rrrtestmultipleheadsjs> z!ifileindextests.testmultipleheadsN)r rr__doc__r@rLrXrbrrrrr s v\ orc@sheZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)ifiledatatestszGeneric tests for the ifiledata interface. All file storage backends for data should conform to the tests in this class. Use ``makeifiledatatests()`` to create an instance of this type. c Cs|}||i||jdddddd||tdtddD]!}|tkr/q(|t ||Wdn1sDwYq(|||j d|| |j d|t j  |dWdn1stwY|| |j d|t j  | dWdn1swY|||j |t j  | dWdn1swY|||j d|||j d |t j |dd Wdn1swY|g}|t t|Wdn 1s wY||j g}|t t|Wdn 1s-wY|t j t|dgWddS1sMwYdS) NTrevisionscount trackedsizersrevisionscounts trackedsizerrrfoo irrelevant)r!r" storageinfosizerr0r&r1revisionr+rawdatarr/readr)renamedrJcmp emitrevisionsr'r(r$)r<r=r?r>rrrr@sV           $zifiledatatests.testemptyc Csd}|}|}||d|d|j|j}Wdn1s!wY||i||jddddt|d||dt||t  |dWdn1s^wY|| |||| |||| ||| ||| |||||||d||g}t|}||j|||j|j||j|j||j||j|j||j||j ||j|t t|Wdn1swY|j|gdd}t|}||j|||j|j||j|j||j||j|j||j||j |||j|t t|Wdn 1sMwY|tjt||d gWddS1snwYdS) NrArTrerBrhsextra revisiondatar)r!rHrIr+r"rlr#rmr&r1rnrorpr)rqrrrJrsr(r3p1nodep2node assertIsNonelinknodebasenodebaserevisionsizedeltar'rr/r$)r<fulltextr=rKr3r>r2rrrrLsb                 $z!ifiledatatests.testsinglerevisionc Csp d}|d}d|d}|}|*}||d|d|j|j}||d|d||j}||d|d||j}Wdn1sAwY||i||jddddt|t|t|d ||dt|||dt|||d t||t  |dWdn1swY|| |||| |||| |||| |||| |||| |||t j  | d Wdn1swY|||||||||||||t j  |d Wdn 1s$wY||||||||||t j  |d Wdn 1sXwY|||||||||||||||||||||t j |d d Wdn 1swY|j|||gdd } t| } || j||| j|j|| j|j|| j|| j|j|| j|| j ||| jt| } || j||| j||| j|j|| j|| j||| j|| j || jd|t| } || j||| j||| j|j|| j|| j||| j|| j || jd||t t| Wdn 1szwY|j|||gdd } t| } || j||| j|j|| j|j|| j|| j|j|| j|| j ||| jt| } || j||| j||| j|j|| j|| j||| j|| j || jd|t| } || j||| j||| j|j|| j|| j||| j|| j || jd||t t| Wdn 1sRwY|t jt|jgddWdn 1srwYt|j|||gdd} |t| d|dd| D|||h|j||gddd} t| } || j||| j||| j|j|| j|j|| j|| j ||| jt| } || j||| j|j|| j|j|t t| Wdn 1swY|j||hdd } t| } || j||| j||| j|j|| j|j|| j|| j ||| jt| } || j||| j||| j|j|| j||| j|| j || jd||t t| Wdn 1swY|j||gddd} t| } || j||| j||| j|j|| j||| j|| j || jd||j|gdt j!d} t| } || j||| j|j|| j|j|| j|j|| j|| j || jd||t t| Wdn 1s2wY|j||gdt j!d} t| } || j||| j|j|| j|j|| j|j|| j|| j || jd|t| } || j||| j||| j|j|| j||t t| WddS1swYdS)NrMrNrOrrBrPTrerhrrrkrts s sbad) nodesordersstoragecSsh|]}|jqSrr3).0orrr sz7ifiledatatests.testmultiplerevisions..snodes)r~ru)ruassumehaveparentrevisions)ru deltamodes )"r!rHrIr+r"rlr#rmr&r1rnrorr/rpr)rqrrrJrsr(r3rvrwrxryrzr{r|r'ProgrammingErrorr$r CG_DELTAMODE_PREV) r<rRrSrTr=rKrUrVrWr>r2resrrrrXs                                                      $z$ifiledatatests.testmultiplerevisionsc Csd}d}d}ddd}ddd}d d d |g}d d d |g}|}|+} ||d| d|j|j} |||| d| |j} |||| d|j|j} Wdn1sVwY||dt|||dt|||| ||| | |||| ||| | ||| | ||| | || | | || | d| || || || || || || || |dS)Nrjbarsbazsource0s(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaascopyscopyrevsource1(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbri copy: source0 s4copyrev: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  s copy: source1 s4copyrev: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb  rrBr)r)joinr!rHrIr+r"rmr#rnrorpr)rqrJrr) r<rRrSrTmeta1meta2stored1stored2r=rKrUrVrWrrr testrenamed*sR zifiledatatests.testrenamedc Csrd}d}d}ddd}ddd dd g}|}| }||i|d |j|j}||||d |j|j} Wdn1s@wY||d t|d ||d t||||||| ||||| ||| | ||| |||| | || | ||| | ||| | | || | | |dS)Ns foos    foos barrrrrirs copyrev: %s s  barrrBr\)rr!rHrIr+r"rmr#rnrorpr)rrrJ) r<rRstored0rSrrr=rKrUrVrrrtestmetadataprefixds: z!ifiledatatests.testmetadataprefixc CsB|}d}|d}|#}||d|d|j|j}d}|j|||||jd|dWdn1s4wY|t|d|||||jf|t j  | |Wdn1scwY|t j  | |Wdn1s~wY|t j | |WddS1swYdS)Nxfoo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo bar rrBrawtextr)r!rHrIr+_addrawrevisionfnr"r#r-r&r StorageErrorrnrorpr<r=rRrSrKrUrVrrrtestbadnodereads*    "zifiledatatests.testbadnodereadc C|}d}|d}|#}||d|d|j|j}d}|j|||||jd|dWdn1s4wY|tj ||Wdn1sOwY|tj||WddS1skwYdSNrrrrrBr) r!rHrIr+rr&rrrorrrrtestbadnoderevisionraw    "z%ifiledatatests.testbadnoderevisionrawc Crr) r!rHrIr+rr&rrrprrrrtestbadnoderevisionrz"ifiledatatests.testbadnoderevisionc Cs8|}d}|d}|d}|#}||d|d|j|j}d}|j|||||jd|dWdn1s8wY|tj ||Wdn1sSwYt |||j}|}t ||} |j|||||jdd| fd Wdn1swY| t|d | |||dS) N|foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo rsbaz rrrBrr)r|rP)r!rHrIr+rr&rrrpr hashrevisionsha1rtextdiffr"r#) r<r=rRrSrTrKrUrVrWr|rrrtestbadnodedeltas.    zifiledatatests.testbadnodedeltac Cs0|}tddid}|$}|dd|d|j|j}d}|j|||||jd|dd Wdn1s7wY||d| t j  | dWdn1sZwY| t j  | dWdn1suwY| t j |dWddS1swYdS Ncensored tombstonerirjrrrBTcensored)r!r packmetarHrIr+rrJr6r&rCensoredNodeErrorrnrorpr<r=rrKrUrVrrr testcensoreds.     "zifiledatatests.testcensoredc Cs|}tddid}|$}|dd|d|j|j}d}|j|||||jd|dd Wdn1s7wY|tj | dWddS1sSwYdSr) r!r rrHrIr+rr&rrrorrrrtestcensoredrawrevisions   "z&ifiledatatests.testcensoredrawrevisionN)r rrrcr@rLrXrrrrrrrrrrrrrds6@:+! rdc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZdS)ifilemutationtestszGeneric tests for the ifilemutation interface. All file storage backends that support writing should conform to this interface. Use ``makeifilemutationtests()`` to create an instance of this type. c Cs|}|,}|dd|d|j|j}|dd|d|j|j}|dd|d|j|j}Wdn1s7wY|||||||t|ddS)NrjrrB)r!rHrIr+r"r#r<r=rKrUrVrWrrr testaddnoop?s   zifilemutationtests.testaddnoopc Cs|}|4}|tj|jd|d|j|jddWdn1s'wYWddSWddS1s?wYdS)Nrjrrr)r!rHr&rr addrevisionr+r<r=rKrrrtestaddrevisionbadnodeKs "z)ifilemutationtests.testaddrevisionbadnodec Cs|}|K}tdddD]}d|>tj@rd|>}nq|tj|jd|d|j |j |dWdn1s>wYWddSWddS1sVwYdS)NrrFrBrj)flags) r!rHr0r REVISION_FLAGS_KNOWNr&rrrr+)r<r=rKr?rrrrtestaddrevisionunknownflagTs "z-ifilemutationtests.testaddrevisionunknownflagc s|}gfdddd}|!}gfdd}fdd}|jgd|||d Wdn1s8wY|g|g|t|d d }tt||}|}||d|d |j|j}Wdn1swwY|}||j|j|j|j|d ifg} |!}gfd d}fd d}|j| ||||d Wdn1swY|dg|td|d d dd |t | d g|| d d || d d dS)Ncs||fdSN)append)argskwargs) callbackargsrrcbdsz1ifilemutationtests.testaddgroupsimple..cbcSdSNrrrrrr linkmappergsz9ifilemutationtests.testaddgroupsimple..linkmapperc"||}|||dSrr3rclr2r3rnodesrr onchangesetm  z:ifilemutationtests.testaddgroupsimple..onchangesetc||dSrrr3rr2rrrondupchangesetrz=ifilemutationtests.testaddgroupsimple..ondupchangeset addrevisioncbduplicaterevisioncbrrjcrrrrrrrrrcrrrrrrrrrsI˱\WGkFzyrB) r!rHaddgroupr"r#rtrivialdiffheaderrIr+r$r,r2r3) r<r=rrKrrrRdelta0rUdeltasr)rrrrtestaddgroupsimple_sb        z%ifilemutationtests.testaddgroupsimplec s|}gd}g}|}|D]}|||d|d|j|jqWdn1s-wY|}g}t|D] \}}tt||}||||j|j|j|j|difq<|"}gfdd} |j |dd|| | d| |Wdn1swY| t|t|| t | gd| | |dd| | |d d | | |d d | |d|d| |d |d | |d |d dS) N)rjrrMrcrrrrnewnodesrrrrz.onchangesetcSrrrxrrrz9ifilemutationtests.testaddgroupmultiple..rrQrBr)r!rHrrIr+ enumeraterrr#rr"r$r,r2r3) r<r= fulltextsrrKr}rr?r|rrrrtestaddgroupmultiplesF    z'ifilemutationtests.testaddgroupmultiplec Cs|}tddid}|$}|dd|d|j|j}d}|j|||||jd|dd Wdn1s7wYtd d }d ||jd ||difg}|0}| t j | |dd|Wdn1smwYWddSWddS1swYdS)NrrrirrrrBTrsxbar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar s|bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar baz srcSrrrrrrrrrz=ifilemutationtests.testdeltaagainstcensored..) r!r rrHrIr+rrrr&rCensoredBaseErrorr)r<r=rrKrUrVr|rrrrtestdeltaagainstcensoreds.   "z+ifilemutationtests.testdeltaagainstcensoredc Cs0|}|*}|dd|d|j|j}|dd|d||j}|dd|d||j}Wdn1s5wY|}|||Wdn1sOwY|t|d|t|gd|| |d|| |d| t j | |WddS1swYdS) NrrrrBsfoo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo rrPrQ) r!rHrIr+censorrevisionr"r#r$r,rpr&rrrrrrtestcensorrevisionbasics    "z*ifilemutationtests.testcensorrevisionbasicc Cs|}|}tdD]}|d|d|||j|jq Wdn1s(wYtdD]}||||tfq1dSN r)r!rHr0rIr+r" getstrippointset)r<r=rKr2rrrtestgetstrippointnoparentss   z-ifilemutationtests.testgetstrippointnoparentsc Cs|}|}|j}tdD]}|d|d||||jqWdn1s*wYtdD]}||||tfq3dSr)r!rHr+r0rIr"rrr<r=rKp1r2rrrtestgetstrippointlinears   z*ifilemutationtests.testgetstrippointlinearc Cs|}|@}|dd|d|j|j}|dd|d||j}|dd|d||j|dd|d||j|d d|d ||jWdn1sKwYtd D]}||||tfqTdS) Nrrr rBrYrrZrPr[r\r)r!rHrIr+r0r"rr)r<r=rKrUrVr2rrrtestgetstrippointmultipleheads(s  z1ifilemutationtests.testgetstrippointmultipleheadsc Cs|}|*}|dd|d|j|j}|dd|d||j|dd|d||jWdn1s5wY||ddtf||ddtf||ddtf||d dtf||d dtf||ddtf||d ddhf||d ddhf||d ddhf||dddhf||dddhf||dd tfdS)Nrrr rrYrrBrrPr\r^ )r!rHrIr+r"rr)r<r=rKrUrrr testgetstrippointearlierlinkrevs5s$ z3ifilemutationtests.testgetstrippointearlierlinkrevscCsP|}|}|d|Wdn1swY|t|ddSr)r!rHstripr"r#rrrrteststripemptyJs  z!ifilemutationtests.teststripemptyc Cs|}|}|j}tdD]}|d|d||||j}qWdn1s*wY|t|d|}|d|Wdn1sLwY|t|ddS)Nrrr)r!rHr+r0rIr"r#rrrrr teststripallRs   zifilemutationtests.teststripallc Cs |}|,}|dd|d|j|j|dd|d|j|j}|dd|d|j|j}Wdn1s7wY|t|d|}|d|Wdn1sYwY|t|d|}|d|Wdn1s{wY|t|d |tj  | |Wdn1swY|}|d |Wdn1swY|t|d |}|d|Wdn1swY|t|d |tj | |WddS1swYdS) Nrrr rrYrrPrrr^rB) r!rHrIr+r"r#rr&rr/r2)r<r=rKrVrWrrrteststrippartialas:       "z#ifilemutationtests.teststrippartialN)r rrrcrrrrrrrrrrrrrrrrrrr6s    P/    rcC|||d}tdtf|S)a9Create a unittest.TestCase class suitable for testing file storage. ``makefilefn`` is a callable which receives the test case as an argument and returns an object implementing the ``ifilestorage`` interface. ``maketransactionfn`` is a callable which receives the test case as an argument and returns a transaction object. ``addrawrevisionfn`` is a callable which receives arguments describing a low-level revision to add. This callable allows the insertion of potentially bad data into the store in order to facilitate testing. Returns a type that is a ``unittest.TestCase`` that can be used for testing the object implementing the file storage interface. Simply assign the returned value to a module-level attribute and a test loader should find and run it automatically. r!rHrr)typer makefilefnmaketransactionfnaddrawrevisionfndrrrmakeifileindextestss rcCr)Nrrd)rrdrrrrmakeifiledatatests rcCr)Nrr)rrrrrrmakeifilemutationtestsrr) __future__rrr3rrpycompatrrr interfacesr utilsr rr rrdrrrrrrrrs.    t)R