B
    u9aoM  ã               @   sè   d dl Z d dlmZmZ d dlZd dlZd dlZG dd„ dejƒZG dd„ dejƒZ	G dd„ dejƒZ
d	Zd
ZdZdZdZdZdZdZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZdd„ Zedkräeƒ  dS )é    N)Úrun_unittestÚfindfilec               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestWithAsciic             C   sš   t  d dd¡}| j| ¡ ddd |  t| ¡ ƒddg¡ |  |jtƒ ¡ t  d dd¡}| j| ¡ ddd |  t| ¡ ƒd	d
dg¡ |  |jtƒ ¡ d S )NZdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZeabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbg×£p=
×ï?é   )Úplaces)Úinsertr   r   r   é   )Úequalr   éd   r   ée   Zebbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)r	   r   é2   r   r   )r   r   r   r   é3   )r	   r   r
   r   r   )	ÚdifflibÚSequenceMatcherÚassertAlmostEqualÚratioÚassertEqualÚlistÚget_opcodesÚbpopularÚset)ÚselfÚsm© r   ú"/usr/lib/python3.7/test_difflib.pyÚtest_one_insert	   s    zTestWithAscii.test_one_insertc             C   s@   t  d dd¡}| j| ¡ ddd |  t| ¡ ƒdddg¡ d S )	NZQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbÚPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbg+‡ÙÎï?r   )r   )r	   r   é(   r   r   )Údeleter   é)   r   r   )r	   r   éQ   r   éP   )r   r   r   r   r   r   r   )r   r   r   r   r   Útest_one_delete   s    zTestWithAscii.test_one_deletec             C   sr   t jdd„ ddd}|  |jtƒ ¡ t jdd„ ddd}|  |jdh¡ t jd	d„ ddd}|  |jdd
h¡ d S )Nc             S   s   | dkS )Nú r   )Úxr   r   r   Ú<lambda>!   ó    z*TestWithAscii.test_bjunk.<locals>.<lambda>r   ZTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)ZisjunkÚaÚbc             S   s   | dkS )Nr#   r   )r$   r   r   r   r%   %   r&   zhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb                    r#   c             S   s   | dkS )N)r#   r(   r   )r$   r   r   r   r%   )   r&   r(   )r   r   r   Zbjunkr   )r   r   r   r   r   Ú
test_bjunk    s    





zTestWithAscii.test_bjunkN)Ú__name__Ú
__module__Ú__qualname__r   r"   r)   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdd„ ZdS )ÚTestAutojunkz-Tests for the autojunk parameter added in 2.7c             C   st   d}d}t  d ||¡}| j| ¡ ddd |  |jdh¡ t jd ||dd}| j| ¡ d	dd |  |jtƒ ¡ d S )
NZÈbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZÉabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbr   r   )r   r(   F)ZautojunkgìQ¸…ëï?)r   r   r   r   r   r   r   )r   Zseq1Zseq2r   r   r   r   Ú#test_one_insert_homogenous_sequence0   s    z0TestAutojunk.test_one_insert_homogenous_sequenceN)r*   r+   r,   Ú__doc__r.   r   r   r   r   r-   .   s   r-   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú
TestSFbugsc             C   sB   t  d g g ¡}|  | ¡ d¡ |  | ¡ d¡ |  | ¡ d¡ d S )Nr   )r   r   r   r   Zquick_ratioZreal_quick_ratio)r   Úsr   r   r   Útest_ratio_for_null_seqnA   s    z#TestSFbugs.test_ratio_for_null_seqnc             C   s>   t  d g g ¡ ¡ }|  tt|¡ t  g g ¡}|  tt|¡ d S )N)r   r   Zget_grouped_opcodesÚassertRaisesÚStopIterationÚnextÚunified_diff)r   Z	group_genZdiff_genr   r   r   Útest_comparing_empty_listsH   s    z%TestSFbugs.test_comparing_empty_listsc             C   sX   t  d dd¡}| ¡ }| ¡ }|  |d jd¡ |  |d jd¡ |  |d jd¡ d S )NZabxcdZabcdr   é   r   )r   r   Zget_matching_blocksr   Úsize)r   r1   ÚfirstÚsecondr   r   r   Útest_matching_blocks_cacheO   s    z%TestSFbugs.test_matching_blocks_cachec             C   s\   t t ¡  dgdg¡ƒ}|  d|d ¡ |  d|d ¡ |  d|d ¡ |  d	|d
 ¡ d S )Nz	I am a buggyz		I am a bugz- 	I am a buggyr   z?            --
