o
    gNV                     @   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G dd dejZdd Zedkr}e  dS dS )    N)run_unittestfindfilec                   @   $   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| g d	 | |jt  d S )
NZdbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZeabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbgףp=
?   Z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   G/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_difflib.pytest_one_insert	   s   zTestWithAscii.test_one_insertc                 C   s>   t d dd}| j| ddd | t| g d d S )NZQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbg+?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   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      | dkS N r   xr   r   r   <lambda>!       z*TestWithAscii.test_bjunk.<locals>.<lambda>r   ZTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)Zisjunkabc                 S   r%   r&   r   r(   r   r   r   r*   %   r+   zhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb                    r'   c                 S   s   | dv S )N)r'   r-   r   r(   r   r   r   r*   )   r+   r-   )r   r   r   Zbjunkr   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 )
NZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbZabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbr   r   r   r-   F)ZautojunkgQ?)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/   r0   r1   __doc__r3   r   r   r   r   r2   .   s    r2   c                   @   s<   e Zd Zd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   r6   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 bugr>   z? +
r   r   r   ZDifferZcomparer   r   diffr   r   r   test_added_tab_hintX   s
   zTestSFbugs.test_added_tab_hintc                 C   sL   t t dgdg}| d|d  | d|d  | d|d  d S )	Nz	 	 	^z	 	 	^
