U
    uiq                     @  s   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
 d dlmZ d dlZd dlmZ d dlmZ d dlmZmZmZ d dlmZ d	d
lmZmZ d	dlmZ G dd deZejdd Z G dd dZ!G dd dZ"dS )    )annotationsN)Path)mock)path)errors)egg_infomanifest_makerwrite_entries)Distribution   )contextsenvironment)DALSc                   @  s   e Zd ZdS )EnvironmentN)__name__
__module____qualname__ r   r   B/tmp/pip-unpacked-wheel-9osl9suo/setuptools/tests/test_egg_info.pyr      s   r   c               	   #  s   t jddv t } t tj d}t fdd|D | _t	t
tj| j  t| jd dtd| j ii | V  W 5 Q R X d S )	Nzsetuptools-test.)prefix)homelibscriptsdatazegg-basec                 3  s    | ]}|t j |fV  qd S )N)osr   join).0dirnameZenv_dirr   r   	<genexpr>"   s     zenv.<locals>.<genexpr>r   z.pydistutils.cfgzT
                [egg_info]
                egg-base = %(egg-base)s
                )r   tempdirr   r   chmodstatS_IRWXUdictpathslistmapmkdirvaluesr   buildr   )envsubsr   r   r   r+      s"     r+   c                   @  sD  e Zd ZedZdd ZedddddZd	d
 Zedd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdddZdjejd dZdjejd dZd ZG d!d" d"Zejd#d$d%d&d'd(d)d*d+d,d-eeed.d/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zej d;ed<d=d>d?fed@d=d>dfedAd=d>d?fed<dBd=dCd?fej!edDd=d>d?dEdFgdGdH Z"ej dIedJdKdLdMdNdOgg fedPdKdLdMdNdOgg fedQdKdLdMdNgdOgfedRdKdLdMg dNdOgfedSdKdLdMdOgdNgfedTd=dUdNgdVgfedAd=d>dWgg fedXdBd=dCdWgg fedJdYdKdLdZdNdOgg fej!d[dKd\d]d^dLd_d`dadNdbdcdddedWgdfgdgdFej!edhdKdidjdNgdkgdldFej!edmdKdUdNgg dndFgdodp Z#ej dIedqdKdLdMg dNdOgfedrdKdLdMg dNdOgfedsdKdtdLdudNdvdOgg fedwdKdtdLdudNdvdOgg fedxdKdtdLdudNdOgdvgfedsd=dydvgdNdOgfedzd{dKdtdLd|dNdvdOgg fej!ed}dKdidjdNgdkgdldFej!ed~dKd]d^ddNdcgddgddFg	dd Z$dd Z%dd Z&dd Z'dd Z(dd Z)dd Z*dd Z+dd Z,dd Z-dd Z.dddZ/dd Z0dS )TestEggInfoz
        from setuptools import setup

        setup(
            name='foo',
            py_modules=['hello'],
            entry_points={'console_scripts': ['hi = hello.run']},
            zip_safe=False,
        )
        c                 C  s   t | jtdd d S )NzO
                def run():
                    print('hello')
                )setup.pyzhello.py)r   r*   setup_scriptr   )selfr   r   r   _create_project@   s    zTestEggInfo._create_projectz	list[str]ztuple[int, int])pkg_info_linesreturnc                 C  s6   | d  dd }tt| dd d \}}||fS )Nr    r   .   )splitr'   int)r2   version_strmajorminorr   r   r   _extract_mv_versionK   s    zTestEggInfo._extract_mv_versionc           	   	   C  s   t j|jd d}t }t|}|  || t|ddd}|	 }W 5 Q R X d|ksbt
d|ksnt
d|kszt
d	}| || d
S )z
        When the egg_info section is empty or not present, running
        save_version_info should add the settings to the setup.cfg
        in a deterministic order.
        r   	setup.cfgrutf-8encoding
[egg_info]tag_build =tag_date = 0Z	tag_buildZtag_dateN)r   r   r   r%   r
   r   initialize_optionssave_version_infoopenreadAssertionError_validate_content_order	r0   
