o
    5‘ði‹  ã                   @   st   d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ G dd„ dƒZG d	d
„ d
ƒZdd„ ZdS )z%Tests for automatic package discoveryé    N)Úfind_namespace_packagesÚfind_packages)ÚFlatLayoutPackageFinderé   )Ú	os_helperc                   @   s¶   e Zd Zdd„ Zdd„ Zdd„ Zd(dd	„Zd(d
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zejje ¡  dd�dd„ ƒZdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdS ))ÚTestFindPackagesc                 C   s   t  ¡ | _|  ¡  d S ©N)ÚtempfileÚmkdtempÚdist_dirÚ_make_pkg_structure©ÚselfÚmethod© r   úb/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/tests/test_find_packages.pyÚsetup_method   s   
zTestFindPackages.setup_methodc                 C   s   t  | j¡ d S r   )ÚshutilÚrmtreer   r   r   r   r   Úteardown_method   s   z TestFindPackages.teardown_methodc                 C   s¨   |   d| j¡| _|  d| j¡ |   d| j¡| _|   d| j¡ |   d| j¡| _|  d| j¡ |   d| j¡| _|   d| j¡| _|  d	| j¡ |  d
| j¡ |  d| j¡ dS )aG  Make basic package structure.

        dist/
            docs/
                conf.py
            pkg/
                __pycache__/
                nspkg/
                    mod.py
                subpkg/
                    assets/
                        asset
                    __init__.py
            setup.py

        Údocszconf.pyÚpkgÚ__pycache__Únspkgzmod.pyÚsubpkgÚassetsÚassetú__init__.pyzsetup.pyN)Ú_mkdirr   Údocs_dirÚ_touchÚpkg_dirÚ
ns_pkg_dirÚsub_pkg_dirÚ	asset_dir)r   r   r   r   r      s   z$TestFindPackages._make_pkg_structureNc                 C   s    |r	t j ||¡}t  |¡ |S r   )ÚosÚpathÚjoinÚmkdir)r   r&   Ú
parent_dirr   r   r   r   4   s   
zTestFindPackages._mkdirc                 C   s$   |r	t j ||¡}t|dƒ ¡  |S )NÚwb)r%   r&   r'   ÚopenÚclose)r   r&   Údir_r   r   r   r    :   s   zTestFindPackages._touchc                 C   s,   |   d| j¡ t| jƒ}|ddgksJ ‚d S )Nr   r   ú
pkg.subpkg©r    r!   r   r   ©r   Úpackagesr   r   r   Útest_regular_package@   s   
z%TestFindPackages.test_regular_packagec                 C   s.   |   d| j¡ t| jdd�}|dgksJ ‚d S )Nr   )zpkg.*©Úexcluder   r/   r0   r   r   r   Útest_excludeE   s   zTestFindPackages.test_excludec                 C   s<   |   d| j¡ |   d| j¡ t| jdd�}|dgksJ ‚dS )zW
        Excluding a parent package should not exclude child packages as well.
        r   )r   r3   r.   N)r    r!   r#   r   r   r0   r   r   r   Útest_exclude_recursiveJ   s   z'TestFindPackages.test_exclude_recursivec                 C   sJ   |   d| j¡ |  d| j¡}|   d|¡ t| jdgd�}|dgks#J ‚dS )zM
        If include is specified, other packages should be excluded.
        r   Ú	other_pkg)ÚincludeN)r    r!   r   r   r   )r   Úalt_dirr1   r   r   r   Útest_include_excludes_otherS   s
   z,TestFindPackages.test_include_excludes_otherc                 C   sV   t  tj | jd¡¡ |  d| j¡}|  d|¡ |  d|¡ t	| jƒ}d|vs)J ‚d S )Núpkg/subpkg/assetsz	some.datar   zfile.datzpkg.some.data)
r   r   r%   r&   r'   r   r   r!   r    r   )r   Údata_dirr1   r   r   r   Útest_dir_with_dot_is_skipped]   s   
z-TestFindPackages.test_dir_with_dot_is_skippedc                 C   s@   |   d| j¡}|   d|¡}|  d|¡ t| jƒ}d|vsJ ‚dS )zk
        Ensure that a package in a non-package such as build/pkg/__init__.py
        is excluded.
        Úbuildr   r   z	build.pkgN)r   r   r    r   )r   Ú	build_dirÚbuild_pkg_dirr1   r   r   r   Ú,test_dir_with_packages_in_subdir_is_excludede   s
   
z=TestFindPackages.test_dir_with_packages_in_subdir_is_excludedzSymlink support required)Úreasonc                 C   sT   |   d| j¡ tj | jd¡}t d|¡ tj |¡sJ ‚t| jƒ}d|v s(J ‚dS )z¨
        A symbolically-linked directory should be treated like any other
        directory when matched as a package.

        Create a link from lpkg -> pkg.
        r   Úlpkgr   N)	r    r!   r%   r&   r'   r   ÚsymlinkÚisdirr   )r   Ú
