Ë
    ómxiq  ã                   ó  — d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ  G d„ de	j"                  «      Zd	„ Zd
„ Zdd„Zdd„Zdd„Zd„ Zdd„Z G d„ d«      Z G d„ de«      Zy)zUtilities used in ODB testingé    )ÚOStreamN)Úarray)ÚBytesIO)Úwrapsc                   ó0   ‡ — e Zd ZdZdZeˆ fd„«       Zˆ xZS )ÚTestBasezÚBase 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           	      óÚ  •— 	 t         ‰| �  «        t        j                  j                  | j                  «      | _        | j                  sut        j                  d| j                  «       t        j                  j                  }t        j                  j                   | | |t        «      «      «      d«      | _        | j                  j                  d«      sJ ‚y # t        $ r Y ŒØw xY w)NzpYou can set the %s environment variable to a .git repository of your choice - defaulting to the gitdb repositoryz.git)ÚsuperÚ
setUpClassÚAttributeErrorÚosÚenvironÚgetÚk_env_git_repoÚgitrepopathÚloggingÚinfoÚpathÚdirnameÚjoinÚ__file__Úendswith)ÚclsÚospdÚ	__class__s     €úE/home/htdocs/ttos/venv/lib/python3.12/site-packages/gitdb/test/lib.pyr   zTestBase.setUpClass(   s»   ø€ ð	Ü‰GÑÔ ô Ÿ*™*Ÿ.™.¨×);Ñ);Ó<ˆŒØ�ŠÜ�L‰Lð Cð  EH÷  EWñ  EWôXä—7‘7—?‘?ˆDÜ Ÿg™gŸl™l©4±±T¼(³^Ó0DÓ+EÀvÓNˆCŒOà�‰×'Ñ'¨Ô/Ð/Ñ/øô ò 	Ùð	ús   ƒC Ã	C*Ã)C*)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   Ú__classcell__)r   s   @r   r   r      s#   ø„ ñð 0€Nð ó0ó ô0ó    r   c                 ó4   ‡ — ˆ fd„}‰ j                   |_         |S )zŒCreate a temporary directory which can be written to, remove it if the
    test succeeds, but leave it otherwise to aid additional debuggingc           
      óî  •— t        j                  ‰j                  ¬«      }t        j                  |«       d}	 	  ‰| |«      |s*t        j                  «        t        j                  |«       S S # t        $ rJ t        j                  j                  dt        | «      j                  › d‰j                  › d|›d�«       d}‚ w xY w# |s*t        j                  «        t        j                  |«       w w xY w)N)ÚprefixFzTest ú.z failed, output is at ú