tmpdir_cwdr+   Z	setup_cfgdisteifcontentZexpected_orderr   r   r   +test_egg_info_save_version_info_setup_emptyQ   s    
z7TestEggInfo.test_egg_info_save_version_info_setup_emptyc                 C  s,   d |}tjtjB }t|| |s(tdS )zY
        Assert that the strings in expected appear in content
        in order.
        z.*N)r   re	MULTILINEDOTALLsearchrJ   )rQ   expectedpatternflagsr   r   r   rK   k   s    
z#TestEggInfo._validate_content_orderc           	   	   C  s   t j|jd d}t|tdi t }t|}|  |	| t
|ddd}| }W 5 Q R X d|ksttd|kstd	|kstd
}| || dS )z
        When running save_version_info on an existing setup.cfg
        with the 'default' values present from a previous run,
        the file should remain unchanged.
        r   r=   zU
            [egg_info]
            tag_build =
            tag_date = 0
            r>   r?   r@   rB   rC   rD   rE   N)r   r   r   r%   r*   r   r
   r   rF   rG   rH   rI   rJ   rK   rL   r   r   r   .test_egg_info_save_version_info_setup_defaultsu   s$     	
z:TestEggInfo.test_egg_info_save_version_info_setup_defaultsc                 C  sB   |    | || td}ddddddg}t||ks>td S )Nfoo.egg-infoPKG-INFOSOURCES.txtzdependency_links.txtentry_points.txtznot-zip-safeztop_level.txt)r1   _run_egg_info_commandr   listdirsortedrJ   )r0   rM   r+   actualrW   r   r   r   test_expected_files_produced   s    
z(TestEggInfo.test_expected_files_producedc           	      C  s   t  }t|}tjdtdd}tjdd d}|H |8 dd l}d}tj|jj	|d |
  W 5 Q R X W 5 Q R X W 5 Q R X d S )	Nzos.utimeZTEST)Zside_effectz+setuptools.command.egg_info.egg_info.mkpath)
return_valr   z,Cannot update time stamp of directory 'None'match)r
   r   r   patchOSErrordistutils.errorspytestraisesr   DistutilsFileErrorrun)	r0   rM   r+   rN   rO   Zutime_patchZmkpath_patch	distutilsmsgr   r   r   test_handling_utime_error   s     z%TestEggInfo.test_handling_utime_errorc              	   C  sZ   t d}t d}t||d tt}| || W 5 Q R X d|jjd ksVtd S )Nzp
            [metadata]
            name=foo
            version=0.0.1
            license=file:MIT
            zK
            from setuptools import setup

            setup()
            r.   r=   
ValueErrorr   )	r   r   r*   rj   rk   rJ   r_   valueargs)r0   rM   r+   setup_configr/   excr   r   r   test_license_is_a_string   s    	z$TestEggInfo.test_license_is_a_stringc                 C  sR   |    | || tjd}td | || tjd}||ksNtdS )z9Ensure timestamps are updated when the command is re-run.r[   gMbP?N)r1   r_   r   r   getmtimetimesleeprJ   )r0   rM   r+   Ztimestamp_aZtimestamp_br   r   r   test_rebuilt   s    
zTestEggInfo.test_rebuiltc              	   C  sz   |    ttdddid | || tjdd}tj|d}t|dd	}d
| 	dkslt
W 5 Q R X d S )Nz:
                recursive-include docs *.rst
            z	usage.rstzRun 'hi')MANIFEST.inZdocsr5   r[   r]   r?   r@   zdocs/usage.rst
r1   r   r*   r   r_   r   r   rH   rI   r7   rJ   )r0   rM   r+   egg_info_dirZsources_txtrP   r   r   r   test_manifest_template_is_read   s     
z*TestEggInfo.test_manifest_template_is_readFc                 C  s4   t d|rdn| }|r|nd}t||d d S )Nzi
            from setuptools import setup

            setup(name='foo', zip_safe=False, %s)
             rq   )r   r   r*   )r0   requiresuse_setup_cfgr/   ru   r   r   r   _setup_script_with_requires   s    
