a
    
d^                     @   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__ c/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/yapftests/yapf_test_helper.pyr   "   s    zYAPFTest.__init__c              	   C   s   ||krddg}t d}| D ].}t||krB|d|  q"|d|  q"|d | D ].}t||kr|d|  qd|d|  qd|d |tj| | dd	d
d | d	| 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%   s.    


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| |rZtj|tjd t|}|D ]}|  qh|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   