U
    ¤�©jÐ  ã                   @   s  d Z ddlZddlZddlZddlZddlZej e¡p:dZ	ej e	¡Z
dd„ e e
¡D ƒZdd„ eD ƒZdd„ Zej d	e¡d
d„ ƒZej e	d¡Zzdd„ dD ƒZW n ek
rÄ   edƒ‚Y nX ej dddg¡dd„ ƒZej de¡dd„ ƒZdd„ ZdS )a  This file tests the source code provided by the documentation.

See
- doctest documentation: https://docs.python.org/3/library/doctest.html
- Issue 443: https://github.com/collective/icalendar/issues/443

This file should be tests, too:

    >>> print("Hello World!")
    Hello World!

é    NÚ.c                 C   s@   g | ]8\}}}|D ](}|  ¡  d ¡rd|krd ||f¡‘qqS )z.pyZfuzzingú/)ÚlowerÚendswithÚjoin)Ú.0ÚdirpathÚdirnamesÚ	filenamesÚfilename© r   úE/tmp/pip-unpacked-wheel-g40nyxg1/icalendar/tests/test_with_doctest.pyÚ
<listcomp>   s     ýr   c                 C   s0   g | ](}d |t tƒd…  dd¡ dd¡ ‘qS )Z	icalendaréýÿÿÿú\r   r   )ÚlenÚICALENDAR_PATHÚreplace)r   Zpython_filer   r   r   r      s   þÿc                   C   s   t tkst‚d S ©N)Ú__name__ÚMODULE_NAMESÚAssertionErrorr   r   r   r   Útest_this_module_is_among_them&   s    r   Úmodule_namec              
   C   sz   zt  | ¡}W n8 tk
rF } z|jdkr4t d¡ ‚ W 5 d}~X Y nX tj|| |d�}|jdksvt	|j› d| › �ƒ‚dS )z,This test runs doctest on the Python module.Úpytzz,pytz is not installed, skipping this module.N)ÚnameÚglobsr   ú errors in )
Ú	importlibÚimport_moduleÚModuleNotFoundErrorr   ÚpytestÚskipÚdoctestÚtestmodÚfailedr   )r   Úenv_for_doctestÚmoduleÚeÚtest_resultr   r   r   Útest_docstring_of_python_file*   s    

r*   z	../../../c                 C   sD   g | ]<}t  t j t|¡¡D ]"}| ¡  d ¡rt j t||¡‘qqS )z.rst)ÚosÚlistdirÚpathr   ÚDOCUMENTATION_PATHr   r   )r   Úsubdirr   r   r   r   r   ;   s
    ý)Zdocsr   zICould not find the documentation - remove the build folder and try again.r   z
README.rstz	index.rstc                    s   t ‡ fdd„tD ƒƒst‚d S )Nc                 3   s   | ]}|  ˆ ¡V  qd S r   )r   )r   r-   ©r   r   r   Ú	<genexpr>O   s     z)test_files_is_included.<locals>.<genexpr>)ÚanyÚDOCUMENT_PATHSr   r0   r   r0   r   Útest_files_is_includedG   s    r4   Údocumentc                 C   sx   zddl }W n tk
r*   t d¡ Y nX ztj| d|dd�}W 5 | ¡  X |jdkstt|j› dt	j
 | ¡› �ƒ‚dS )z^This test runs doctest on a documentation file.

    functions are also replaced to work.
    r   Nz'pytz not installed, skipping this file.F)Zmodule_relativer   Zraise_on_errorr   )r   ÚImportErrorr!   r"   Zuse_zoneinfor#   Ztestfiler%   r   r+   r-   Úbasename)r5   Zzoneinfo_onlyr&   Ztzpr   r)   r   r   r   Útest_documentation_fileR   s        ÿ

ÿþr8   c                 C   s   dt jkst‚dS )z#Allow importing zoneinfo for tests.ZzoneinfoN)ÚsysÚmodulesr   )r&   r   r   r   Útest_can_import_zoneinfoh   s    r;   )Ú__doc__r#   r   r+   r9   r!   r-   ÚdirnameÚ__file__ZHEREr   ÚwalkZPYTHON_FILESr   r   ÚmarkZparametrizer*   r   r.   r3   ÚFileNotFoundErrorÚOSErrorr4   r8   r;   r   r   r   r   Ú<module>   sF   þý
þ
ÿ
þþ