r   z+ 		I am a bugr8   z? +
r   )r   r   ZDifferZcomparer   )r   Údiffr   r   r   Útest_added_tab_hintX   s
    zTestSFbugs.test_added_tab_hintc             C   s$   |   tt dgdgd¡ƒdg¡ d S )NÚ2Ú3r   ))r   z -2)r   z +3T)r   r   r   Z_mdiff)r   r   r   r   Útest_mdiff_catch_stop_iteration`   s    z*TestSFbugs.test_mdiff_catch_stop_iterationN)r*   r+   r,   r2   r7   r<   r>   rA   r   r   r   r   r0   @   s
   	r0   z
   1. Beautiful is beTTer than ugly.
   2. Explicit is better than implicit.
   3. Simple is better than complex.
   4. Complex is better than complicated.
z™
   1. Beautiful is better than ugly.
   3.   Simple is better than complex.
   4. Complicated is better than complex.
   5. Flat is better than nested.
u    
   1. Beautiful is beTTer than ugly.
   2. Explicit is better than Ä±mplÄ±cÄ±t.
   3. Simple is better than complex.
   4. Complex is better than complicated.
uœ   
   1. Beautiful is better than Ã¼gly.
   3.   SÄ±mple is better than complex.
   4. Complicated is better than cÃ¶mplex.
   5. Flat is better than nested.
zÛ
		Line 1: preceded by from:[tt] to:[ssss]
  		Line 2: preceded by from:[sstt] to:[sssst]
  	 	Line 3: preceded by from:[sstst] to:[ssssss]
Line 4:  	has from:[sst] to:[sss] after :
Line 5: has from:[t] to:[ss] at end	
zÞ
    Line 1: preceded by from:[tt] to:[ssss]
    	Line 2: preceded by from:[sstt] to:[sssst]
      Line 3: preceded by from:[sstst] to:[ssssss]
Line 4:   has from:[sst] to:[sss] after :
Line 5: has from:[t] to:[ss] at end
zôline 0
1234567890123456789012345689012345
line 1
line 2
line 3
line 4   changed
line 5   changed
line 6   changed
line 7
line 8  subtracted
line 9
1234567890123456789012345689012345
short line
just fits in!!
just fits in two lines yup!!
the endzùline 0
1234567890123456789012345689012345
line 1
line 2    added
line 3
line 4   chanGEd
line 5a  chanGed
line 6a  changEd
line 7
line 8
line 9
1234567890
another long line that needs to be wrapped
just fitS in!!
just fits in two lineS yup!!
the endc               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestSFpatchesc          !   C   sÞ  t d d }td d }d| }d| }| ¡ }| ¡ }| ¡ }| ¡ }t ¡ }t ¡ }t}t}t ¡ }	tjdd}
tjdd}|	j	||dd	d
dd}d 
d|	j||dd	ddd|	j||dd	ddd|	j||dd	dddd|	j||dd	dddd|	j||dd	ddd|	j||dd	d
dd|	jg g dd	ddd|	jg g dd	d
dd|
 ||¡d|	 ||¡d|j| ¡ | ¡ dddd| | ¡ | ¡ ¡d| | d¡| d¡¡g¡}| dd | ¡}ttd!ƒƒ}|  || ¡ ¡ W d Q R X d S )"Nz(123
123
123
123
123
123
123
123
123
123
r   z(456
456
456
456
456
456
456
456
456
456
r8   )Útabsizeé   )Z
wrapcolumnÚfromÚtoFé   )ÚcontextZnumlinesÚ
z8<h2>Context (first diff within numlines=5(default))</h2>T)rH   z7<h2>Context (first diff after numlines=5(default))</h2>z<h2>Context (numlines=6)</h2>é   z<h2>Context (numlines=0)</h2>r   z<h2>Same Context</h2>z<h2>Same Full</h2>z<h2>Empty Context</h2>z<h2>Empty Full</h2>z<h2>tabsize=2</h2>z<h2>tabsize=default</h2>z+<h2>Context (wrapcolumn=14,numlines=0)</h2>z#<h2>wrapcolumn=14,splitlines()</h2>z'<h2>wrapcolumn=14,splitlines(True)</h2>z</body>z
%s
</body>ztest_difflib_expect.html)Úpatch914575_from1Úpatch914575_to1Ú
splitlinesÚpatch914575_from2Úpatch914575_to2Úpatch914575_from3Úpatch914575_to3r   ÚHtmlDiffÚ	make_fileÚjoinZ
make_tableÚreplaceÚopenr   r   Úread)r   Zf1aZt1aZf1bZt1bÚf2Zt2Zf3Zt3ÚiÚjÚkZfullZtablesÚactualÚfpr   r   r   Útest_html_diff¸   s\    

zTestSFpatches.test_html_diffc             C   sJ   t  ¡ }dd„ t|d ƒD ƒ}dd„ t|d ƒD ƒ}t d ||¡ ¡  d S )Nc             S   s    g | ]}|d  rdpd| ‘qS )r8   zK:%dzV:A:%dr   )Ú.0rY   r   r   r   ú
<listcomp>ô   s    z6TestSFpatches.test_recursion_limit.<locals>.<listcomp>r8   c             S   s    g | ]}|d  rdpd| ‘qS )r8   zK:%dzV:B:%dr   )r_   rY   r   r   r   r`   õ   s    )ÚsysÚgetrecursionlimitÚranger   r   r   )r   ÚlimitÚoldÚnewr   r   r   Útest_recursion_limitñ   s    z"TestSFpatches.test_recursion_limitc             C   s,   t  ¡ }| t ¡ t ¡ ¡}|  d|¡ d S )Nz"content="text/html; charset=utf-8")r   rR   rS   rK   rM   rL   ÚassertIn)r   Ú	html_diffÚoutputr   r   r   Útest_make_file_default_charsetø   s    

