o
    tBhQ                     @  s  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
mZ d dlmZ d dlmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% d d	l&m'Z'm(Z(m)Z)m*Z*m+Z+ d d
l,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 G dd de	j7Z8G dd de	j7Z9G dd de	j7Z:G dd de	j7Z;G dd de2Z<eddZ=G dd dZ>G dd de>Z?G dd de	j7Z@G dd  d e	j7ZAG d!d" d"e	j7ZBG d#d$ d$e	j7ZCd+d)d*ZDdS ),    )annotationsN)
ModuleType)Any)CompileError)InspectErrorModuleInspect)
ArgSigFunctionSigbuild_signaturefind_unique_signatures!infer_arg_sig_from_anon_docstringinfer_prop_type_from_docstringinfer_sig_from_docstringis_valid_typeparse_all_signaturesparse_signature)Optionscollect_build_targetsgenerate_stubsis_blacklisted_pathis_non_library_modulemypy_optionsparse_options)generate_c_function_stubgenerate_c_property_stubgenerate_c_type_stubinfer_method_sigis_c_property_readonly)common_dir_prefixremove_misplaced_type_commentswalk_packages)DataDrivenTestCase	DataSuite)assert_equalassert_string_arrays_equallocal_sys_path_setc                      s   e Zd ZdZeejdkddddZeejdkdddd	Z	eejdkddd
dZ
dddddZdd fddZ  ZS )StubgenCmdLineSuitezATest cases for processing command-line options and finding files.win32zclean up fails on WindowsreturnNonec              
   C  s  t  }t p}z`t | t d | dd | dd t t jdd | ddd t	dg}t
|t|\}}t|g  dd |D }t|t jdddt jddt jddh W t | nt | w W d    d S 1 s{w   Y  d S )Nsubdira.pyb.pypack__init__.pyc                 S  s   h | ]}|j qS  )path.0modr/   r/   l/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/test/teststubgen.py	<setcomp>A   s    z7StubgenCmdLineSuite.test_files_found.<locals>.<setcomp>)osgetcwdtempfileTemporaryDirectorychdirmkdir	make_filer0   joinr   r   r   r#   selfcurrenttmpoptspy_modsc_modsfilesr/   r/   r4   test_files_found3   s,   




	"z$StubgenCmdLineSuite.test_files_foundc              
   C  s   t  }t g}zWt | t d | jdddd | dd | dd tddg}t|t	|\}}t
|g  dd	 |D }t
|t jddt jddt jddh W t | nt | w W d    d S 1 srw   Y  d S )
Nr-   r.   zfrom . import a, bcontentr+   r,   z-pc                 S  s   h | ]}t j|jpd qS )FAIL)r6   r0   relpathr1   r/   r/   r4   r5   Z   s    z:StubgenCmdLineSuite.test_packages_found.<locals>.<setcomp>)r6   r7   r8   r9   r:   r;   r<   r   r   r   r#   r0   r=   r>   r/   r/   r4   test_packages_foundM   s*   



	"z'StubgenCmdLineSuite.test_packages_foundc              
   C  s   t  }t }|t_t C}z/t | | j	|ddd t
ddg}t|t|\}}| dks5J W tjt_t | n
tjt_t | w W d    d S 1 sUw   Y  d S )Nzmymodule.pyzimport arG   -mmymodule )r6   r7   ioStringIOsysstdoutr8   r9   r:   r<   r   r   r   getvalue
__stdout__)r?   r@   captured_outputrA   rB   rC   rD   r/   r/   r4   test_module_not_foundf   s   

"z)StubgenCmdLineSuite.test_module_not_foundrN   rG   r0   strrH   c                G  sF   t jj| }t|d}|| W d    d S 1 sw   Y  d S )Nw)r6   r0   r=   openwrite)r?   rH   r0   filefr/   r/   r4   r<   v   s   "zStubgenCmdLineSuite.make_fileNresult
Any | Nonec                   s6   t   t |W  d    S 1 sw   Y  d S N)r%   superrun)r?   r]   	__class__r/   r4   ra   {   s   
$zStubgenCmdLineSuite.runr(   r)   )r0   rW   rH   rW   r(   r)   r_   )r]   r^   r(   r^   )__name__
__module____qualname____doc__unittestskipIfrQ   platformrF   rK   rV   r<   ra   __classcell__r/   r/   rb   r4   r&   0   s    r&   c                   @     e Zd ZdddZdS )StubgenCliParseSuiter(   r)   c                 C  s   t  5}ttt|dgdh ttt|ddgddh tt|dg}| |h d W d    d S 1 s;w   Y  d S )Nmypy.errorsmypy.stubgenmypy>   	mypy.testmypy.test.helpersrq   ro   rp   )r   r#   setr    
assertTrue
issuperset)r?   mall_mypy_packagesr/   r/   r4   test_walk_packages   s   "z'StubgenCliParseSuite.test_walk_packagesNrd   )re   rf   rg   ry   r/   r/   r/   r4   rn          rn   c                   @  s8  e Zd ZdZd@ddZd@ddZd@dd	Zd@d
dZd@ddZd@ddZ	d@ddZ
d@ddZdAddZd@ddZd@ddZd@ddZd@d d!Zd@d"d#Zd@d$d%Zd@d&d'Zd@d(d)Zd@d*d+Zd@d,d-Zd@d.d/Zd@d0d1Zd@d2d3Zd@d4d5Zd@d6d7Zeejd8kd9d@d:d;Z eejd8kd<d@d=d>Z!d?S )BStubgenUtilSuitez)Unit tests for stubgen utility functions.r(   r)   c                 C  s   |  ddg g f d S )Nzfunc()funcassert_parse_signaturer?   r/   r/   r4   test_parse_signature   s   z%StubgenUtilSuite.test_parse_signaturec                 C  s.   |  dddgg f |  ddddgg f d S )Nz	func(arg)r|   argzdo(arg, arg2)doarg2r}   r   r/   r/   r4   test_parse_signature_with_args   s   z/StubgenUtilSuite.test_parse_signature_with_argsc                 C  D   |  ddg dgf |  dddgdgf |  ddg ddgf d S )Nzfunc([arg])r|   r   zfunc(arg[, arg2])r   zfunc([arg[, arg2]])r}   r   r/   r/   r4   'test_parse_signature_with_optional_args      z8StubgenUtilSuite.test_parse_signature_with_optional_argsc                 C  r   )Nzfunc(arg=None)r|   r   zfunc(arg, arg2=None)r   zfunc(arg=1, arg2="")r}   r   r/   r/   r4   %test_parse_signature_with_default_arg   r   z6StubgenUtilSuite.test_parse_signature_with_default_argc                 C  s   |  dddgg f d S )NzClassName.func(arg)r|   r   r}   r   r/   r/   r4   ,test_parse_signature_with_qualified_function   s   z=StubgenUtilSuite.test_parse_signature_with_qualified_functionc                 C  s   |  ddddgdgf d S )NzClassName.func(arg, *, arg2=1)r|   r   *r   r}   r   r/   r/   r4   %test_parse_signature_with_kw_only_arg   s   z6StubgenUtilSuite.test_parse_signature_with_kw_only_argc                 C     |  ddddgg f d S )NzClassName.func(arg, *args)r|   r   *argsr}   r   r/   r/   r4   "test_parse_signature_with_star_arg      z3StubgenUtilSuite.test_parse_signature_with_star_argc                 C  r   )NzClassName.func(arg, **args)r|   r   z**argsr}   r   r/   r/   r4   'test_parse_signature_with_star_star_arg   r   z8StubgenUtilSuite.test_parse_signature_with_star_star_argsigrW   r]    tuple[str, list[str], list[str]]c                 C  s   t t|| d S r_   )r#   r   )r?   r   r]   r/   r/   r4   r~      s   z'StubgenUtilSuite.assert_parse_signaturec                 C  sd   t tg g d t tdgg d t tddgg d t tdgdgd t tdgddgd d S )	N()r   (arg)r   (arg, arg2)z(arg, arg2=...)z**xz(arg, arg2=..., **x))r#   r
   r   r/   r/   r4   test_build_signature   s
   z%StubgenUtilSuite.test_build_signaturec                 C  s   t tg dddgg f d S )N)zrandom textz.. function:: fn(argz.. function:: fn()z  .. method:: fn2(arg))fnr   )fn2r   )r#   r   r   r/   r/   r4   test_parse_all_signatures   s   
z*StubgenUtilSuite.test_parse_all_signaturesc                 C  s   t tg dddg d S )N)r|   r   r   )func2r   )r   r   func3r   r   r   )r#   r   r   r/   r/   r4   test_find_unique_signatures   s   	z,StubgenUtilSuite.test_find_unique_signaturesc              	   C  s8  t tddtdtddgddg t tddtdtddgddg t tddtdtddtd	d
dgddg t tddtdtddtd	d
dgddg t tddtdtddtd	d
dgddg t tddg  t tddg  t tddtdtdd
dgddg t tddg  t tddtdtdddgddg t tddtdtddd
dgddg t tddtdtdd d
dgddg t tddtdg ddg t tddtdtddd
dgddg t tddtdtddd
dgddg t tddtdtdddgddg t tddtdtdddtd ddgddg t td!dtdtdd"dgddg t td#dtdtdd$d
dgddg t td%dtdtddd
dgddg t td&dg  t td'dtdtdd dgddg t td(dtdtddd
dgddg d S ))Nz
func(x) - yr|   xnamer   r   argsret_typez
func(x)z
func(x, Y_a=None)Y_aT)r   defaultz
func(x, Y_a=3)z
func(x, Y_a=[1, 2, 3])z
afunc(x) - yz

func(x, yz
func(x=z(y))z
func xz
func(x: int)int)r   typez
func(x: int=3)r   r   r   z

func(x=3)z
func() -> intz
func(x: int=3) -> intz
func(x: int=3) -> int   
z 
func(x: Tuple[int, str]) -> strzTuple[int,str]rW   z9
func(x: Tuple[int, Tuple[str, int], str], y: int) -> strTuple[int,Tuple[str,int],str]yz
func(x: foo.bar)foo.barz
func(x: list=[1,2,[3,4]])listz
func(x: str="nasty[")z
func[(x: foo.bar, invalid]z&
func(x: invalid::type<with_template>)z
func(x: str="")r#   r   r	   r   r   r/   r/   r4   test_infer_sig_from_docstring   s   					

		z.StubgenUtilSuite.test_infer_sig_from_docstringc                 C  s0   t tddtdtddtddgddg d S )Nz$
func(x, x) -> str
func(x, y) -> intr|   r   r   r   r   r   r   r   r/   r/   r4   ,test_infer_sig_from_docstring_duplicate_argsz  s   z=StubgenUtilSuite.test_infer_sig_from_docstring_duplicate_argsc                 C  s   t tddd  d S )Nz:
            x
              x
             x
            r|   )r#   r   r   r/   r/   r4   -test_infer_sig_from_docstring_bad_indentation  s   z>StubgenUtilSuite.test_infer_sig_from_docstring_bad_indentationc                 C  sH   t tdtddtddg t tdtdddd	td
ddd	g d S )Nz(*args, **kwargs)r   r   z**kwargszB(x: Tuple[int, Tuple[str, int], str]=(1, ('a', 2), 'y'), y: int=4)r   r   Tr   r   r   )r#   r   r   r   r/   r/   r4   &test_infer_arg_sig_from_anon_docstring  s   z7StubgenUtilSuite.test_infer_arg_sig_from_anon_docstringc                 C  s<   t tdd t tdd t tdd t tdd  d S )Nzstr: A string.rW   zOptional[int]: An int.zOptional[int]zTuple[int, int]: A tuple.zTuple[int, int]z
str: A string.)r#   r   r   r/   r/   r4   #test_infer_prop_type_from_docstring  s   z4StubgenUtilSuite.test_infer_prop_type_from_docstringc                 C  s   t ddg ks	J d S )Nz*fetch_row([maxrows, how]) -- Fetches stuff	fetch_row)r   r   r/   r/   r4   -test_infer_sig_from_docstring_square_brackets  s   z>StubgenUtilSuite.test_infer_sig_from_docstring_square_bracketsc                 C  s   d}t t|| d S )Nu   
        ሴ
        def f(x):  # type: (int) -> int

        def g(x):
            # type: (int) -> int

        def h():

            # type: () int

        x = 1  # type: int
        r#   r   )r?   goodr/   r/   r4   %test_remove_misplaced_type_comments_1  s   z6StubgenUtilSuite.test_remove_misplaced_type_comments_1c                 C     d}d}t t|| d S )Nz
        def f(x):
            # type: Callable[[int], int]
            pass

        #  type:  "foo"
        #  type:  'bar'
        x = 1
        # type: int
        z?
        def f(x):

            pass



        x = 1

        r   r?   bad	bad_fixedr/   r/   r4   %test_remove_misplaced_type_comments_2     

z6StubgenUtilSuite.test_remove_misplaced_type_comments_2c                 C  r   )Nz
        def f(x):
            """docstring"""
            # type: (int) -> int
            pass

        def g(x):
            """docstring
            """
            # type: (int) -> int
            pass
        z
        def f(x):
            """docstring"""

            pass

        def g(x):
            """docstring
            """

            pass
        r   r   r/   r/   r4   %test_remove_misplaced_type_comments_3     z6StubgenUtilSuite.test_remove_misplaced_type_comments_3c                 C  r   )Nz
        def f(x):
            '''docstring'''
            # type: (int) -> int
            pass

        def g(x):
            '''docstring
            '''
            # type: (int) -> int
            pass
        z
        def f(x):
            '''docstring'''

            pass

        def g(x):
            '''docstring
            '''

            pass
        r   r   r/   r/   r4   %test_remove_misplaced_type_comments_4  r   z6StubgenUtilSuite.test_remove_misplaced_type_comments_4c                 C  r   )Nz
        def f(x):
            # type: (int, List[Any],
            #        float, bool) -> int
            pass

        def g(x):
            # type: (int, List[Any])
            pass
        z{
        def f(x):

            #        float, bool) -> int
            pass

        def g(x):

            pass
        r   r   r/   r/   r4   %test_remove_misplaced_type_comments_5	  r   z6StubgenUtilSuite.test_remove_misplaced_type_comments_5c                 C  r   )Ns   
        
        def f(x):  # type: (int) -> int

        def g(x):
            # type: (int) -> int
            pass

        def h():
            # type: int
            pass

        x = 1  # type: int
        s   
        
        def f(x):  # type: (int) -> int

        def g(x):
            # type: (int) -> int
            pass

        def h():

            pass

        x = 1  # type: int
        r   )r?   originaldestr/   r/   r4   )test_remove_misplaced_type_comments_bytes   s   z:StubgenUtilSuite.test_remove_misplaced_type_comments_bytesr'   z0Tests building the paths common ancestor on *nixc                 C  s   t g dksJ t dgdksJ t dgdksJ t dgdks#J t ddgdks-J t ddgdks7J t d	dgdksAJ t d
dgdksKJ t d	dgdksUJ t d
dgdks_J t ddgdksiJ t dgdksrJ t dgdks{J d S )N.x.pyiz./x.pyifoo/bar/x.pyizfoo/barzfoo/bar/y.pyiz	foo/y.pyifooz	foo/x.pyizfoo/bar/zar/x.pyizfoo/bar/zar/y.pyifoo/bar\x.pyifoo\bar/x.pyifoo\barr   r   r/   r/   r4   test_common_dir_prefix_unixA  s   z,StubgenUtilSuite.test_common_dir_prefix_unixz3Tests building the paths common ancestor on Windowsc                 C  s   t dgdks	J t dgdksJ t dgdksJ t ddgdks%J t ddgdks/J t d	dgdks9J t d
dgdksCJ t d	dgdksMJ t d
dgdksWJ t ddgdksaJ t dgdksjJ t dgdkssJ t dgdks|J d S )Nr   r   z.\x.pyizfoo\bar\x.pyir   zfoo\bar\y.pyiz	foo\y.pyir   z	foo\x.pyizfoo\bar\zar\x.pyizfoo\bar\zar\y.pyir   r   r   r   r   r/   r/   r4   test_common_dir_prefix_winQ  s   z+StubgenUtilSuite.test_common_dir_prefix_winNrd   )r   rW   r]   r   r(   r)   )"re   rf   rg   rh   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri   rj   rQ   rk   r   r   r/   r/   r/   r4   r{      sB    












 
"









!
r{   c                   @  s    e Zd ZdddZdddZdS )	StubgenHelpersSuiter(   r)   c                 C  sd   t drJ t drJ t drJ t drJ t dsJ t ds$J t ds*J t ds0J d S )	Nz
foo/bar.pyzfoo.pyzfoo/xvendor/bar.pyzfoo/vendorx/bar.pyzfoo/vendor/bar.pyzfoo/vendored/bar.pyzfoo/vendored/bar/thing.pyz
foo/six.py)r   r   r/   r/   r4   test_is_blacklisted_pathe  s   z,StubgenHelpersSuite.test_is_blacklisted_pathc                 C  s   t drJ t drJ t drJ t drJ t drJ t ds$J t ds*J t ds0J t d	s6J t d
s<J t dsBJ t dsHJ t dsNJ t dsTJ t dsZJ t ds`J t dsfJ t dslJ t dsrJ t dsxJ d S )Nr   r   zfoo.bartestzfoo.bartestszfoo.testbarzfoo.testzfoo.test.fooz	foo.testszfoo.tests.foozfoo.testing.foozfoo.SelfTest.foozfoo.test_barzfoo.bar_testszfoo.testingzfoo.conftestzfoo.bar_test_utilzfoo.bar_test_utilszfoo.bar_test_basez	foo.setupzfoo.__main__)r   r   r/   r/   r4   test_is_non_library_moduleo  s(   z.StubgenHelpersSuite.test_is_non_library_moduleNrd   )re   rf   rg   r   r   r/   r/   r/   r4   r   d  s    

