a
    t=ic                      @   s   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mZ zddl	Z	W n e
yZ   dZ	Y n0 g dZG dd dejZG dd	 d	ZG d
d deZdd ZG dd deZG dd dejedZdS )a  
Python Markdown

A Python implementation of John Gruber's Markdown.

Documentation: https://python-markdown.github.io/
GitHub: https://github.com/Python-Markdown/markdown/
PyPI: https://pypi.org/project/Markdown/

Started by Manfred Stienstra (http://www.dwerg.net/).
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
Currently maintained by Waylan Limberg (https://github.com/waylan),
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).

Copyright 2007-2018 The Python Markdown Project (v. 1.7 and later)
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
Copyright 2004 Manfred Stienstra (the original version)

License: BSD (see LICENSE.md for details).
    N   )markdownMarkdownutil)TestCaseLegacyTestCaseKwargsc                   @   s&   e Zd ZdZi ZdddZdd ZdS )r   a  
    A unittest.TestCase subclass with helpers for testing Markdown output.

    Define `default_kwargs` as a dict of keywords to pass to Markdown for each
    test. The defaults can be overridden on individual tests.

    The `assertMarkdownRenders` method accepts the source text, the expected
    output, and any keywords to pass to Markdown. The `default_kwargs` are used
    except where overridden by `kwargs`. The output and expected output are passed
    to `TestCase.assertMultiLineEqual`. An AssertionError is raised with a diff
    if the actual output does not equal the expected output.

    The `dedent` method is available to dedent triple-quoted strings if
    necessary.

    In all other respects, behaves as unittest.TestCase.
    Nc           
      K   sh   |pi }| j  }|| tf i |}||}| || | D ]\}}	| t|||	 qHdS )a  
        Test that source Markdown text renders to expected output with given keywords.

        `expected_attrs` accepts a dict. Each key should be the name of an attribute
        on the `Markdown` instance and the value should be the expected value after
        the source text is parsed by Markdown. After the expected output is tested,
        the expected value for each attribute is compared against the actual
        attribute of the `Markdown` instance using `TestCase.assertEqual`.
        N)	default_kwargscopyupdater   convertassertMultiLineEqualitemsassertEqualgetattr)
selfsourceexpectedZexpected_attrskwargskwsmdoutputkeyvalue r   d/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/markdown/test_tools.pyassertMarkdownRenders9   s    


zTestCase.assertMarkdownRendersc                 C   s   t | S )z
        Dedent text.
        )textwrapdedentstrip)r   textr   r   r   r   M   s    zTestCase.dedent)N)__name__
__module____qualname____doc__r	   r   r   r   r   r   r   r   $   s   
r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	recursionlimita  
    A context manager which temporarily modifies the Python recursion limit.

    The testing framework, coverage, etc. may add an arbitrary number of levels to the depth. To maintain consistency
    in the tests, the current stack depth is determined when called, then added to the provided limit.

    Example usage:

        with recursionlimit(20):
            # test code here

    See https://stackoverflow.com/a/50120316/866026
    c                 C   s   t  | | _t | _d S N)r   Z_get_stack_depthlimitsysgetrecursionlimit	old_limit)r   r'   r   r   r   __init__f   s    zrecursionlimit.__init__c                 C   s   t | j d S r&   )r(   setrecursionlimitr'   )r   r   r   r   	__enter__j   s    zrecursionlimit.__enter__c                 C   s   t | j d S r&   )r(   r,   r*   )r   typer   tbr   r   r   __exit__m   s    zrecursionlimit.__exit__N)r!   r"   r#   r$   r+   r-   r0   r   r   r   r   r%   W   s   r%   c                   @   s   e Zd ZdZdS )r   z2 A dict like class for holding keyword arguments. Nr!   r"   r#   r$   r   r   r   r   r   v   s   r   c                 C   s,   t j| ddddddddddd
d\}}|S )z: Normalize whitespace for a string of html using tidylib. r   r   ZLF)
Zdrop_empty_parasZfix_backslashZfix_bad_commentsZfix_uriZjoin_stylesZlower_literalsZ
merge_divsZoutput_xhtmlZquote_ampersandnewline)options)tidylibZtidy_fragment)r    r   errorsr   r   r   _normalize_whitespace{   s    r6   c                   @   s   e Zd Zdd ZdS )LegacyTestMetac                 C   s2  dd }| dd}| dg }| dd}| dd	}| d
d}	| dt }
tj|r"t|D ]}tj||}tj|rjtj|\}}||krjtj|||	 }|	dd	dd}|

 }||v r|||  d| }||vr
|||||||< qjtddd ||< qjt| |||S )Nc                    s    fdd}|S )Nc                    s   t  dd}| }W d    n1 s*0    Y  t dd }| dd}W d    n1 sf0    Y  t|fi }trrzt|}t|}W q ty   | d Y q0 nr| d | || d S )Nzutf-8)encodingz

z"Tidylib's c library not available.zTidylib not available.)	openreadreplacer   r4   r6   OSErrorZskipTestr   )r   finputr   r   infiler   	normalizeoutfiler   r   test   s    &.
z;LegacyTestMeta.__new__.<locals>.generate_test.<locals>.testr   )rA   rC   rB   r   rD   r   r@   r   generate_test   s    z-LegacyTestMeta.__new__.<locals>.generate_testlocation excluderB   F	input_extz.txt
output_extz.htmlr	    _-ztest_%sZExcludedc                   S   s   d S r&   r   r   r   r   r   <lambda>       z(LegacyTestMeta.__new__.<locals>.<lambda>)getr   ospathisdirlistdirjoinisfilesplitextr<   r
   r   unittestskipr.   __new__)clsnamebasesdctrE   rF   rH   rB   rI   rJ   r   filerA   ZtnameextrC   r   Z	test_namer   r   r   rZ      s.    
zLegacyTestMeta.__new__N)r!   r"   r#   rZ   r   r   r   r   r7      s   r7   c                   @   s   e Zd ZdZdS )r   a  
    A `unittest.TestCase` subclass for running Markdown's legacy file-based tests.

    A subclass should define various properties which point to a directory of
    text-based test files and define various behaviors/defaults for those tests.
    The following properties are supported:

    location: A path to the directory of test files. An absolute path is preferred.
    exclude: A list of tests to exclude. Each test name should comprise the filename
             without an extension.
    normalize: A boolean value indicating if the HTML should be normalized.
               Default: `False`.
    input_ext: A string containing the file extension of input files. Default: `.txt`.
    ouput_ext: A string containing the file extension of expected output files.
               Default: `html`.
    default_kwargs: A `Kwargs` instance which stores the default set of keyword
                    arguments for all test files in the directory.

    In addition, properties can be defined for each individual set of test files within
    the directory. The property should be given the name of the file without the file
    extension. Any spaces and dashes in the filename should be replaced with
    underscores. The value of the property should be a `Kwargs` instance which
    contains the keyword arguments that should be passed to `Markdown` for that
    test file. The keyword arguments will "update" the `default_kwargs`.

    When the class instance is created, it will walk the given directory and create
    a separate unitttest for each set of test files using the naming scheme:
    `test_filename`. One unittest will be run for each set of input and output files.
    Nr1   r   r   r   r   r      s   r   )	metaclass)r$   rQ   r(   rX   r   rG   r   r   r   r4   ImportError__all__r   r%   dictr   r6   r.   r7   r   r   r   r   r   <module>   s    
32