idwdZddlmZddlZddlZddlmZddlmZddlZddl 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|_|jsrtj d|jtj j }tj |||td|_dSdS)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__)clsospd __class__s C/opt/cloudlinux/venv/lib/python3.11/site-packages/gitdb/test/lib.pyr zTestBase.setUpClass(s  GG       D *..);<< O LCEHEW X X X7?D gll44TT(^^0D0D+E+EvNNCOOO  O Os $ 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#r9r:s` r with_packs_rwrB[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) globhasattrrrrbasenamerHOSErrorr.copy) source_glob target_dirr>src_filetargets rr@r@tsIk** . .  .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)r4dataodatas r make_objectrfs) #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_rbr)rZr[ds rmake_memory_fileris* =),,A q6671:: r#c&eZdZdZdZdZdZdS) DummyStreamc0d|_d|_d|_dS)NFr)was_readbytesclosedr5s r__init__zDummyStream.__init__s   r#c"d|_||_dSNT)rmrn)r5sizes rreadzDummyStream.reads  r#cd|_dSrs)rorps rclosezDummyStream.closes  r#cdSNrps r_assertzDummyStream._assertr#N)rrrrqrurwr{rzr#rrkrksP r#rkceZdZdZdZdS) DeriveTestcH|d|_||_dS)Nmyarg)poprargs)r5shar4rtstreamrkwargss rrqzDeriveTest.__init__s ZZ((  r#cdSryrzrps rr{zDeriveTest._assertr|r#N)rrrrqr{rzr#rr~r~s2r#r~)rC)F)r gitdbrr1rWriorrIunittestr)r.rr,r functoolsrTestCaserr;rBr?r@r_rfrirkr~rzr#rrs $#    00000x 000F<   $IIII . . . .$    ((( $r#