r   c                   @  sP   e Zd ZdZdZdZdgZdd	d
ZdddZdddZ	dddZ
d ddZdS )!StubgenPythonSuitea'  Data-driven end-to-end test cases that generate stub files.

    You can use these magic test case name suffixes:

    *_semanal
        Run semantic analysis (slow as this uses real stubs -- only use
        when necessary)
    *_import
        Import module and perform runtime introspection (in the current
        process!)

    You can use these magic comments:

    # flags: --some-stubgen-option ...
        Specify custom stubgen options

    # modules: module1 module2 ...
        Specify which modules to output (by default only 'main')
    Tr   zstubgen.testtestcaser!   r(   r)   c                 C  s6   t   | | W d    d S 1 sw   Y  d S r_   )r%   run_case_inner)r?   r   r/   r/   r4   run_case  s   "zStubgenPythonSuite.run_casec              
   C  s  g }g }d |j}|jd|fg D ]E\}}|dd dd}|dr-|d\}}}|| d|vr=|d	|g t|d
}	|		| W d    n1 sRw   Y  q| 
||}
| |}d}zlz0|jdspd|
_|jdsyd|
_t|
 g }|D ]}t||}| j||t|dkd qW n ty } z	|j}W Y d }~nd }~ww t|j|d|j d|j d W |D ]}|tjv rtj|= qt| d S |D ]}|tjv rtj|= qt| w )N