z- 	 	 	^r   z	+ 	 	 	^
r	   z
? 	 	 	 +
r>   rC   rD   r   r   r   %test_hint_indented_properly_with_tabs`   s   z0TestSFbugs.test_hint_indented_properly_with_tabsc                 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_iterationf   s   z*TestSFbugs.test_mdiff_catch_stop_iterationN)	r/   r0   r1   r7   r=   rB   rF   rG   rK   r   r   r   r   r5   @   s    	r5   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
zline 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 endzline 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                   @   4   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!d"d#}| ||  W d    d S 1 sw   Y  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
r>   )tabsize   )Z
wrapcolumnfromtoF   )contextZnumlines
z8<h2>Context (first diff within numlines=5(default))</h2>T)rS   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.htmlzutf-8)encoding)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f2t2Zf3Zt3ijkfullZtablesactualfpr   r   r   test_html_diff   sb   

"zTestSFpatches.test_html_diffc                 C   sJ   t  }dd t|d D }dd t|d D }td ||  d S )Nc                 S       g | ]}|d  r
dpd| qS )r>   K:%dzV:A:%dr   .0rf   r   r   r   
<listcomp>        z6TestSFpatches.test_recursion_limit.<locals>.<listcomp>r>   c                 S   rm   )r>   rn   zV:B:%dr   ro   r   r   r   rq      rr   )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   r^   r_   rW   rY   rX   assertInr   Z	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"rz   r|   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-asciir   z%content="text/html; charset=us-ascii"z&#305;mpl&#305;c&#305;t)r   r^   r_   patch914575_nonascii_from1rY   patch914575_nonascii_to1r{   r|   r   r   r   2test_make_file_usascii_charset_with_nonascii_input  s   
z@TestSFpatches.test_make_file_usascii_charset_with_nonascii_inputN)r/   r0   r1   rl   ry   r~   r   r   r   r   r   r   rM      s    9rM   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestOutputFormatc                 C   d   g d}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   r>   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   r<   r   r   context_diffr   argsZudZcdr   r   r   test_tab_delimiter  s   
z#TestOutputFormat.test_tab_delimiterc                 C   r   )
N)r   r   r   r   r   r   r   r>   z--- Originalz+++ Currentz*** Originalz--- Currentr   r   r   r   r   &test_no_trailing_tab_on_empty_filedate!  s
    z7TestOutputFormat.test_no_trailing_tab_on_empty_filedatec                 C   h   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   4rR   z4,2rU   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   r   )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   rI   r   r   rR   z4,5rU   z4,6r   0)r   Z_format_range_contextr   r   r   r   r   test_range_format_context:  s   z*TestOutputFormat.test_range_format_contextN)r/   r0   r1   r   r   r   r   r   r   r   r   r     s
    r   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 |}|D ]}| |td|  qd S )Nz.all lines of diff should be bytes, but got: %r)r   ZassertIsInstancebytes)r   rE   liner   r   r   checkV  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 )N   hellos   andrs   andré   a   bs   2005s   2013)r   r<   r   r   
diff_bytes)r   r,   r-   unifiedrS   r   r   r   r   test_byte_content]  s"   zTestBytes.test_byte_contentc              
      s   d}d}dg}dg} j }tj}tj}|t||||| |t|||||  fdd}g d}	tj|||||dd	}
||	|
 d
}d}|t||||||| |t||||||| g d}	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                    s@   t |} t| t| t| |D ]
\}} || qd S r8   )r   r   lenzip)expectrj   er,   rJ   r   r   
assertDiff  s
   z1TestBytes.test_byte_filenames.<locals>.assertDiff)s   --- odz.txts   +++ łodz.txt   @@ -1 +1 @@   -odz is a city in Poland.   +Łodz is a city in Poland.    )r   s
   2005-03-18s
   2005-03-19)s   --- odz.txt	2005-03-18s   +++ łodz.txt	2005-03-19r   r   r   )r   r   r<   r   r   )r   fnafnbr,   r-   r   r   rS   r   r   rj   dateadatebr   rJ   r   test_byte_filenamesy  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 )Nr   Zhelloz2lines to compare must be str, not bytes (b'hello')z.all arguments must be bytes, not str ('hello'))r   r<   r   _assert_type_errorr   )r   r,   r-   r   rS   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	   ola9.txtz-all arguments must be str, not: b'ol\xe9.txt')r   r   r<   )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   r<   r   )r   r,   r-   r   r   r   r   r   test_mixed_types_dates  s   z TestBytes.test_mixed_types_datesc                 G   sL   |  t}t||  W d    n1 sw   Y  | |t|j d S r8   )r9   	TypeErrorr   r   str	exception)r   msg	generatorr   ctxr   r   r   r     s   zTestBytes._assert_type_errorN)
r/   r0   r1   r   r   r   r   r   r   r   r   r   r   r   r   S  s    5r   c                   @   rL   )TestJunkAPIsc                 C   $   dD ]}|  t|t| qd S )N)#z  z #z# z # r   )
assertTruer   IS_LINE_JUNKreprr   r   r   r   r   test_is_line_junk_true     z#TestJunkAPIs.test_is_line_junk_truec                 C   r   )N)##z ##z## zabc zabc #zMr. Moose is up!)assertFalser   r   r   r   r   r   r   test_is_line_junk_false  r   z$TestJunkAPIs.test_is_line_junk_falsec                 C   s    dd d }|  t| d S )N	i@B r   )r   r   r   )r   Z
evil_inputr   r   r   test_is_line_junk_REDOS  s   z$TestJunkAPIs.test_is_line_junk_REDOSc                 C   r   )N)r'   r   )r   r   IS_CHARACTER_JUNKr   r   charr   r   r   test_is_character_junk_true  r   z(TestJunkAPIs.test_is_character_junk_truec                 C   r   )N)r,   r   rT   )r   r   r   r   r   r   r   r   test_is_character_junk_false  r   z)TestJunkAPIs.test_is_character_junk_falseN)r/   r0   r1   r   r   r   r   r   r   r   r   r   r     s    r   c                   @   r   )TestFindLongestc                    s8   t  fddfddtdt d D D S )Nc                 3   s    | ]}| v V  qd S r8   r   )rp   Zb_part)r,   r   r   	<genexpr>  s    z6TestFindLongest.longer_match_exists.<locals>.<genexpr>c                    s    g | ]} || d   qS )r	   r   ro   )r-   nr   r   rq     rr   z7TestFindLongest.longer_match_exists.<locals>.<listcomp>r   r	   )anyru   r   )r   r,   r-   r   r   )r,   r-   r   r   longer_match_exists  s   $z#TestFindLongest.longer_match_existsc                 C   s  d}d}t j||d}| }| |jd | |jd | |jd | ||j|j|j  ||j|j|j   | | |||j |jddd}| |jd	 | |jd
 | |jd | ||j|j|j  ||j|j|j   | | |dd  |dd  |j |jddd}| |jd | |jd | |jd | ||j|j|j  ||j|j|j   | | ||dd |j d S )Nzfoo barzfoo baz barr,   r-   r   rU   r>   r   )Zaloblor      rR   r	   )Zbhir   )	r   r   find_longest_matchr   r,   r-   r?   r   r   r   r,   r-   r   matchr   r   r   test_default_args  s6   &"z!TestFindLongest.test_default_argsc                 C   s   d}d}t j||d}|dt|dt|}| |jd | |jd | |jd | ||j|j|j  ||j|j|j   | | 	|||j d S )NZdabcdZddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddabcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddr   r   c   rR   )
r   r   r   r   r   r,   r-   r?   r   r   r   r   r   r   %test_longest_match_with_popular_chars  s   z5TestFindLongest.test_longest_match_with_popular_charsN)r/   r0   r1   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t| 	 d S )Nr   )r   r^   Z_default_prefixdoctestZDocTestSuiter   r   r2   rM   r5   r   r   r   r   )ZDoctestsr   r   r   	test_main&  s   

r   __main__)r   Ztest.supportr   r   Zunittestr   rs   ZTestCaser   r2   r5   rW   rX   r   r   rZ   r[   r\   r]   rM   r   r   r   r   r   r/   r   r   r   r   <module>   s4    &.X? .