linked_pkgr1   r   r   r   Ú$test_symlinked_packages_are_includedp   s   
z5TestFindPackages.test_symlinked_packages_are_includedc                 C   s   t |ƒt |ƒks
J ‚d S r   )Úset)r   ÚactualÚexpectedr   r   r   Ú_assert_packages   s   z!TestFindPackages._assert_packagesc                 C   s(   t | jdgdgd�}|  |g d¢¡ d S )Nzpkg*úpkg.subpkg.assets)r8   r4   ©r   ú	pkg.nspkgr.   ©r   r   rK   r0   r   r   r   Útest_pep420_ns_package‚   s   ÿz'TestFindPackages.test_pep420_ns_packagec                 C   s$   t | jdgd�}|  |g d¢¡ d S )NrL   r3   )r   r   rN   r.   rO   r0   r   r   r   Ú"test_pep420_ns_package_no_includesˆ   s   z3TestFindPackages.test_pep420_ns_package_no_includesc                 C   s"   t | jƒ}g d¢}|  ||¡ d S )N)r   r   rN   r.   rL   rO   )r   r1   rJ   r   r   r   Ú.test_pep420_ns_package_no_includes_or_excludesŒ   s   
z?TestFindPackages.test_pep420_ns_package_no_includes_or_excludesc                 C   s4   |   d| j¡ t| jddgd�}|  |g d¢¡ d S )Nr   r   rL   r3   rM   )r    r!   r   r   rK   r0   r   r   r   Ú3test_regular_package_with_nested_pep420_ns_packages‘   s
   
ÿzDTestFindPackages.test_regular_package_with_nested_pep420_ns_packagesc                 C   s@   t  | j¡ t  tj | jd¡¡ t| jƒ}|  |g d¢¡ d S )Nr;   rM   )	r   r   r   r%   r&   r'   r   r   rK   r0   r   r   r   Ú*test_pep420_ns_package_no_non_package_dirs˜   s   
z;TestFindPackages.test_pep420_ns_package_no_non_package_dirsr   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r    r2   r5   r6   r:   r=   rA   ÚpytestÚmarkÚskipifr   Úcan_symlinkrG   rK   rP   rQ   rR   rS   rT   r   r   r   r   r      s(    

	

r   c                	   @   s†   e Zd Zg d¢ddgfddgddgfg d¢g fg d¢dgfg d	¢dgfg d
¢g d¢fg d¢g d¢fdœZej de ¡ ¡dd„ ƒZdS )ÚTestFlatLayoutPackageFinder)z.pkg/__init__.pyúpkg/__init__.pyzpkg/nested/file.txtr   z
pkg.nestedz_pkg/__init__.pyzpkg/_private/__init__.pyzpkg._private)zinvalid-pkg/__init__.pyzother.pkg/__init__.pyzyet,another/file.py)r]   zdocs/conf.pyzdocs/readme.rst)r]   ztests/test_pkg.pyztests/__init__.py)r]   zexamples/__init__.pyzexamples/file.pyzexample/other_file.pyzpkg/example/__init__.pyzpkg/examples/__init__.py)r   zpkg.exampleszpkg.example)zhtmlcov/index.htmlr]   ztasks/__init__.pyztasks/subpackage/__init__.pyzfabfile/__init__.pyzfabfile/subpackage/__init__.pyzpkg/tasks/__init__.pyzpkg/fabfile/__init__.py)r   z	pkg.taskszpkg.fabfile)zhidden-folderszprivate-packageszinvalid-namer   ÚtestsÚexamplesztool-specificÚexamplec                 C   s>   | j | \}}t||ƒ t t|ƒ¡}t|ƒt|ƒksJ ‚d S r   )ÚEXAMPLESÚensure_filesr   ÚfindÚstrrH   )r   Útmp_pathr`   ÚfilesÚexpected_packagesÚfound_packagesr   r   r   Ú&test_unwanted_directories_not_includedÎ   s   
zBTestFlatLayoutPackageFinder.test_unwanted_directories_not_includedN)	rU   rV   rW   ra   rX   rY   ÚparametrizeÚkeysri   r   r   r   r   r\   Ÿ   s.    þþþþ	öôâ.r\   c                 C   s.   |D ]}| | }|j jddd� | ¡  qd S )NT)ÚparentsÚexist_ok)Úparentr(   Útouch)Ú	root_pathrf   Úfiler&   r   r   r   rb   Ö   s
   
ýrb   )Ú__doc__r%   r   r	   rX   Ú
setuptoolsr   r   Úsetuptools.discoveryr   Úcompat.py39r   r   r\   rb   r   r   r   r   Ú<module>   s     7