z'TestEggInfo._setup_script_with_requireszpython_version<'{this_ver}'r   )Zthis_verzpython_version < "{this_ver}"z<=>++c                   @  s   e Zd Zedd ZdS )zTestEggInfo.RequiresTestHelperc                    s   g }g }| D ]}|  dd}|dd}t|dkrT|d  }t|}ni }|d  }	 fdd|D \}
}}|	|
df|	d	 |d
ffD ]P\}}}|| d}|dr|dd  }t	j
j}|t	j|||||d qqt	j
jd||dS )Nz

   r   r}   r   c                   s   g | ]}t |jf  qS r   )r   format)r   aformat_dictr   r   
<listcomp>  s    z>TestEggInfo.RequiresTestHelper.parametrize.<locals>.<listcomp>FZ_in_setup_cfgTr   z@xfail
   )marksz;requires,use_setup_cfg,expected_requires,install_cmd_kwargs)ids)lstripr7   poplenstripastliteral_evalappend
startswithrj   markZxfailparamparametrize)Z	test_listr   ZidlistZ	argvaluestestZtest_paramsZname_kwargsvalinstall_cmd_kwargsnameZsetup_py_requiresZsetup_cfg_requiresexpected_requiresZid_r   Zuse_cfgr   r   r   r   r     sF    


	z*TestEggInfo.RequiresTestHelper.parametrizeN)r   r   r   staticmethodr   r   r   r   r   RequiresTestHelper  s   r   z
        install_requires_deterministic

        install_requires=["wheel>=0.5", "pytest"]

        [options]
        install_requires =
            wheel>=0.5
            pytest

        wheel>=0.5
        pytest
        z
        install_requires_ordered

        install_requires=["pytest>=3.0.2,!=10.9999"]

        [options]
        install_requires =
            pytest>=3.0.2,!=10.9999

        pytest!=10.9999,>=3.0.2
        z
        install_requires_with_marker

        install_requires=["barbazquux;{mismatch_marker}"],

        [options]
        install_requires =
            barbazquux; {mismatch_marker}

        [:{mismatch_marker_alternate}]
        barbazquux
        z
        install_requires_with_extra
        {'cmd': ['egg_info']}

        install_requires=["barbazquux [test]"],

        [options]
        install_requires =
            barbazquux [test]

        barbazquux[test]
        a  
        install_requires_with_extra_and_marker

        install_requires=["barbazquux [test]; {mismatch_marker}"],

        [options]
        install_requires =
            barbazquux [test]; {mismatch_marker}

        [:{mismatch_marker_alternate}]
        barbazquux[test]
        z
        setup_requires_with_markers

        setup_requires=["barbazquux;{mismatch_marker}"],

        [options]
        setup_requires =
            barbazquux; {mismatch_marker}

        z
        extras_require_with_extra
        {'cmd': ['egg_info']}

        extras_require={{"extra": ["barbazquux [test]"]}},

        [options.extras_require]
        extra = barbazquux [test]

        [extra]
        barbazquux[test]
        aF  
        extras_require_with_extra_and_marker_in_req

        extras_require={{"extra": ["barbazquux [test]; {mismatch_marker}"]}},

        [options.extras_require]
        extra =
            barbazquux [test]; {mismatch_marker}

        [extra]

        [extra:{mismatch_marker_alternate}]
        barbazquux[test]
        z
        extras_require_with_marker

        extras_require={{":{mismatch_marker}": ["barbazquux"]}},

        @xfail
        [options.extras_require]
        :{mismatch_marker} = barbazquux

        [:{mismatch_marker}]
        barbazquux
        a(  
        extras_require_with_marker_in_req

        extras_require={{"extra": ["barbazquux; {mismatch_marker}"]}},

        [options.extras_require]
        extra =
            barbazquux; {mismatch_marker}

        [extra]

        [extra:{mismatch_marker_alternate}]
        barbazquux
        z
        extras_require_with_empty_section

        extras_require={{"empty": []}},

        [options.extras_require]
        empty =

        [empty]
        )invalid_markermismatch_markermismatch_marker_alternatec              	   C  s   |  || | j||f| tjdd}tj|d}tj|rft|dd}	|	 }
W 5 Q R X nd}
|
 |kszt	t