z	./main.py   /r   z	.__init__z-p rL   rX   out_importT_semanal   )headerzInvalid output (z, line ))r=   inputrE   replaceendswith
rpartitionappendextendrY   rZ   parse_flagsparse_modulesr   	no_import
parse_onlyr   module_to_pathadd_filelenr   messagesr$   outputr[   linerQ   modulesshutilrmtree)r?   r   extramodssourcer[   rH   r3   _r\   optionsr   out_diramodulefnamer/   r/   r4   r     s\   





z!StubgenPythonSuite.run_case_innerprogram_textrW   r   	list[str]r   c                 C  sR   t jd|t jd}|r|d }ng }t|| }d|vr$d|_|S d|_|S )Nz# flags: (.*)$flagsr   z	--verboseT)research	MULTILINEgroupsplitr   quietverbose)r?   r   r   r  	flag_listr   r/   r/   r4   r     s   zStubgenPythonSuite.parse_flagsc                 C  s*   t jd|t jd}|r|d S dgS )Nz# modules: (.*)$r   r   main)r  r  r  r  r  )r?   r   r   r/   r/   r4   r     s   z StubgenPythonSuite.parse_modulesr0   r]   r   boolc                 C  s   t j|s|d|dd  d S |r!|d|dd    t|dd}||   W d    d S 1 s<w   Y  d S )Nz<%s was not generated>\r   z#    utf8)encoding)	r6   r0   existsr   r   rY   r   read
splitlines)r?   r0   r]   r   r[   r/   r/   r4   r     s   "zStubgenPythonSuite.add_fileN)r   r!   r(   r)   )r   rW   r   r   r(   r   )r   rW   r(   r   )r0   rW   r]   r   r   r  r(   r)   )re   rf   rg   rh   required_out_section	base_pathrE   r   r   r   r   r   r/   r/   r/   r4   r     s    


(
r   r?   r   c                   @     e Zd ZdS )TestBaseClassNre   rf   rg   r/   r/   r/   r4   r        r  c                   @  r  )	TestClassNr  r/   r/   r/   r4   r    r  r  c                   @  s  e Zd ZdZd;ddZd;ddZd;dd	Zd;d
dZd;ddZd;ddZ	d;ddZ
d;ddZd;ddZd;ddZd;ddZd;ddZd;ddZd;ddZd;d d!Zd;d"d#Zd;d$d%Zd;d&d'Zd;d(d)Zd;d*d+Zd;d,d-Zd;d.d/Zd;d0d1Zd;d2d3Zd;d4d5Zd;d6d7Zd;d8d9Zd:S )<StubgencSuitezoUnit tests for stub generation from C modules using introspection.

    Note that these don't cover a lot!
    r(   r)   c                 C  s   t tdtg d S )N__hash__r#   r   self_argr   r/   r/   r4   test_infer_hash_sig  s   z!StubgencSuite.test_infer_hash_sigc                 C  s   t tdttddg d S )N__getitem__indexr   r#   r   r  r   r   r/   r/   r4   test_infer_getitem_sig  s   z$StubgencSuite.test_infer_getitem_sigc                 C  s$   t tdttddtddg d S )N__setitem__r   r   objectr!  r   r/   r/   r4   test_infer_setitem_sig  s   z$StubgencSuite.test_infer_setitem_sigc                 C  s.   dD ]}t td| dttddg qd S )N)eqneltlegtgeaddraddsubrsubmulrmul__otherr   r!  r?   opr/   r/   r4   test_infer_binary_op_sig  s   "z&StubgencSuite.test_infer_binary_op_sigc                 C  s&   dD ]}t td| dtg qd S )N)negposr2  r  r4  r/   r/   r4   test_infer_unary_op_sig  s   z%StubgencSuite.test_infer_unary_op_sigc                 C  s>   g }t dd}g }t|dt|| t|g  t|d d d S )Nr   rN   aliasr   zclass alias:)r   r   r$  r#   )r?   r   r3   importsr/   r/   r4   -test_generate_c_type_stub_no_crash_for_object"  s   

