
    i!                    X   d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ej                            ed          Zej                            ed          Zej                            ed          Z G d d	e
j                  Zed
k    r e
j                     dS dS )zFIntegration tests for misc/diff-cache.py and misc/apply-cache-diff.py.    )annotationsN)PREFIXmisczdiff-cache.pyzapply-cache-diff.pyc                      e Zd ZdZddZdS )DiffCacheIntegrationTestszKRun mypy twice with different sources, diff the caches, and apply the diff.returnNonec                    t          j                    }t          j                            t          j                    d          }t          j                                        }t          |d<   	 t          j                            |d          t          j                            |d          }t          t          j                            |d          d          5 }|	                    d           d d d            n# 1 swxY w Y   t          t          j                            |d          d          5 }|	                    d	           d d d            n# 1 swxY w Y   t          j        t          j        d
dddddg|dd|          }|j        dk    sJ d|j                     t!          j        d           t          j        t          j                            |d                     t          t          j                            |d          d          5 }|	                    d           d d d            n# 1 swxY w Y   t          t          j                            |d          d          5 }|	                    d           d d d            n# 1 swxY w Y   t          j        t          j        d
dddd|ddg	|dd|          }|j        dk    sJ d|j                     fdt          j                  D             }t)          |          dk    sJ d|             |d         }t          j        t          j        t*          dt          j                            |          t          j                            ||          |gdd|          }|j        dk    sJ d|j                     t          |          5 }t-          j        |          }	d d d            n# 1 swxY w Y   t1          |	t2                    sJ t)          |	          dk    s
J d            t5          |	                                          }
d |
D             }d |
D             }d  |
D             }t)          |          dk    sJ d!|             t)          |          d"k    sJ d#|             t)          |          d$k    sJ d%|             d&|
v sJ t-          j        |	d&                   }t5          |                                          d'd(hk    s,J d)t;          |                                                       t;          |d'                   d*gk    sJ t;          |d(                   d*d+gk    sJ t          j                            ||          }t          j                            |d,          }t          j                            ||          }t=          j        |           dd-l m! d@fd2} ||          }t          j        t          j        tD          d||gdd|          }|j        dk    sJ d3|j                      ||          }|D ]K}|#                    d4          sd5|v r0||v sJ | d6            ||         ||         k    sJ | d7            L ||          }d8D ]}|D ]}|#                    |          sd9| |v s||v sJ | d6            |$                    d:          r-||         |%                    |          k    sJ | d;            r||         ||         k    sJ | d<            dd=l&m'}  ||d&                   }t5          |                                          d'd(hk    s,J d>t;          |                                                       t;          |d'                   d*gk    sJ t;          |d(                   d*d+gk    sJ 	 t=          j(        |d?           t=          j(        t          j        )                    |          d?           d S # t=          j(        |d?           t=          j(        t          j        )                    |          d?           w xY w)ANz	diff.json
PYTHONPATHcache1cache2za.pywzx: int = 1
zb.pyz(import a
def foo() -> int:
    return 1
z-mmypyz--sqlite-cachez--cache-fine-grainedz--cache-dirT)cwdcapture_outputtextenvr   zmypy run 1 failed:    z/import a
def foo() -> str:
    return str(a.x)
zc.pyzimport a
y: str = 'world'
zmypy run 2 failed: c                    g | ][}t           j                            t           j                            |                    ?|d                                          Y|\S )r   )ospathisdirjoinisdigit).0er   s     X/root/projects/qq-shell/venv/lib64/python3.11/site-packages/mypy/test/test_diff_cache.py
<listcomp>zQDiffCacheIntegrationTests.test_diff_cache_produces_valid_json.<locals>.<listcomp>[   sd       7==fa!8!899 ?@dllnn      z!Expected one version subdir, got z--sqlite)r   r   r   zdiff-cache.py failed: zExpected non-empty diffc                D    h | ]}d |v s|                     d          |S )z/b.b.
startswithr   ks     r   	<setcomp>zPDiffCacheIntegrationTests.test_diff_cache_produces_valid_json.<locals>.<setcomp>}   -    JJJA!q||D7I7Iar   c                D    h | ]}d |v s|                     d          |S )z/c.c.r"   r$   s     r   r&   zPDiffCacheIntegrationTests.test_diff_cache_produces_valid_json.<locals>.<setcomp>~   r'   r   c                D    h | ]}d |v s|                     d          |S )/a.a.r"   r$   s     r   r&   zPDiffCacheIntegrationTests.test_diff_cache_produces_valid_json.<locals>.<setcomp>   r'   r   z Unexpected a.* entries in diff:    z%Expected 2 b.* entries in diff, got:    z%Expected 3 c.* entries in diff, got: z@root.deps.jsonz<a.x>z<a>zUnexpected root deps keys: zb.foocpatched)SqliteMetadataStore	cache_dirstrr   dict[str, bytes]c                     |           fd                                 D             }j        J j                                         |S )Nc                <    i | ]}|                     |          S  )read)r   namestores     r   
<dictcomp>zcDiffCacheIntegrationTests.test_diff_cache_produces_valid_json.<locals>.read_all.<locals>.<dictcomp>   s'    NNNT$