tj|jd dg kst	d S )	Nr5   r[   zrequires.txtr?   r@   r   r   barbazquux*)r   r_   r   r   r   existsrH   rI   r   rJ   globr%   )r0   rM   r+   r   r   r   r   r   Zrequires_txtfpZinstall_requiresr   r   r   test_requires9  s     zTestEggInfo.test_requiresc              	   C  s4   d}|  | tt | || W 5 Q R X dS )z
        Packages that pass unordered install_requires sequences
        should be rejected as they produce non-deterministic
        builds. See #458.
        z0install_requires={"fake-factory==0.5.2", "pytz"}N)r   rj   rk   rJ   r_   )r0   rM   r+   reqr   r   r   *test_install_requires_unordered_disallowed  s    
z6TestEggInfo.test_install_requires_unordered_disallowedc              	   C  sd   d}|j | jd}| | tt | || W 5 Q R X ttj	
|jd dg ks`td S )Nz/extras_require={{":{marker}": ["barbazquux"]}},markerr   r   r   r   r   rj   rk   rJ   r_   r   r   r   r   r%   r0   rM   r+   tmplr   r   r   r   'test_extras_require_with_invalid_marker  s    
z3TestEggInfo.test_extras_require_with_invalid_markerc              	   C  sd   d}|j | jd}| | tt | || W 5 Q R X ttj	
|jd dg ks`td S )Nz5extras_require={{"extra": ["barbazquux; {marker}"]}},r   r   r   r   r   r   r   r   .test_extras_require_with_invalid_marker_in_req  s    
z:TestEggInfo.test_extras_require_with_invalid_marker_in_reqc           	   	   C  s   |  d tj j|jd d}tjdgtj	|jd t
|gd|d\}}tj	dd	}ttj	|d
dd}| d}W 5 Q R X d|kstd|kstd S )Nz*extras_require={"foobar": ["barbazquux"]},r   HOMEr   r   r   cmdpypathdata_streamr+   r5   r[   r\   r?   r@   r}   zProvides-Extra: foobarMetadata-Version: 2.1r   r   environcopyupdater%   r   run_setup_pypathsepr   strr   rH   rI   r7   rJ   	r0   rM   r+   r   coder   r   r   r2   r   r   r   test_provides_extra  s    


zTestEggInfo.test_provides_extrac              	   C  s   |  d tj j|jd d}tjdgtj	|jd t
|gd|d tj	dd	}ttj	|d
dd}| }W 5 Q R X d|kstd S )Nz0install_requires=["spam ; python_version<'3.6'"]r   r   r   r   r   r   r5   r[   r\   r?   r@   zProvides-Extra:)r   r   r   r   r   r%   r   r   r   r   r   r   rH   rI   rJ   )r0   rM   r+   r   r   r   Zpkg_info_textr   r   r   test_doesnt_provides_extra  s     
z&TestEggInfo.test_doesnt_provides_extrazfiles, license_in_sourcesz}
                              [metadata]
                              license_file = LICENSE
                              zTest license)r=   LICENSETz
                              [metadata]
                              license_file = INVALID_LICENSE
                              z
                              zexclude LICENSE)r=   r|   r   z
                              [metadata]
                              license_file = LICEN[CS]E*
                              Zglob_pattern)idc                 C  s   |    t| tjdgtj|jd t	|gd tjdd}t
|djdd}|rjd	|kstnd	|ksvtd
|kstd S )Nr   r   r   r   r5   r[   r]   r?   r@   r   INVALID_LICENSE)r1   r   r*   r   r   r   r   r   r%   r   r   	read_textrJ   )r0   rM   r+   filesZlicense_in_sourcesr   sources_textr   r   r   test_setup_cfg_license_file!  s    B
z'TestEggInfo.test_setup_cfg_license_filez#files, incl_licenses, excl_licensesz
                              [metadata]
                              license_files =
                                  LICENSE-ABC
                                  LICENSE-XYZ
                              ABC licenseXYZ license)r=   LICENSE-ABCLICENSE-XYZr   r   z
                              [metadata]
                              license_files = LICENSE-ABC, LICENSE-XYZ
                              z
                              [metadata]
                              license_files =
                                  LICENSE-ABC
                              zv
                              [metadata]
                              license_files =
                              z
                              [metadata]
                              license_files = LICENSE-XYZ
                              z
                              [metadata]
                              license_files =
                                  LICENSE-ABC
                                  INVALID_LICENSE
                              )r=   r   r   r   z~
                              [metadata]
                              license_files = LICENSE
                              zexclude LICENSE-XYZ)r=   r|   r   r   r   zABC copyingz