z;StubgencSuite.test_generate_c_type_stub_no_crash_for_objectc                 C  sL   G dd d}g }g }t dd}t|d||| t|g  t|ddg d S )Nc                   @  s   e Zd ZdZdS )z^StubgencSuite.test_generate_c_type_stub_variable_type_annotation.<locals>.TestClassVariableClsr   N)re   rf   rg   r   r/   r/   r/   r4   TestClassVariableCls,  s    r=  r   rN   Czclass C:z    x: ClassVar[int] = ...)r   r   r#   )r?   r=  r   r;  r3   r/   r/   r4   2test_generate_c_type_stub_variable_type_annotation*  s   

z@StubgencSuite.test_generate_c_type_stub_variable_type_annotationc                 C  sJ   G dd dt }g }g }td}t|d||| t|dg t|g  d S )Nc                   @  r  )zAStubgencSuite.test_generate_c_type_inheritance.<locals>.TestClassNr  r/   r/   r/   r4   r  7  r  r  zmodule, r>  zclass C(KeyError): ...)KeyErrorr   r   r#   r?   r  r   r;  r3   r/   r/   r4    test_generate_c_type_inheritance6  s   z.StubgencSuite.test_generate_c_type_inheritancec                 C  s>   g }g }t tjd}t|dt|| t|dg t|g  d S )NrN   r>  zclass C(TestBaseClass): ...)r   r  rf   r   r  r#   )r?   r   r;  r3   r/   r/   r4   ,test_generate_c_type_inheritance_same_moduleA  s   z:StubgencSuite.test_generate_c_type_inheritance_same_modulec                 C  sX   dd l }G dd d|j}g }g }tdd}t|d||| t|dg t|dg d S )	Nr   c                   @  r  )zNStubgencSuite.test_generate_c_type_inheritance_other_module.<locals>.TestClassNr  r/   r/   r/   r4   r  L  r  r  r   rN   r>  zclass C(argparse.Action): ...import argparse)argparseActionr   r   r#   )r?   rE  r  r   r;  r3   r/   r/   r4   -test_generate_c_type_inheritance_other_moduleI  s   
z;StubgencSuite.test_generate_c_type_inheritance_other_modulec                 C  sL   G dd dt }g }g }tdd}t|d||| t|dg t|g  d S )Nc                   @  r  )zNStubgencSuite.test_generate_c_type_inheritance_builtin_type.<locals>.TestClassNr  r/   r/   r/   r4   r  W  r  r  r   rN   r>  zclass C(type): ...)r   r   r   r#   rA  r/   r/   r4   -test_generate_c_type_inheritance_builtin_typeV  s   
z;StubgencSuite.test_generate_c_type_inheritance_builtin_typec              	   C  T   G dd d}g }g }t |jd}t|d|j||ddd t|dg t|g  d S )Nc                   @     e Zd ZdddZdS )	zDStubgencSuite.test_generate_c_type_with_docstring.<locals>.TestClassarg0rW   r(   r)   c                 S     dS )zB
                test(self: TestClass, arg0: int)
                Nr/   r?   rK  r/   r/   r4   testc      zIStubgencSuite.test_generate_c_type_with_docstring.<locals>.TestClass.testNrK  rW   r(   r)   re   rf   rg   rN  r/   r/   r/   r4   r  b  rz   r  rN   rN  r?   self_var
