
    .Phq                        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dS )zUtilities used in ODB testing    )OStreamN)array)BytesIO)wrapsc                   6     e Zd ZdZdZe fd            Z xZS )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           	         	 t                                                       n# t          $ r Y nw xY wt          j                            | j                  | _        | j        spt          j	        d| j                   t          j
        j        }t          j
                             | | |t                                        d          | _        | j                            d          sJ d S )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     N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/gitdb/test/lib.pyr   zTestBase.setUpClass(   s    	GG     	 	 	D	 *..);<< 	OL C  EH  EWX X X7?D gll44TT(^^0D0D+E+EvNNCO''///////s    $ 
11)__name__
__module____qualname____doc__r   classmethodr   __classcell__)r   s   @r   r   r      sU          0N 0 0 0 0 [0 0 0 0 0    r   c                 *      fd} 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           
         t          j        j                  }t          j        |           d}	 	  | |          |s(t          j                     t          j        |           S S # t          $ rD t          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   dm444
	$tD$''  $
d####$    
  !nd)<!n!nt}!n!ndh!n!n!nooo  $
d####$s   A* *AB88B; ;,C'r   r8   r9   s   ` r   with_rw_directoryr<   =   s-    $ $ $ $ $, }GNr$   c                 *      fd} j         |_         |S )zFunction that provides a path into which the packs for testing should be
    copied. Will pass on the path to the actual function afterwardsc                 ^    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_   s7    $Y//=$TBBBBtD$r$   r:   r;   s   ` r   with_packs_rwrC   [   s-              }GNr$    c                     t           j                            t           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<<11:xHHHr$   Fc                 ~   t          j         |           D ]}|rt          t          d          ryt          j                            |t          j                            |                    }	 t          j        ||           m# t          $ r t          j	        ||           Y w xY wt          j	        ||           dS )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 copiedlinkN)
globhasattrr   r   r   basenamerI   OSErrorr/   copy)source_glob
target_dirr?   src_filetargets        r   rA   rA   t   s     Ik** 	. 	. 	.GB// 	.W\\*bg.>.>x.H.HIIF2&)))) 2 2 2Hj111112 K*----	. 	.s   ,BB$#B$c                     | dz  }t          |          }|r#t          |          }t          j        |           t	          d|          }|                                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`      s[      1$K[!!H !>>x   c8A99;;r$   c                 V    dt          |          z  }|                    d          |z   S )z0:return: bytes resembling an uncompressed objectzblob %i ascii)lenencode)r5   dataodatas      r   make_objectrg      s)    #d))#E<<  4''r$   c                 ^    t          | |          }t          |          t          |          fS )z`:return: tuple(size_of_stream, stream)
    :param randomize: try to produce a very random stream)r`   rc   r   )r[   r\   ds      r   make_memory_filerj      s*     	=),,Aq6671::r$   c                   &    e Zd Zd Zd Zd Zd ZdS )DummyStreamc                 0    d| _         d| _        d| _        d S )NFr   )was_readbytesclosedr6   s    r   __init__zDummyStream.__init__   s    
r$   c                 "    d| _         || _        d S NT)rn   ro   )r6   sizes     r   readzDummyStream.read   s    


r$   c                     d| _         d S rt   )rp   rq   s    r   closezDummyStream.close   s    r$   c                     | j         sJ d S N)rn   rq   s    r   _assertzDummyStream._assert   s    }r$   N)r   r   r    rr   rv   rx   r{    r$   r   rl   rl      sP          
        r$   rl   c                       e Zd Zd Zd ZdS )
DeriveTestc                 H    |                     d          | _        || _        d S )Nmyarg)popr   args)r6   shar5   ru   streamr   kwargss          r   rr   zDeriveTest.__init__   s     ZZ((
			r$   c                 *    | j         sJ | j        sJ d S rz   )r   r   rq   s    r   r{   zDeriveTest._assert   s$    yzr$   N)r   r   r    rr   r{   r|   r$   r   r~   r~      s2              r$   r~   )rD   )F)r!   gitdbr   r2   rX   r   ior   rJ   unittestr*   r/   r   r-   r   	functoolsr   TestCaser   r<   rC   r@   rA   r`   rg   rj   rl   r~   r|   r$   r   <module>r      s  
 $ #       



                  				 				       
0 0 0 0 0x  0 0 0F  <  $I I I I. . . .$
 
 
 
( ( (          $         r$   