ABC noticezABC authorsZLicensezInvalid license)r=   r   COPYING-ABC
NOTICE-ABCAUTHORS-ABCLICENCE-XYZr   INVALID-LICENSEr   r   r   r   r   Zdefault_glob_patternsz
                              [metadata]
                              license_files =
                                  LICENSE*
                              z
XYZ notice)r=   r   
NOTICE-XYZr   Zno_default_glob_patternsz
                              [metadata]
                              license_files =
                                  LICENSE-ABC
                                  LICENSE*
                              Zfiles_only_added_oncec           
      C  s   |    t| tjdgtj|jd t	|gd tjdd}t
|djdd}d	d
 | D }|D ]}	||	dksntqn|D ]}	||	dkstqd S )Nr   r   r   r5   r[   r]   r?   r@   c                 S  s   g | ]}|  qS r   r   r   liner   r   r   r   A  s     z<TestEggInfo.test_setup_cfg_license_files.<locals>.<listcomp>r   r   r1   r   r*   r   r   r   r   r   r%   r   r   r   
splitlinescountrJ   
r0   rM   r+   r   Zincl_licensesZexcl_licensesr   r   Zsources_lineslfr   r   r   test_setup_cfg_license_filesu  s     C
z(TestEggInfo.test_setup_cfg_license_filesz
                              [metadata]
                              license_file =
                              license_files =
                              z
                              [metadata]
                              license_file =
                                  LICENSE-ABC
                                  LICENSE-XYZ
                              a  
                              [metadata]
                              license_file = LICENSE-ABC
                              license_files =
                                  LICENSE-XYZ
                                  LICENSE-PQR
                              zPQR license)r=   r   LICENSE-PQRr   r   a9  
                              [metadata]
                              license_file = LICENSE-ABC
                              license_files =
                                  LICENSE-ABC
                                  LICENSE-XYZ
                                  LICENSE-PQR
                              z
                              [metadata]
                              license_file = LICENSE-ABC
                              license_files =
                                  LICENSE-XYZ
                              )r=   r   a  
                              [metadata]
                              license_file = LICENSE-ABC
                              license_files =
                                LICENSE-PQR
                                LICENSE-XYZ
                              z'exclude LICENSE-ABC
exclude LICENSE-PQR)r=   r|   r   r   r   z~
                              [metadata]
                              license_file = LICENSE*
                              z
                              [metadata]
                              license_file = LICENSE*
                              license_files =
                                NOTICE*
                              )r=   r   r   r   Zcombined_glob_patterrnsc           
      C  s   |    t| tjdgtj|jd t	|gd tjdd}t
|djdd}d	d
 | D }|D ]}	||	dksntqn|D ]}	||	dkstqd S )Nr   r   r   r5   r[   r]   r?   r@   c                 S  s   g | ]}|  qS r   r   r   r   r   r   r     s     zITestEggInfo.test_setup_cfg_license_file_license_files.<locals>.<listcomp>r   r   r   r   r   r   r   )test_setup_cfg_license_file_license_filesI  s     '
