o
    ?n0j^                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl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ejZdddZdS )z"Support module for tests for yapf.    N)blank_line_calculator)comment_splicer)continuation_splicer)pytree_unwrapper)pytree_utils)pytree_visitor)split_penalty)subtype_assigner)identify_container)stylec                       s$   e Zd Z fddZdd Z  ZS )YAPFTestc                    s   t t| j|  d S )N)superr   __init__)selfargs	__class__ a/home/wildlama/miniconda3/envs/lam_a2e/lib/python3.10/site-packages/yapftests/yapf_test_helper.pyr   "   s   zYAPFTest.__init__c              	   C   s   ||krjddg}t d}| D ]}t||kr!|d|  q|d|  q|d | D ]}t||krB|d|  q2|d|  q2|d |tj| | dd	d
d | d	| d S d S )NzCode format mismatch:z	Expected:ZCOLUMN_LIMITz!> %sz > %szActual:zDiff:actualexpected )fromfiletofileZlineterm
)
r   ZGet
splitlineslenappendextenddifflibZunified_diffZfailjoin)r   Zexpected_codecodemsgZlinelenliner   r   r   assertCodeEqual%   s0   


zYAPFTest.assertCodeEqual)__name__
__module____qualname__r   r$   __classcell__r   r   r   r   r       s    r   Fc                 C   sz   t | }t| t| t| t	| t
| t| |r-tj|tjd t|}|D ]}|  q4|S )aV  Produces logical lines from the given code.

  Parses the code into a tree, performs comment splicing and runs the
  unwrapper.

  Arguments:
    code: code to parse as a string
    dumptree: if True, the parsed pytree (after comment splicing) is dumped
              to stderr. Useful for debugging.

  Returns:
    List of logical lines.
  )Ztarget_stream)r   ZParseCodeToTreer   ZSpliceCommentsr   ZSpliceContinuationsr	   ZAssignSubtypesr
   ZIdentifyContainersr   ZComputeSplitPenaltiesr   ZCalculateBlankLinesr   Z
DumpPyTreesysstderrr   ZUnwrapPyTreeZCalculateFormattingInformation)r!   ZdumptreetreeZllinesZlliner   r   r   ParseAndUnwrap?   s   








r,   )F)__doc__r   r)   ZunittestZyapf.pytreer   r   r   r   r   r   r   r	   Zyapf.yapflibr
   r   ZTestCaser   r,   r   r   r   r   <module>   s    