bgwdZddlmZddlZddlZddlmZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZGdde jZd Zd Zdd ZddZddZdZddZGddZGddeZdS)zUtilities used in ODB testing)OStreamN)array)BytesIO)wrapsc6eZdZdZdZefdZxZS)TestBasezBase class for all tests TestCase providing access to readonly repositories using the following member variables. * gitrepopath * read-only base path of the git source repository, i.e. .../git/.git GITDB_TEST_GIT_REPO_BASEc  tn#t$rYnwxYwtj|j|_|jsptj d|jtj j }tj |||td|_|jdsJdS)NzpYou can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repositoryz.git)super setUpClassAttributeErrorosenvirongetk_env_git_repo gitrepopathlogginginfopathdirnamejoin__file__endswith)clsospd __class__s _/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/gitdb/test/lib.pyr zTestBase.setUpClass(s  GG       D *..);<< O LCEHEW X X X7?D gll44TT(^^0D0D+E+EvNNCO''///////s $ 11)__name__ __module__ __qualname____doc__r classmethodr __classcell__)rs@rrrsU0N 0 0 0 0[ 0 0 0 0 0rc*fd}j|_|S)zCreate a temporary directory which can be written to, remove it if the test succeeds, but leave it otherwise to aid additional debuggingc tjj}tj|d} |||s(t jtj|SS#t$rDtj dt|jdjd|dd}wxYw#|s(t jtj|wwxYw)N)prefixFzTest .z failed, output is at  T)tempfilemktemprrmkdirgccollectshutilrmtree Exceptionsysstderrwritetype)selfrkeepfuncs rwrapperz"with_rw_directory..wrapperAsdm444  $ tD$'' $  d#### $      !nd).wrapper_s7$Y// =$TBBBBtD$r$r:r;s` r with_packs_rwrC[s-     }G Nr$ctjtjtd|S)z:return: absolute path into the fixture directory :param relapath: relative path into the fixtures directory, or '' to obtain the fixture directory itselffixtures)rrrrr)relapaths rr@r@ms* 7<<11:x H HHr$Fc~tj|D]}|rttdrytj|tj|} tj||m#t$rtj ||YwxYwtj ||dS)zCopy all files found according to the given source glob into the target directory :param hard_link_ok: if True, hard links will be created if possible. Otherwise the files will be copiedlinkN) globhasattrrrrbasenamerIOSErrorr/copy) source_glob target_dirr?src_filetargets rrArAtsIk** . .  .GB// .W\\*bg.>.>x.H.HIIF 2&)))) 2 2 2 Hj11111 2 K* - - - - . .s,BB$#B$c|dz}t|}|r#t|}tj|t d|}|S)zb:return: string with given size in bytes :param randomize: try to produce a very random streami)rangelistrandomshufflertobytes) size_in_bytes randomize actual_sizeproduceras r make_bytesr`s[ 1$K[!!H!>>x    c8A 99;;r$cVdt|z}|d|zS)z0:return: bytes resembling an uncompressed objectzblob %iascii)lenencode)r5dataodatas r make_objectrgs) #d)) #E << 4 ''r$c^t||}t|t|fS)z`:return: tuple(size_of_stream, stream) :param randomize: try to produce a very random stream)r`rcr)r[r\ds rmake_memory_filerjs* =),,A q6671:: r$c&eZdZdZdZdZdZdS) DummyStreamc0d|_d|_d|_dS)NFr)was_readbytesclosedr6s r__init__zDummyStream.__init__s   r$c"d|_||_dSNT)rnro)r6sizes rreadzDummyStream.reads  r$cd|_dSrt)rprqs rclosezDummyStream.closes  r$c|jsJdSN)rnrqs r_assertzDummyStream._asserts}}r$N)rrr rrrvrxr{r$rrlrlsP r$rlceZdZdZdZdS) DeriveTestcH|d|_||_dS)Nmyarg)poprargs)r6shar5rustreamrkwargss rrrzDeriveTest.__init__s ZZ((  r$c*|jsJ|jsJdSrz)rrrqs rr{zDeriveTest._asserts"yyzzr$N)rrr rrr{r|r$rr~r~s2r$r~)rD)F)r!gitdbrr2rXriorrJunittestr*r/rr-r functoolsrTestCaserr<rCr@rAr`rgrjrlr~r|r$rrs $#    00000x 000F<   $IIII . . . .$    ((( $r$