
    gq                        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 )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        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     C/var/www/openai/venv/lib/python3.12/site-packages/gitdb/test/lib.pyr   zTestBase.setUpClass(   s    	G  **..););<LL C  EH  EW  EWX77??D ggll4T(^0D+EvNCO''///  		s   C 	C*)C*)__name__
__module____qualname____doc__r   classmethodr   __classcell__)r   s   @r   r   r      s#     0N 0 0    r   c                 4      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        $ 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    dmm4
	$D$' 

d#   

  5d)<)<(=Qt}}oMcdhckkm!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 )zFunction 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(     77<<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)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   basenamerH   OSErrorr/   copy)source_glob
target_dirr?   src_filetargets        r   rA   rA   t   s     IIk*GB/WW\\*bgg.>.>x.HIF2&)
 KK*- +
  2Hj12s   )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 c8A99;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q671: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    ZZ(
	r$   c                 <    | j                   sJ | j                  sJ y ry   )r   r   rp   s    r   rz   zDeriveTest._assert   s    yyyzz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~   
 $  
        	 	  
0x   0F<$I.$
( $ r$   