class_name%def test(self, arg0: int) -> Any: ...r   rf   r   rN  r#   rA  r/   r/   r4   #test_generate_c_type_with_docstringa     z1StubgencSuite.test_generate_c_type_with_docstringc              	   C  rI  )Nc                   @  rJ  )	zPStubgencSuite.test_generate_c_type_with_docstring_no_self_arg.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )z1
                test(arg0: int)
                Nr/   rM  r/   r/   r4   rN  s  rO  zUStubgencSuite.test_generate_c_type_with_docstring_no_self_arg.<locals>.TestClass.testNrP  rQ  r/   r/   r/   r4   r  r  rz   r  rN   rN  r?   rR  rU  rV  rA  r/   r/   r4   /test_generate_c_type_with_docstring_no_self_argq  rX  z=StubgencSuite.test_generate_c_type_with_docstring_no_self_argc              	   C  rI  )Nc                   @  s   e Zd ZedddZdS )	zAStubgencSuite.test_generate_c_type_classmethod.<locals>.TestClassrK  rW   r(   r)   c                 S  s   d S r_   r/   )clsrK  r/   r/   r4   rN    s   zFStubgencSuite.test_generate_c_type_classmethod.<locals>.TestClass.testNrP  )re   rf   rg   classmethodrN  r/   r/   r/   r4   r    s    r  rN   rN  rZ  rR  z*def test(cls, *args, **kwargs) -> Any: ...rV  rA  r/   r/   r4    test_generate_c_type_classmethod  s   z.StubgencSuite.test_generate_c_type_classmethodc              	   C  rI  )Nc                   @  s   e Zd Zd	d