z5TestEggInfo.test_setup_cfg_license_file_license_filesc              	   C  s   |    ttdddddd tjdgtj|j	d t
|gd	 tjd
d}ttj|ddd}| d}W 5 Q R X dd |D }d|d kstd|dd kstd|dd kstdS )zCAll matched license files should have a corresponding License-File.z
                              [metadata]
                              license_files =
                                  NOTICE*
                                  LICENSE*
                              r   r   Zincludedznot include)r=   r   r   ZNOTICEZIGNOREr   r   r   r5   r[   r\   r?   r@   r}   c                 S  s   g | ]}| d r|qS )zLicense-File:)r   r   r   r   r   r     s    
 z?TestEggInfo.test_license_file_attr_pkg_info.<locals>.<listcomp>zLicense-File: NOTICEr   zLicense-File: LICENSE-ABCr   NzLicense-File: LICENSE-XYZ)r1   r   r*   r   r   r   r   r   r   r%   r   rH   rI   r7   rJ   )r0   rM   r+   r   r   r2   Zlicense_file_linesr   r   r   test_license_file_attr_pkg_info  s.    z+TestEggInfo.test_license_file_attr_pkg_infoc              	   C  s   |  d tjdgtj|jd t|gdd\}}tjdd}t	tj|dd	d
}|
 d}W 5 Q R X | |dkstdS )z5Make sure latest metadata version is used by default.r   r   r   r   r   r   r   r5   r[   r\   r?   r@   r}   )r6   r   N)r   r   r   r   r   r   r%   r   r   rH   rI   r7   r<   rJ   r0   rM   r+   r   r   r   r   r2   r   r   r   test_metadata_version$  s    

z!TestEggInfo.test_metadata_versionc           
   	   C  s   |  d tj j|jd d}tjdgtj	|jd t
|gd|d\}}tj	dd	}ttj	|d
dd}| d}W 5 Q R X d}	|	|kstd|kstd S )Nz.long_description_content_type='text/markdown',r   r   r   r   r   r   r5   r[   r\   r?   r@   r}   z'Description-Content-Type: text/markdownr   r   
r0   rM   r+   r   r   r   r   r   r2   Zexpected_liner   r   r   "test_long_description_content_type2  s$    

z.TestEggInfo.test_long_description_content_typec           	   	   C  s   |  d tjdgtj|jd t|gdd\}}tjdd}t	tj|dd	d
}|
 d}W 5 Q R X d|kstd|d kst||dd  }d|kstd|kstd S )Nzqlong_description='This is a long description\nover multiple lines',long_description_content_type='text/markdown',r   r   r   r   r5   r[   r\   r?   r@   r}   r   r   zThis is a long descriptionzover multiple lines)r   r   r   r   r   r   r%   r   r   rH   rI   r7   rJ   index)	r0   rM   r+   r   r   r   r   r2   Zlong_desc_linesr   r   r   test_long_descriptionM  s     
z!TestEggInfo.test_long_descriptionc           
   	   C  s   |  d tj j|jd d}tjdgtj	|jd t
|gd|d\}}tj	dd	}ttj	|d
dd}| d}W 5 Q R X d}	|	|kstd}	|	|kst| |dkstd S )Nzproject_urls={
                'Link One': 'https://example.com/one/',
                'Link Two': 'https://example.com/two/',
                },r   r   r   r   r   r   r5   r[   r\   r?   r@   r}   z/Project-URL: Link One, https://example.com/one/z/Project-URL: Link Two, https://example.com/two/r   r6   r   r   r   r   r   r%   r   r   r   r   r   r   rH   rI   r7   rJ   r<   r   r   r   r   test_project_urlsd  s(    

zTestEggInfo.test_project_urlsc              	   C  s   |  d tjdgtj|jd t|gdd\}}tjdd}t	tj|dd	d
}|
 d}W 5 Q R X d|kstdS )zTest single line license.zlicense='MIT',r   r   r   r   r5   r[   r\   r?   r@   r}   zLicense: MITNr   r   r   r   r   r   r%   r   r   rH   rI   r7   rJ   r   r   r   r   test_license  s    

zTestEggInfo.test_licensec              	   C  s   |  d tjdgtj|jd t|gdd\}}tjdd}t	tj|dd	d
}|
 d}W 5 Q R X d|kstd|kstdd|kstdS )z:Test license is escaped correctly if longer than one line.z<license='This is a long license text \nover multiple lines',r   r   r   r   r5   r[   r\   r?   r@   r}   z%License: This is a long license text z        over multiple linesztext 
        over multipleNr   r   r   r   r   test_license_escape  s    