z,TestSFpatches.test_make_file_default_charsetc             C   s0   t  ¡ }|jt ¡ t ¡ dd}|  d|¡ d S )Nz
iso-8859-1)Úcharsetz'content="text/html; charset=iso-8859-1")r   rR   rS   rK   rM   rL   rh   )r   ri   rj   r   r   r   Útest_make_file_iso88591_charsetþ   s
    
z-TestSFpatches.test_make_file_iso88591_charsetc             C   s<   t  ¡ }|jt ¡ t ¡ dd}|  d|¡ |  d|¡ d S )Nzus-ascii)rl   z%content="text/html; charset=us-ascii"z&#305;mpl&#305;c&#305;t)r   rR   rS   Úpatch914575_nonascii_from1rM   Úpatch914575_nonascii_to1rh   )r   ri   rj   r   r   r   Ú2test_make_file_usascii_charset_with_nonascii_input  s    
z@TestSFpatches.test_make_file_usascii_charset_with_nonascii_inputN)r*   r+   r,   r^   rg   rk   rm   rp   r   r   r   r   rB   ¶   s
   9rB   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestOutputFormatc             C   sl   ddddddg}t j|ddiŽ}|  t|ƒd	d
… ddg¡ t j|ddiŽ}|  t|ƒd	d
… ddg¡ d S )NÚoneÚtwoÚOriginalÚCurrentz2005-01-26 23:30:50z2010-04-02 10:20:52ÚlinetermÚ r   r8   z --- Original	2005-01-26 23:30:50z+++ Current	2010-04-02 10:20:52z *** Original	2005-01-26 23:30:50z--- Current	2010-04-02 10:20:52)r   r6   r   r   Úcontext_diff)r   ÚargsÚudÚcdr   r   r   Útest_tab_delimiter  s    z#TestOutputFormat.test_tab_delimiterc             C   sh   ddddg}t j|ddiŽ}|  t|ƒdd… d	d
g¡ t j|ddiŽ}|  t|ƒdd… ddg¡ d S )Nrr   rs   rt   ru   rv   rw   r   r8   z--- Originalz+++ Currentz*** Originalz--- Current)r   r6   r   r   rx   )r   ry   rz   r{   r   r   r   Ú&test_no_trailing_tab_on_empty_filedate  s
    z7TestOutputFormat.test_no_trailing_tab_on_empty_filedatec             C   sh   d}t j}|  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd	¡ |  |d