T)ÚtempfileÚmktempr   r   ÚmkdirÚgcÚcollectÚshutilÚrmtreeÚ	ExceptionÚsysÚstderrÚwriteÚtype)Úselfr   ÚkeepÚfuncs      €r   Úwrapperz"with_rw_directory.<locals>.wrapperA   sË   ø€ Ü�‰ d§m¡mÔ4ˆÜ
�‰�ŒØˆð	$ðÙ˜D $Ó'ñ Ü—
‘
”Ü—‘˜dÕ#ð øô ò Ü—
‘
× Ñ  5¬¨d«×)<Ñ)<Ð(=¸Q¸t¿}¹}¸oÐMcÐdhÐckÐkmÐ!nÔoØ�Øðûñ Ü—
‘
”Ü—‘˜dÕ#ð ús   »A0 Á0ACÃC Ã.C4©r   ©r8   r9   s   ` r   Úwith_rw_directoryr<   =   s   ø€ ô$ð, —}‘}€GÔØ€Nr$   c                 ó4   ‡ — ˆ fd„}‰ j                   |_         |S )zŒFunction that provides a path into which the packs for testing should be
    copied. Will pass on the path to the actual function afterwardsc                 óH   •— t        d«      }t        ||d¬«        ‰| |«      S )Nzpacks/*T)Úhard_link_ok)Úfixture_pathÚcopy_files_globbed)r6   r   Úsrc_pack_globr8   s      €r   r9   zwith_packs_rw.<locals>.wrapper_   s&   ø€ Ü$ YÓ/ˆÜ˜=¨$¸TÕBÙ�D˜$ÓÐr$   r:   r;   s   ` r   Úwith_packs_rwrC   [   s   ø€ ô ð —}‘}€GÔØ€Nr$   c                 ó†   — t         j                  j                  t         j                  j                  t        «      d| «      S )z¦:return: absolute path into the fixture directory
    :param relapath: relative path into the fixtures directory, or ''
        to obtain the fixture directory itselfÚfixtures)r   r   r   r   r   )Úrelapaths    r   r@   r@   m   s(   € ô �7‰7�<‰<œŸ™Ÿ™¬Ó1°:¸xÓHÐHr$   c                 ó|  — t        j                   | «      D ]  }|ret        t        d«      rUt        j                  j	                  |t        j                  j                  |«      «      }	 t        j                  ||«       Œjt        j                  ||«       Œ� y# t        $ r t        j                  ||«       Y Œ¤w xY w)zÆCopy 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 copiedÚlinkN)
ÚglobÚhasattrr   r   r   ÚbasenamerH   ÚOSErrorr/   Úcopy)Úsource_globÚ
target_dirr?   Úsrc_fileÚtargets        r   rA   rA   t   s�   € ô —I‘I˜kÓ*ò 	.ˆÙœG¤B¨Ô/Ü—W‘W—\‘\ *¬b¯g©g×.>Ñ.>¸xÓ.HÓIˆFð2Ü—‘˜ &Õ)ô
 �K‰K˜ *Õ-ñ	.øô
 ò 2Ü—‘˜H jÖ1ð2ús   Á)BÂB;Â:B;c                 óž   — | dz  }t        |«      }|r t        |«      }t        j                  |«       t	        d|«      }|j                  «       S )zb:return: string with given size in bytes
    :param randomize: try to produce a very random streamé   Úi)ÚrangeÚlistÚrandomÚshuffler   Útobytes)Úsize_in_bytesÚ	randomizeÚactual_sizeÚproducerÚas        r   Ú
make_bytesr_   †   sH   € ð   1Ñ$€KÜ�[Ó!€HÙÜ˜“>ˆÜ�‰�xÔ äˆc�8Ó€AØ�9‰9‹;Ðr$   c                 óF   — dt        |«      z  }|j                  d«      |z   S )z0:return: bytes resembling an uncompressed objectzblob %i Úascii)ÚlenÚencode)r5   ÚdataÚodatas      r   Úmake_objectrf   “   s$   € àœ#˜d›)Ñ#€EØ�<‰<˜Ó  4Ñ'Ð'r$   c                 óF   — t        | |«      }t        |«      t        |«      fS )z`:return: tuple(size_of_stream, stream)
    :param randomize: try to produce a very random stream)r_   rb   r   )rZ   r[   Úds      r   Úmake_memory_fileri   ™   s#   € ô 	�= )Ó,€AÜˆq‹6”7˜1“:ÐÐr$   c                   ó$   — e Zd Zd„ Zd„ Zd„ Zd„ Zy)ÚDummyStreamc                 ó.   — d| _         d| _        d| _        y )NFr   )Úwas_readÚbytesÚclosed©r6   s    r   Ú__init__zDummyStream.__init__¦   s   € ØˆŒØˆŒ
Øˆ�r$   c                 ó    — d| _         || _        y ©NT)rm   rn   )r6   Úsizes     r   ÚreadzDummyStream.read«   s   € ØˆŒØˆ�
r$   c                 ó   — d| _         y rs   )ro   rp   s    r   ÚclosezDummyStream.close¯   s	   € Øˆ�r$   c                 ó    — | j                   sJ ‚y ©N)rm   rp   s    r   Ú_assertzDummyStream._assert²   s   € Ø�}Š}Ð‰}r$   N)r   r   r    rq   ru   rw   rz   © r$   r   rk   rk   ¤   s   „ òò
òór$   rk   c                   ó   — e Zd Zd„ Zd„ Zy)Ú
DeriveTestc                 ó>   — |j                  d«      | _        || _        y )NÚmyarg)Úpopr   Úargs)r6   Úshar5   rt   Ústreamr�   Úkwargss          r   rq   zDeriveTest.__init__¸   s   € Ø—Z‘Z Ó(ˆŒ
Øˆ�	r$   c                 ó<   — | j                   sJ ‚| j                  sJ ‚y ry   )r�   r   rp   s    r   rz   zDeriveTest._assert¼   s   € Ø�yŠyÐˆyØ�zŠzÐ‰zr$   N)r   r   r    rq   rz   r{   r$   r   r}   r}   ¶   s   „ òór$   r}   )Ú )F)r!   Úgitdbr   r2   rW   r   Úior   rI   Úunittestr*   r/   r   r-   r   Ú	functoolsr   ÚTestCaser   r<   rC   r@   rA   r_   rf   ri   rk   r}   r{   r$   r   ú<module>rŒ      s~   ðñ
 $Ý ã 
Û Ý å ã Û Û Û Û 	Û 	Û Ý ô
0ˆx× Ñ ô 0òFò<ó$Ió.ó$
ò(ó÷ñ ô$�õ r$   