o
    DDi                     @   s   d dl mZ d dlmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ G dd	 d	ZG d
d deeZdS )    )dedent)OptionalSequenceType)parse_modulePartialParserConfig)Codemod)CodemodContext)SkipFile)UnitTestc                   @   s   e Zd ZU dZdZee ed< ede	de	fddZ
de	d	e	dd
fddZd
d
d
ddde	de	dedee dee	 deee	  dededd
fddZd
S )_CodemodTesta  
    Mixin that can be added to a unit test framework in order to provide
    convenience features. This is provided as an internal-only feature so
    that CodemodTest can be used with other frameworks. This is necessary
    since we set a metaclass on our UnitTest implementation.
    .	TRANSFORMdatareturnc                    s   t | d}dtdtfdd  fdd|D }|r/|d d	kr/|d
d }|r/|d d	ks!|rE|d d	krE|dd }|rE|d d	ks7d|}|dsS|d S |S )z
        Given a code string originting from a multi-line triple-quoted string,
        normalize the code using ``dedent`` and ensuring a trailing newline
        is present.
        
liner   c                 S   s   t |  dkr
dS | S )Nr    )lenstrip)r    r   P/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/codemod/_testing.pyfilter_line'   s   z3_CodemodTest.make_fixture_data.<locals>.filter_linec                    s   g | ]} |qS r   r   ).0r   r   r   r   
<listcomp>-   s    z2_CodemodTest.make_fixture_data.<locals>.<listcomp>r   r      N)r   splitstrjoinendswith)r   linescoder   r   r   make_fixture_data   s   

z_CodemodTest.make_fixture_dataexpectedactualNc                 C   s   |  t|t| dS )a  
        Given an expected and actual code string, makes sure they equal. This
        ensures that both the expected and actual are sanitized, so its safe to
        use this on strings that may have come from a triple-quoted multi-line
        string.
        N)assertEqualCodemodTestr#   )selfr$   r%   r   r   r   assertCodeEqual;   s   	z_CodemodTest.assertCodeEqualF)context_overridepython_versionexpected_warningsexpected_skipbeforeafterargsr*   r+   r,   r-   kwargsc                O   s   |dur|nt  }	| j|	g|R i |}
tt||dur#t|dnt d}z|
|}W n ty=   |s9 |}Y nw |rE| d | 	t|t|j
 |dur_| ||	j dS dS )a  
        Given a before and after code string, and any args/kwargs that should
        be passed to the codemod constructor specified in
        :attr:`~CodemodTest.TRANSFORM`, validate that the codemod executes as
        expected. Verify that the codemod completes successfully, unless the
        ``expected_skip`` option is set to ``True``, in which case verify that
        the codemod skips.  Optionally, a :class:`CodemodContext` can be provided.
        If none is specified, a default, empty context is created for you.
        Additionally, the python version for the code parser can be overridden
        to a valid python version string such as `"3.6"`. If none is specified,
        the version of the interpreter running your tests will be used. Also, a
        list of warning strings can be specified and :meth:`~CodemodTest.assertCodemod`
        will verify that the codemod generates those warnings in the order
        specified. If it is left out, warnings are not checked.
        N)r+   )configz$Expected SkipFile but was not raised)r	   r   r   r'   r#   r   transform_moduler
   failr&   r"   assertSequenceEqualwarnings)r(   r.   r/   r*   r+   r,   r-   r0   r1   contexttransform_instance
input_treeoutput_treer   r   r   assertCodemodI   s0   


z_CodemodTest.assertCodemod)__name__
__module____qualname____doc__r   r   r   __annotations__staticmethodr   r#   r)   objectr   r	   r   boolr;   r   r   r   r   r      s:   
 
	
r   c                   @   s   e Zd ZdZdS )r'   aP  
    Base test class for a :class:`Codemod` test. Provides facilities for
    auto-instantiating and executing a codemod, given the args/kwargs that
    should be passed to it. Set the :attr:`~CodemodTest.TRANSFORM` class
    attribute to the :class:`Codemod` class you wish to test and call
    :meth:`~CodemodTest.assertCodemod` inside your test method to verify it
    transforms various source code chunks correctly.

    Note that this is a subclass of ``UnitTest`` so any :class:`CodemodTest`
    can be executed using your favorite test runner such as the ``unittest``
    module.
    N)r<   r=   r>   r?   r   r   r   r   r'      s    r'   N)textwrapr   typingr   r   r   libcstr   r   libcst.codemod._codemodr   libcst.codemod._contextr	   libcst.codemod._runnerr
   libcst.testing.utilsr   r   r'   r   r   r   r   <module>   s   p