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   