4 0 0NNNr   )list_alldbclose)r2   resultr:   r1   s     @r   read_allzODiffCacheIntegrationTests.test_diff_cache_produces_valid_json.<locals>.read_all   s\    ++I66NNNNU^^=M=MNNNx+++   r   zapply-cache-diff.py failed: r,   r+   z missing after applyz changed after apply)r!   r)   /z.meta.ffz unchanged after applyz differs from target)
json_loadsz#Unexpected applied root deps keys: )ignore_errors)r2   r3   r   r4   )*tempfilemkdtempr   r   r   environcopyr   openwrite
subprocessrunsys
executable
returncodestderrtimesleeputimelistdirlen_DIFF_CACHE_PATHjsonload
isinstancedictsetkeysloadssortedshutilcopytreemypy.metastorer1   _APPLY_CACHE_DIFF_PATHr#   endswithget	mypy.utilrB   rmtreedirname)selfsrc_diroutput_filer   r   fr?   subdirsverdatar[   b_keysc_keysa_keys	root_deps
cache2_verr0   patched_verr@   beforeafterr9   targetprefixrB   applied_root_depsr1   r   s                             @@r   #test_diff_cache_produces_valid_jsonz=DiffCacheIntegrationTests.test_diff_cache_produces_valid_json   s
    "$$gll8#3#5#5{CCjoo"Lm	LW\\'844FW\\'844F bgll7F33S99 (Q'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (bgll7F33S99 GQEFFFG G G G G G G G G G G G G G G^N$*!	 #  F  $)))+P+P+P))) JqMMM HRW\\'622333 bgll7F33S99 NQLMMMN N N N N N N N N N N N N N Nbgll7F33S99 8Q67778 8 8 8 8 8 8 8 8 8 8 8 8 8 8^N$*!
 #  F" $)))+P+P+P)))   F++  G
 w<<1$$$&S'&S&S$$$!*C  ^N$GLL--GLL--  $  F $)))+SFM+S+S))) k"" $ay||$ $ $ $ $ $ $ $ $ $ $ $ $ $ $dD)))))t99q===";===
 tyy{{##DJJJJJFJJJJJFJJJJJFv;;!###%P%P%P###v;;!###%UV%U%U###v;;!###%UV%U%U### %,,,,
4(9#:;;Iy~~''((-    HVINN4D4D-E-EGG   )G,--'::::)E*++~==== fc22Jgll7I66G',,w44KOFG,,, ;:::::      Xk**F  ^!7[R]^#	  F $)))+Y&-+Y+Y)))H[))E  V V??4(( VETMM5===T*G*G*G===!$<5;66648U8U8U666 Xj))F& 
Z 
Z" 	Z 	ZD OOF33 !|6||t7K7K 5===T*G*G*G===}}Z00 Z  %T{fjj.>.>>>>4@_@_@_>>>>$T{fTl:::t<Y<Y<Y::::	Z -,,,,, *
51B+C D D(--//005    XV<M<R<R<T<T5U5UWW   +G455'BBBB+E233~EEEEEM'6666M"'//+66dKKKKKK M'6666M"'//+66dKKKKKs   0A.a D 4a  Da D1a 9Ea Ea "E#B?a "I8a Ia I1a =Ja J##a &J#'D)a O1%a 1O55a 8O59O=a AbN)r   r	   )__name__
__module____qualname____doc__ry   r7   r   r   r   r      s:        UUuL uL uL uL uL uLr   r   __main__)r}   
__future__r   rV   r   r^   rJ   rL   rD   rP   unittestmypy.test.configr   r   r   	_MISC_DIRrU   ra   TestCaser   rz   mainr7   r   r   <module>r      s    L L " " " " " "  				      



    # # # # # #GLL((	7<<	?;; i1FGG xL xL xL xL xL 1 xL xL xLv zHMOOOOO r   