d
ƒd¡ d S )Na’             Each <range> field shall be of the form:
             %1d", <beginning line number>  if the range contains exactly one line,
           and:
            "%1d,%1d", <beginning line number>, <number of lines> otherwise.
           If a range is empty, its beginning line number shall be the number of
           the line just before the range, or 0 if the empty range starts the file.
        r   z3,0é   Ú4rG   z4,2rJ   z4,3r   z0,0)r   Z_format_range_unifiedr   )r   ÚspecÚfmtr   r   r   Útest_range_format_unified#  s    	z*TestOutputFormat.test_range_format_unifiedc             C   sh   d}t j}|  |ddƒd¡ |  |ddƒd¡ |  |ddƒd¡ |  |ddƒd	¡ |  |d
d
ƒd¡ d S )Na             The range of lines in file1 shall be written in the following format
           if the range contains two or more lines:
               "*** %d,%d ****
", <beginning line number>, <ending line number>
           and the following format otherwise:
               "*** %d ****
", <ending line number>
           The ending line number of an empty range shall be the number of the preceding line,
           or 0 if the range is at the start of the file.

           Next, the range of lines in file2 shall be written in the following format
           if the range contains two or more lines:
               "--- %d,%d ----
", <beginning line number>, <ending line number>
           and the following format otherwise:
               "--- %d ----
", <ending line number>
        r   r@   r~   r   rG   z4,5rJ   z4,6r   Ú0)r   Z_format_range_contextr   )r   r€   r   r   r   r   Útest_range_format_context4  s    z*TestOutputFormat.test_range_format_contextN)r*   r+   r,   r|   r}   r‚   r„   r   r   r   r   rq     s   rq   c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )Ú	TestBytesc             C   s,   t |ƒ}x|D ]}|  |td| ¡ qW d S )Nz.all lines of diff should be bytes, but got: %r)r   ZassertIsInstanceÚbytes)r   r=   Úliner   r   r   ÚcheckP  s
    
zTestBytes.checkc          
   C   s.  ddg}ddg}t j}t j}| j}|t  |||¡ƒ |t  |||¡ƒ |t  |||dd¡ƒ |t  |||dd¡ƒ |t  |||dddd¡ƒ |t  |||dddd¡ƒ |t  |||¡ƒ |t  |||¡ƒ |t  |||dd¡ƒ |t  |||dd¡ƒ |t  |||dddd¡ƒ |t  |||dddd¡ƒ d S )Ns   hellos   andrés   andrÃ©ó   aó   bs   2005s   2013)r   r6   rx   rˆ   Ú
diff_bytes)r   r'   r(   ÚunifiedrH   rˆ   r   r   r   Útest_byte_contentW  s"    zTestBytes.test_byte_contentc          
      sþ   d}d}dg}dg}ˆ j }tj}tj}|t |||||¡ƒ |t |||||¡ƒ ‡ fdd„}ddd	d
dg}	tj|||||dd}
||	|
ƒ d}d}|t |||||||¡ƒ |t |||||||¡ƒ ddd	d
dg}	tj|||||||dd}
||	|
ƒ d S )Ns   ³odz.txts	   Å‚odz.txts   £odz is a city in Poland.s   Åodz is a city in Poland.c                sD   t |ƒ}ˆ  t| ƒt|ƒ¡ x"t| |ƒD ]\}}ˆ  ||¡ q(W d S )N)r   r   ÚlenÚzip)Úexpectr\   Úer'   )r   r   r   Ú
assertDiff‚  s    z1TestBytes.test_byte_filenames.<locals>.assertDiffs   --- ³odz.txts   +++ Å‚odz.txts   @@ -1 +1 @@s   -£odz is a city in Poland.s   +Åodz is a city in Poland.r&   )rv   s
   2005-03-18s
   2005-03-19s   --- ³odz.txt	2005-03-18s   +++ Å‚odz.txt	2005-03-19)rˆ   r   r6   rx   r‹   )r   ÚfnaÚfnbr'   r(   rˆ   rŒ   rH   r’   r   r\   ÚdateaÚdatebr   )r   r   Útest_byte_filenamess  s:    	