ddZdS )zRStubgencSuite.test_generate_c_type_with_docstring_empty_default.<locals>.TestClassrN   rK  rW   r(   r)   c                 S  rL  )zG
                test(self: TestClass, arg0: str = "")
                Nr/   rM  r/   r/   r4   rN    rO  zWStubgencSuite.test_generate_c_type_with_docstring_empty_default.<locals>.TestClass.testN)rN   rP  rQ  r/   r/   r/   r4   r    s    r  rN   rN  r?   rR  z+def test(self, arg0: str = ...) -> Any: ...rV  rA  r/   r/   r4   1test_generate_c_type_with_docstring_empty_default  rX  z?StubgencSuite.test_generate_c_type_with_docstring_empty_defaultc                 C  J   ddd}g }g }t | jd}t|d||| t|d	g t|d
g dS )zQTest that if argument references type from other module, module will be imported.rK  rW   r(   r)   c                 S  rL  z5
            test(arg0: argparse.Action)
            Nr/   rK  r/   r/   r4   rN    rO  zEStubgencSuite.test_generate_c_function_other_module_arg.<locals>.testrN   rN  z+def test(arg0: argparse.Action) -> Any: ...rD  NrP  r   rf   r   r#   r?   rN  r   r;  r3   r/   r/   r4   )test_generate_c_function_other_module_arg  s   
z7StubgencSuite.test_generate_c_function_other_module_argc                 C  F   ddd}g }g }t dd}t|d	||| t|d
g t|g  dS )zTest that if argument references type from same module but using full path, no module
        will be imported, and type specification will be striped to local reference.
        rK  rW   r(   r)   c                 S  rL  r_  r/   r`  r/   r/   r4   rN    rO  zDStubgencSuite.test_generate_c_function_same_module_arg.<locals>.testrE  rN   rN  z"def test(arg0: Action) -> Any: ...NrP  r   r   r#   rb  r/   r/   r4   (test_generate_c_function_same_module_arg  s   

z6StubgencSuite.test_generate_c_function_same_module_argc                 C  r^  )zTTest that if return type references type from other module, module will be imported.rK  rW   r(   r)   c                 S  rL  z<
            test(arg0: str) -> argparse.Action
            Nr/   r`  r/   r/   r4   rN    rO  zEStubgencSuite.test_generate_c_function_other_module_ret.<locals>.testrN   rN  z+def test(arg0: str) -> argparse.Action: ...rD  NrP  ra  rb  r/   r/   r4   )test_generate_c_function_other_module_ret  s   
