
    #Cc`                        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 ZddZddZddZd ZddZ G d de          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          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)superr	   
setUpClassAttributeErrorosenvirongetk_env_git_repogitrepopathlogginginfopathdirnamejoin__file__endswith)clsospd	__class__s     .lib/python3.11/site-packages/gitdb/test/lib.pyr   zTestBase.setUpClass(   s    	(C  ++---- 	 	 	D	 *..);<< 	OL C  EH  EWX X X7?D gll44TT(^^0D0D+E+EvNNCO''///////s   '+ 
88)__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                 <     t                      fd            }|S )zAll tests decorated with this one will raise SkipTest when run on travis ci.
    Use it to workaround difficult to solve issues
    NOTE: copied from bcore (https://github.com/Byron/bcore)c                 j    dt           j        v rdd l}|                    d           | g|R i |S )NTRAVISr   zCannot run on travis-ci)r   r   noseSkipTest)selfargskwargsr)   funcs       r   wrapperz"skip_on_travis_ci.<locals>.wrapperA   sL    rz!!KKK-- 9:::tD*4***6***r%   r   r.   r/   s   ` r   skip_on_travis_cir1   =   s5     4[[+ + + + [+ Nr%   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          $ rO t          j                            d                    t          |           j        j        |                     d} w xY w# |s(t          j                     t          j        |           w w xY w)N)prefixFz%Test {}.{} failed, output is at {!r}
T)tempfilemktempr   r   mkdirgccollectshutilrmtree	Exceptionsysstderrwriteformattype)r+   r   keepr.   s      r   r/   z"with_rw_directory.<locals>.wrapperP   s    dm444
	$tD$''  $
d####$    
  !I!P!PQUVZQ[Q[Qdfjfsuy!z!z{{{  $
d####$s   A* *ACC ,C2r   r0   s   ` r   with_rw_directoryrD   L   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)r+   r   src_pack_globr.   s      r   r/   zwith_packs_rw.<locals>.wrappern   s7    $Y//=$TBBBBtD$r%   rC   r0   s   ` r   with_packs_rwrK   j   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   rH   rH   |   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   basenamerQ   OSErrorr:   copy)source_glob
target_dirrG   src_filetargets        r   rI   rI      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_bytesrh      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)rA   dataodatas      r   make_objectro      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)rh   rk   r   )rc   rd   ds      r   make_memory_filerr      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r+   s    r   __init__zDummyStream.__init__   s    
r%   c                 "    d| _         || _        d S NT)rv   rw   )r+   sizes     r   readzDummyStream.read   s    


r%   c                     d| _         d S r|   )rx   ry   s    r   closezDummyStream.close   s    r%   c                     | j         sJ d S N)rv   ry   s    r   _assertzDummyStream._assert   s    }r%   N)r   r    r!   rz   r~   r   r    r%   r   rt   rt      sP          
        r%   rt   c                       e Zd Zd Zd ZdS )
DeriveTestc                 H    |                     d          | _        || _        d S )Nmyarg)popr   r,   )r+   sharA   r}   streamr,   r-   s          r   rz   zDeriveTest.__init__   s     ZZ((
			r%   c                 *    | j         sJ | j        sJ d S r   )r,   r   ry   s    r   r   zDeriveTest._assert   s$    yzr%   N)r   r    r!   rz   r   r   r%   r   r   r      s2              r%   r   )rL   )F)r"   gitdbr   r=   r`   r   ior   rR   unittestr5   r:   r   r8   r   	functoolsr   TestCaser	   r1   rD   rK   rH   rI   rh   ro   rr   objectrt   r   r   r%   r   <module>r      s  
 $ #       



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