
    ?d                         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 ddlmZ  G d dej"                        ZddZy)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)	py3compat)stylec                   $     e Zd Z fdZd Z xZS )YAPFTestc                 j    t        t        | 
  |  t        j                  s| j
                  | _        y y )N)superr   __init__r   PY3assertRaisesRegexpassertRaisesRegex)selfargs	__class__s     </usr/lib/python3/dist-packages/yapftests/yapf_test_helper.pyr   zYAPFTest.__init__#   s,    	(D"D)==#66d     c           	         ||k7  r9ddg}t        j                  d      }|j                         D ]9  }t        |      |kD  r|j	                  d|z         &|j	                  d|z         ; |j	                  d       |j                         D ]9  }t        |      |kD  r|j	                  d|z         &|j	                  d|z         ; |j	                  d       |j                  t        j                  |j                         |j                         dd	d
             | j                  dj                  |             y y )NzCode format mismatch:z	Expected:COLUMN_LIMITz!> %sz > %szActual:zDiff:actualexpected )fromfiletofilelineterm
)
r   Get
splitlineslenappendextenddifflibunified_difffailjoin)r   expected_codecodemsglinelenlines         r   assertCodeEqualzYAPFTest.assertCodeEqual(   s   }$k2c		.)g**, %$t9w
**Wt^
$
**Wt^
$	%
 
jj//# %$t9w
**Wt^
$
**Wt^
$	%
 
jj	jj


oo&&( ii		#- r   )__name__
__module____qualname__r   r2   __classcell__)r   s   @r   r   r   !   s    7
 r   r   c                    t        j                  |       }t        j                  |       t	        j
                  |       t        j                  |       t        j                  |       t        j                  |       t        j                  |       |r%t        j                  |t         j"                         t%        j&                  |      }|D ]  }|j)                           |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.
  )target_stream)r   ParseCodeToTreer   SpliceCommentsr   SpliceContinuationsr
   AssignSubtypesr   IdentifyContainersr	   ComputeSplitPenaltiesr   CalculateBlankLinesr   
DumpPyTreesysstderrr   UnwrapPyTreeCalculateFormattingInformation)r.   dumptreetreellinesllines        r   ParseAndUnwraprI   B   s     
	%	%d	+$  &**40!!$'''-%%d+++D1d#**=((.& +e	((*+ 
-r   )F)__doc__r)   rA   unittestyapf.pytreer   r   r   r   r   r   r	   r
   yapf.yapflibr   r   r   TestCaser   rI    r   r   <module>rP      sL    )  
  - ' , ( $ & % ( + "  x    Br   