z7StubgencSuite.test_generate_c_function_other_module_retc                 C  rd  )zTest that if return type references type from same module but using full path,
        no module will be imported, and type specification will be striped to local reference.
        rK  rW   r(   r)   c                 S  rL  rg  r/   r`  r/   r/   r4   rN    rO  zDStubgencSuite.test_generate_c_function_same_module_ret.<locals>.testrE  rN   rN  z"def test(arg0: str) -> Action: ...NrP  re  rb  r/   r/   r4   (test_generate_c_function_same_module_ret  s   

z6StubgencSuite.test_generate_c_function_same_module_retc                 C  sL   G dd d}g }g }t d|jg ||t|j t|g  t|ddg dS )z>Signatures included by PyBind11 inside property.fget are read.c                   @  s"   e Zd ZdddZeeddZdS )	zGStubgencSuite.test_generate_c_property_with_pybind11.<locals>.TestClassr(   r)   c                 S  rL  )z:
                (self: TestClass) -> str
                Nr/   r   r/   r/   r4   get_attribute  rO  zUStubgencSuite.test_generate_c_property_with_pybind11.<locals>.TestClass.get_attributerN   )docNrd   )re   rf   rg   rj  property	attributer/   r/   r/   r4   r    s    
r  rm  z	@propertyzdef attribute(self) -> str: ...N)r   rm  r   r#   r?   r  readwrite_propertiesreadonly_propertiesr/   r/   r4   &test_generate_c_property_with_pybind11  s   
z4StubgencSuite.test_generate_c_property_with_pybind11c                 C  sN   G dd d}g }g }t dt|jg ||t|j t|dg t|g  d S )Nc                   @  s4   e Zd ZdddZedddZejdd	dZd
S )zJStubgencSuite.test_generate_c_property_with_rw_property.<locals>.TestClassr(   r)   c                 S  s
   d| _ d S )Nr   
_attributer   r/   r/   r4   __init__  s   
zSStubgencSuite.test_generate_c_property_with_rw_property.<locals>.TestClass.__init__r   c                 S  s   | j S r_   rr  r   r/   r/   r4   rm    s   zTStubgencSuite.test_generate_c_property_with_rw_property.<locals>.TestClass.attributevaluec                 S  s
   || _ d S r_   rr  )r?   ru  r/   r/   r4   rm    s   
Nrd   )r(   r   )ru  r   r(   r)   )re   rf   rg   rt  rl  rm  setterr/   r/   r/   r4   r    s    
r  rm  zattribute: Any)r   r   rm  r   r#   rn  r/   r/   r4   )test_generate_c_property_with_rw_property  s   z7StubgencSuite.test_generate_c_property_with_rw_propertyc              	   C  rI  )Nc                   @  rJ  )	zMStubgencSuite.test_generate_c_type_with_single_arg_generic.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )zH
                test(self: TestClass, arg0: List[int])
                Nr/   rM  r/   r/   r4   rN    rO  zRStubgencSuite.test_generate_c_type_with_single_arg_generic.<locals>.TestClass.testNrP  rQ  r/   r/   r/   r4   r    rz   r  rN   rN  r?   rR  z+def test(self, arg0: List[int]) -> Any: ...rV  rA  r/   r/   r4   ,test_generate_c_type_with_single_arg_generic  rX  z:StubgencSuite.test_generate_c_type_with_single_arg_genericc              	   C  rI  )Nc                   @  rJ  )	zMStubgencSuite.test_generate_c_type_with_double_arg_generic.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )zM
                test(self: TestClass, arg0: Dict[str, int])
                Nr/   rM  r/   r/   r4   rN  &  rO  zRStubgencSuite.test_generate_c_type_with_double_arg_generic.<locals>.TestClass.testNrP  rQ  r/   r/   r/   r4   r  %  rz   r  rN   rN  r?   rR  z/def test(self, arg0: Dict[str,int]) -> Any: ...rV  rA  r/   r/   r4   ,test_generate_c_type_with_double_arg_generic$  rX  z:StubgencSuite.test_generate_c_type_with_double_arg_genericc              	   C  rI  )Nc                   @  rJ  )	zIStubgencSuite.test_generate_c_type_with_nested_generic.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )zS
                test(self: TestClass, arg0: Dict[str, List[int]])
                Nr/   rM  r/   r/   r4   rN  6  rO  zNStubgencSuite.test_generate_c_type_with_nested_generic.<locals>.TestClass.testNrP  rQ  r/   r/   r/   r4   r  5  rz   r  rN   rN  r?   rR  z5def test(self, arg0: Dict[str,List[int]]) -> Any: ...rV  rA  r/   r/   r4   (test_generate_c_type_with_nested_generic4  rX  z6StubgencSuite.test_generate_c_type_with_nested_genericc              	   C  V   G dd d}g }g }t |jd}t|d|j||ddd t|dg t|dg d S )	Nc                   @  rJ  )	z[StubgencSuite.test_generate_c_type_with_generic_using_other_module_first.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )zY
                test(self: TestClass, arg0: Dict[argparse.Action, int])
                Nr/   rM  r/   r/   r4   rN  F  rO  z`StubgencSuite.test_generate_c_type_with_generic_using_other_module_first.<locals>.TestClass.testNrP  rQ  r/   r/   r/   r4   r  E  rz   r  rN   rN  r?   rR  z;def test(self, arg0: Dict[argparse.Action,int]) -> Any: ...rD  rV  rA  r/   r/   r4   :test_generate_c_type_with_generic_using_other_module_firstD     zHStubgencSuite.test_generate_c_type_with_generic_using_other_module_firstc              	   C  r{  )	Nc                   @  rJ  )	zZStubgencSuite.test_generate_c_type_with_generic_using_other_module_last.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )zY
                test(self: TestClass, arg0: Dict[str, argparse.Action])
                Nr/   rM  r/   r/   r4   rN  V  rO  z_StubgencSuite.test_generate_c_type_with_generic_using_other_module_last.<locals>.TestClass.testNrP  rQ  r/   r/   r/   r4   r  U  rz   r  rN   rN  r?   rR  z;def test(self, arg0: Dict[str,argparse.Action]) -> Any: ...rD  rV  rA  r/   r/   r4   9test_generate_c_type_with_generic_using_other_module_lastT  r}  zGStubgencSuite.test_generate_c_type_with_generic_using_other_module_lastc              	   C  s\   G dd d}g }g }t |jd}t|d|j||ddd t|g d tt|dh d S )	Nc                   @  rJ  )	zLStubgencSuite.test_generate_c_type_with_overload_pybind11.<locals>.TestClassrK  rW   r(   r)   c                 S  rL  )z
                __init__(*args, **kwargs)
                Overloaded function.

                1. __init__(self: TestClass, arg0: str) -> None

                2. __init__(self: TestClass, arg0: str, arg1: str) -> None
                Nr/   rM  r/   r/   r4   rt  f  rO  zUStubgencSuite.test_generate_c_type_with_overload_pybind11.<locals>.TestClass.__init__NrP  )re   rf   rg   rt  r/   r/   r/   r4   r  e  rz   r  rN   rt  r?   rR  )	@overloadz*def __init__(self, arg0: str) -> None: ...r  z5def __init__(self, arg0: str, arg1: str) -> None: ...r  z)def __init__(*args, **kwargs) -> Any: ...zfrom typing import overload)r   rf   r   rt  r#   rt   rA  r/   r/   r4   +test_generate_c_type_with_overload_pybind11d  s$   	z9StubgencSuite.test_generate_c_type_with_overload_pybind11Nrd   )re   rf   rg   rh   r  r"  r%  r6  r9  r<  r?  rB  rC  rG  rH  rW  rY  r\  r]  rc  rf  rh  ri  rq  rw  rx  ry  rz  r|  r~  r  r/   r/   r/   r4   r    s:    

