zTestEggInfo.test_license_escapec           	   	   C  s   |  d tj j|jd d}tjdgtj	|jd t
|gd|d\}}tj	dd	}ttj	|d
dd}| d}W 5 Q R X d|kst| |dkstd S )Nzpython_requires='>=2.7.12',r   r   r   r   r   r   r5   r[   r\   r?   r@   r}   zRequires-Python: >=2.7.12r   r   r   r   r   r   test_python_requires_egg_info  s    


z)TestEggInfo.test_python_requires_egg_infoc                 C  s$   ddg}|D ]}t |stqd S )Nz:standard file not found: should have one of foo.py, bar.pyz"standard file 'setup.py' not found)r   Z_should_suppress_warningrJ   )r0   Zfixturesro   r   r   r   'test_manifest_maker_warning_suppression  s
    z3TestEggInfo.test_manifest_maker_warning_suppressionc              	   C  s   |    tddd}d|_t|}|  |  d|jjksDtt	|jd dd }|
 d	}d|ksrtW 5 Q R X d S )
Nfoo0.0.1r   versionznon_setup.pyr.   z/SOURCES.txtr?   r@   r}   )r1   r
   script_namer   finalize_optionsrm   filelistr   rJ   rH   rI   r7   )r0   rM   rN   Zegg_info_instancerP   sourcesr   r   r   test_egg_info_includes_setup_py  s    z+TestEggInfo.test_egg_info_includes_setup_pyNc                 C  sr   t j j|jd d}|d kr&dg}tj|t j|jd t	|gd|d\}}|r^t
||rn||ksnt
d S )Nr   r   r   r   r   r   )r   r   r   r   r%   r   r   r   r   r   rJ   )r0   rM   r+   r   outputr   r   r   r   r   r   r_     s    

z!TestEggInfo._run_egg_info_commandc              	   C  st   |    tdtdi | || tjdd}ttj|ddd}| 	d}W 5 Q R X d	|kspt
d S )
Nr=   z
                              [egg_info]
                              tag_build = dev
                              tag_date = 0
                              tag_svn_revision = 0
                              r5   r[   r\   r?   r@   r}   zVersion: 0.0.0.dev0r~   )r0   rM   r+   r   r   r2   r   r   r   test_egg_info_tag_only_once  s     
z'TestEggInfo.test_egg_info_tag_only_once)F)NN)1r   r   r   r   r/   r1   r   r<   rR   rK   rZ   rc   rp   rw   r{   r   r   r   sysversion_infor   r   r   r   r   r   r   r   r   r   r   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r_   r   r   r   r   r   r-   2   s  
	#!
)
  
		
	A




  @
	
		
  $
# 	
r-   c                   @  s   e Zd Zdd Zdd ZdS )TestWriteEntriesc              	   C  sf   t ddd}ddi|_|d}d}tjtj|d&}t|dd	 d
|jj	d ksXt
W 5 Q R X d S )Nr   r   r   zfoo = invalid-identifier:foor   z(Problems to parse .*invalid-identifier.*re   entry_pointsr^   z#ensure entry-point follows the specr   )r
   r   get_command_objrj   rk   r   OptionErrorr	   rs   rt   rJ   )r0   rM   r+   rN   r   Zexpected_msgexr   r   r   test_invalid_entry_point  s    

z)TestWriteEntries.test_invalid_entry_pointc                 C  s^   t ddd}ddgd|_|d}t|dd	 td	jd
d}d|ksNtd|ksZtd S )Nr   r   r   zfoo = bar:bazzfaa = bor:boz)abcdefr   r   r^   r?   r@   z[abc]
foo = bar:baz
z[def]
faa = bor:boz
)r
   r   r   r	   r   r   rJ   )r0   rM   r+   rN   r   rQ   r   r   r   test_valid_entry_point  s    
z'TestWriteEntries.test_valid_entry_pointN)r   r   r   r  r  r   r   r   r   r     s   	r   )#
__future__r   r   r   r   rS   r"   r   ry   pathlibr   Zunittestr   rj   Zjaracor   
setuptoolsr   Zsetuptools.command.egg_infor   r   r	   Zsetuptools.distr
   r   r   r   textwrapr   r   r   Zfixturer+   r-   r   r   r   r   r   <module>   s<   
         H