zTestBytes.test_byte_filenamesc             C   s´   dg}dg}t j}t j}d}|  ||||¡ |  ||||¡ |  ||||¡ |  ||||¡ d}|  |t j|||¡ |  |t j|||¡ |  |t j|||¡ |  |t j|||¡ d S )Ns   helloZhelloz2lines to compare must be str, not bytes (b'hello')z.all arguments must be bytes, not str ('hello'))r   r6   rx   Ú_assert_type_errorr‹   )r   r'   r(   rŒ   rH   r   r   r   r   Útest_mixed_types_content¨  s    z"TestBytes.test_mixed_types_contentc             C   s.   dg}dg}d}d}|   dtj||||¡ d S )Nzhello
zohell
s   olé.txts	   olÃa9.txtz-all arguments must be str, not: b'ol\xe9.txt')r˜   r   r6   )r   r'   r(   r“   r”   r   r   r   Útest_mixed_types_filenames¼  s    z$TestBytes.test_mixed_types_filenamesc             C   sZ   dg}dg}d}d}|   dtjtj||dd||¡	 dg}d	g}tt ||d
d||¡ƒ d S )Ns   foo
s   bar
u   1 fÃ©vu   3 fÃ©vu/   all arguments must be bytes, not str ('1 fÃ©v')r‰   rŠ   zfoo
zbar
r'   r(   )r˜   r   r‹   r6   r   )r   r'   r(   r•   r–   r   r   r   Útest_mixed_types_datesÈ  s    z TestBytes.test_mixed_types_datesc          	   G   s8   |   t¡}t||Ž ƒ W d Q R X |  |t|jƒ¡ d S )N)r3   Ú	TypeErrorr   r   ÚstrZ	exception)r   ÚmsgÚ	generatorry   Zctxr   r   r   r˜   Ø  s    zTestBytes._assert_type_errorN)
r*   r+   r,   rˆ   r   r—   r™   rš   r›   r˜   r   r   r   r   r…   M  s   5r…   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚTestJunkAPIsc             C   s(   x"dD ]}|   t |¡t|ƒ¡ qW d S )N)ú#z  z #z# z # rw   )Ú
assertTruer   ÚIS_LINE_JUNKÚrepr)r   r‡   r   r   r   Útest_is_line_junk_trueÞ  s    
z#TestJunkAPIs.test_is_line_junk_truec             C   s(   x"dD ]}|   t |¡t|ƒ¡ qW d S )N)z##z ##z## zabc zabc #zMr. Moose is up!)ÚassertFalser   r£   r¤   )r   r‡   r   r   r   Útest_is_line_junk_falseâ  s    
z$TestJunkAPIs.test_is_line_junk_falsec             C   s    dd d }|   t |¡¡ d S )Nú	i@B z##)r¦   r   r£   )r   Z
evil_inputr   r   r   Útest_is_line_junk_REDOSæ  s    z$TestJunkAPIs.test_is_line_junk_REDOSc             C   s(   x"dD ]}|   t |¡t|ƒ¡ qW d S )N)r#   r¨   )r¢   r   ÚIS_CHARACTER_JUNKr¤   )r   Úcharr   r   r   Útest_is_character_junk_trueê  s    
z(TestJunkAPIs.test_is_character_junk_truec             C   s(   x"dD ]}|   t |¡t|ƒ¡ qW d S )N)r'   r¡   rI   úúú)r¦   r   rª   r¤   )r   r«   r   r   r   Útest_is_character_junk_falseî  s    
z)TestJunkAPIs.test_is_character_junk_falseN)r*   r+   r,   r¥   r§   r©   r¬   r°   r   r   r   r   r    Ý  s
   r    c           	   C   s,   dt j_t t ¡} ttttt	t
tt| ƒ d S )Nr   )r   rR   Z_default_prefixÚdoctestZDocTestSuiter   r   r-   rB   r0   rq   r…   r    )ZDoctestsr   r   r   Ú	test_mainò  s
    
r²   Ú__main__)r   Ztest.supportr   r   Zunittestr±   ra   ZTestCaser   r-   r0   rK   rL   rn   ro   rN   rO   rP   rQ   rB   rq   r…   r    r²   r*   r   r   r   r   Ú<module>   s.   &-X? 