
    ̆h!                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJr   SSKr/ SQr " S S	\R                   5      r " S
 S5      r " S S\5      rS r " S S\5      r " S S\R                   \S9rg! \ a    Sr N[f = f)zIA collection of tools for testing the Markdown code base and extensions.     )annotationsN)Any   )markdownMarkdownutil)TestCaseLegacyTestCaseKwargsc                  :    \ rS rSr% Sr0 rS\S'    S	S jrS rSr	g)
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`.
zdict[str, Any]default_kwargsNc                2   U=(       d    0 nU R                   R                  5       nUR                  U5        [        S0 UD6nUR	                  U5      nU R                  Xr5        UR                  5        H   u  pU R                  [        Xh5      U	5        M"     g)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 )	r   copyupdater   convertassertMultiLineEqualitemsassertEqualgetattr)
selfsourceexpectedexpected_attrskwargskwsmdoutputkeyvalues
             K/opt/services/DDDS/venv/lib/python3.13/site-packages/markdown/test_tools.pyassertMarkdownRendersTestCase.assertMarkdownRenders=   s     (-2!!&&(

6__F#!!&3(..0JCWR-u5 1    c                J    [         R                  " U5      R                  5       $ )z
Dedent text.
)textwrapdedentstrip)r   texts     r"   r(   TestCase.dedentQ   s     t$**,,r%   r   N)
__name__
__module____qualname____firstlineno____doc__r   __annotations__r#   r(   __static_attributes__r   r%   r"   r	   r	   '   s     $ &(NN'>6(-r%   r	   c                  *    \ rS rSrSrS rS rS rSrg)recursionlimit[   a  
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:

``` python
with recursionlimit(20):
    # test code here
```

See <https://stackoverflow.com/a/50120316/866026>.
c                r    [         R                  " 5       U-   U l        [        R                  " 5       U l        g r,   )r   _get_stack_depthlimitsysgetrecursionlimit	old_limit)r   r9   s     r"   __init__recursionlimit.__init__l   s'    **,u4
..0r%   c                D    [         R                  " U R                  5        g r,   )r:   setrecursionlimitr9   )r   s    r"   	__enter__recursionlimit.__enter__p   s    djj)r%   c                D    [         R                  " U R                  5        g r,   )r:   r@   r<   )r   typer!   tbs       r"   __exit__recursionlimit.__exit__s   s    dnn-r%   )r9   r<   N)	r-   r.   r/   r0   r1   r=   rA   rF   r3   r   r%   r"   r5   r5   [   s     1*.r%   r5   c                      \ rS rSrSrSrg)r   |   z3A `dict` like class for holding keyword arguments. r   Nr-   r.   r/   r0   r1   r3   r   r%   r"   r   r   |   s    >r%   r   c                J    [         R                  " U SSSSSSSSSSS.
S9u  pU$ )z;Normalize whitespace for a string of HTML using `tidylib`. r   r   LF)
drop_empty_parasfix_backslashfix_bad_commentsfix_urijoin_styleslower_literals
merge_divsoutput_xhtmlquote_ampersandnewline)options)tidylibtidy_fragment)r*   r   errorss      r"   _normalize_whitespacer[      s@    **4: NF Mr%   c                      \ rS rSrS rSrg)LegacyTestMeta   c                   S nUR                  SS5      nUR                  S/ 5      nUR                  SS5      nUR                  SS5      nUR                  S	S
5      n	UR                  S[        5       5      n
[        R                  R	                  U5      (       Ga1  [        R
                  " U5       GH  n[        R                  R                  X[5      n[        R                  R                  U5      (       d  MI  [        R                  R                  U5      u  pX:X  d  Mq  [        R                  R                  X]U	-   5      nUR                  SS5      R                  SS5      nU
R                  5       nX;   a  UR                  X=   5        SU-  nX;  a  U" XUU5      UU'   M  [        R                  " S5      " S 5      UU'   GM     [        R                  XX#5      $ )Nc                    ^ ^^^ U UUU4S jnU$ )Nc                  > [        TSS9 nUR                  5       nS S S 5        [        TSS9 nUR                  5       R                  SS5      nS S S 5        [        W40 TD6n[        (       a  T(       a   [        W5      n[        U5      nOT(       a  U R                  S5        U R                  UW5        g ! , (       d  f       N= f! , (       d  f       N= f! [         a    U R                  S5         NRf = f)Nzutf-8)encodingz

z"Tidylib's c library not available.zTidylib not available.)	openreadreplacer   rX   r[   OSErrorskipTestr   )	r   finputr   r   infiler   	normalizeoutfiles	        r"   test;LegacyTestMeta.__new__.<locals>.generate_test.<locals>.test   s    &73qFFHE 4'G4  !vvx//=H 5 "%2627yL#8#B!6v!> MM":;))&(; 4344 # L&JKLs(   B9!C
7C 9
C

CC98C9r   )rk   rm   rl   r   rn   s   ```` r"   generate_test-LegacyTestMeta.__new__.<locals>.generate_test   s    < <" Kr%   location excluderl   F	input_extz.txt
output_extz.htmlr    _-ztest_%sExcludedc                     g r,   r   r   r%   r"   <lambda>(LegacyTestMeta.__new__.<locals>.<lambda>   s    tr%   )getr   ospathisdirlistdirjoinisfilesplitextrf   r   r   unittestskiprD   __new__)clsnamebasesdctrp   rr   rt   rl   ru   rv   r   filerk   tnameextrm   r   	test_names                     r"   r   LegacyTestMeta.__new__   sr   	( 77:r*'')R(GGK/	GGK0	WW\73
)68477==""

8,h577>>&))!#!1!1$!7JE'"$'',,x9K"L %c3 7 ? ?S I$kkm <JJsz2$-$5	 /-:6IWZ-[C	N-5]]:-F|-TC	N -  ||Cu22r%   r   N)r-   r.   r/   r0   r   r3   r   r%   r"   r]   r]      s    .3r%   r]   c                      \ rS rSrSrSrg)r
      aQ  
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:

Attributes:
    location (str): A path to the directory of test files. An absolute path is preferred.
    exclude (list[str]): A list of tests to exclude. Each test name should comprise the filename
        without an extension.
    normalize (bool): A boolean value indicating if the HTML should be normalized. Default: `False`.
    input_ext (str): A string containing the file extension of input files. Default: `.txt`.
    output_ext (str): A string containing the file extension of expected output files. Default: `html`.
    default_kwargs (Kwargs[str, Any]): 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.
r   NrJ   r   r%   r"   r
   r
      s    6 	r%   r
   )	metaclass)r1   
__future__r   r   r:   r   r'   typingr   rs   r   r   r   rX   ImportError__all__r	   r5   dictr   r[   rD   r]   r
   r   r%   r"   <module>r      s   ( Q " 	 
    & & 31-x   1-h. .B	T 	
"/3T /3d	X&&. 	G  Gs   A? ?B
	B