r  c                   @  rm   )ArgSigSuiter(   r)   c                 C  sX   t ttddd t ttddd t ttddd t ttddd	d
d d S )Nzasd"dsar   z0ArgSig(name='asd"dsa', type=None, default=False)zasd'dsaz0ArgSig(name="asd'dsa", type=None, default=False)r|   rW   z.ArgSig(name='func', type='str', default=False)T)r   z-ArgSig(name='func', type='str', default=True))r#   reprr   r   r/   r/   r4   	test_repr  s   zArgSigSuite.test_reprNrd   )re   rf   rg   r  r/   r/   r/   r4   r    rz   r  c                   @  rm   )IsValidTypeSuiter(   r)   c                 C  s   t dsJ t dsJ t dsJ t dsJ t dsJ t ds$J t ds*J t dr0J t d	r6J t d
r<J t drBJ t drHJ t drNJ d S )Nr   rW   
Foo_Bar234r   z	List[int]zDict[str, int]r)   zfoo-barzx->yTrueFalsezx,yzx, y)r   r   r/   r/   r4   test_is_valid_type  s   z#IsValidTypeSuite.test_is_valid_typeNrd   )re   rf   rg   r  r/   r/   r/   r4   r    rz   r  c                   @  s4   e Zd ZdddZdddZdddZdd	d
ZdS )ModuleInspectSuiter(   r)   c                 C  s   t  5}|d}|d usJ |jdksJ |jsJ |jd u s"J |jdu s)J |jg ks0J W d    d S 1 s;w   Y  d S )NinspectF)r   get_package_propertiesr   r[   r0   is_c_modulesubpackagesr?   rw   pr/   r/   r4   test_python_module  s   

"z%ModuleInspectSuite.test_python_modulec                 C  s   t  =}|d}|d usJ |jdksJ |jsJ |js J |jdu s'J |js,J tdd |jD s8J W d    d S 1 sCw   Y  d S )Nri   Fc                 s  s    | ]}| d V  qdS )z	unittest.N)
startswith)r2   r.  r/   r/   r4   	<genexpr>  s    z9ModuleInspectSuite.test_python_package.<locals>.<genexpr>)r   r  r   r[   r0   r  r  allr  r/   r/   r4   test_python_package  s   



"z&ModuleInspectSuite.test_python_packagec                 C  sz   t  0}|d}|d usJ |jdksJ |jd u sJ |jdu s$J |jg ks+J W d    d S 1 s6w   Y  d S )N_socketT)r   r  r   r0   r  r  r  r/   r/   r4   test_c_module  s   
"z ModuleInspectSuite.test_c_modulec              	   C  sr   t  ,}| t}|d W d    n1 sw   Y  t|jdks'J W d    d S 1 s2w   Y  d S )Nzfoobar-non-existentz%No module named 'foobar-non-existent')r   assertRaisesr   r  rW   	exception)r?   rw   r   r/   r/   r4   test_non_existent  s   "z$ModuleInspectSuite.test_non_existentNrd   )re   rf   rg   r  r  r  r  r/   r/   r/   r4   r    s
    



	r  r   rW   r   r(   c                 C  sH   t j| |dd d}t j|s"|dd}t j|r"|S |S )Nr   r   z.pyiz/__init__.pyi)r6   r0   r=   r   r  )r   r   r   alt_fnamr/   r/   r4   r     s   r   )r   rW   r   rW   r(   rW   )E
__future__r   rO   os.pathr6   r  r   rQ   r8   ri   typesr   typingr   mypy.errorsr   mypy.moduleinspectr   r   mypy.stubdocr   r	   r
   r   r   r   r   r   r   r   mypy.stubgenr   r   r   r   r   r   r   mypy.stubgencr   r   r   r   r   mypy.stubutilr   r   r    mypy.test.datar!   r"   mypy.test.helpersr#   r$   r%   TestCaser&   rn   r{   r   r   r  r  r  r  r  r  r  r   r/   r/   r/   r4   <module>   sJ    0$	P   U)
c   &