o
    Ÿpjû  ã                   @  s    d dl mZ d dlZd dlm  m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 eeƒ ¡ jd Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ ZdS )é    )ÚannotationsN)ÚPath)ÚConfig)ÚScriptDirectoryé   c                  c  s0    h d£} t  d¡D ]}|  |j¡s|V  q
d S )N>   ú.gitÚvenvÚstorageÚ__pycache__z*.py)ÚROOTÚrglobÚintersectionÚparts)ÚexcludedÚpath© r   ú;/var/www/html/flask_server/tests/test_platform_structure.pyÚ_python_sources   s   €€þr   c                  C  s”  d} d}d}t t||ƒ}t|ƒ}| |v}|sxt d|fd| |f¡t | ¡dt ¡ v s/t t¡r4t t¡nddt ¡ v s@t t ¡rEt t ¡nddt ¡ v sQt t¡rVt t¡ndt |¡t |¡t |¡t |¡d	œ }d
d|i }t	t 
|¡ƒ‚d  }  } } } }}d}t| }	|	j}
|
ƒ }| }|s¾ddt ¡ v s¡t t¡r¦t t¡ndt |¡t |
¡t |¡dœ }t	t 
|¡ƒ‚d  } }	 }
 }}d S )Nzflask_server/platformÚ__file__Ú ©únot in)zh%(py1)s not in %(py13)s
{%(py13)s = %(py3)s(%(py11)s
{%(py11)s = %(py4)s(%(py5)s, %(py7)s, %(py9)s)
})
}ÚstrÚgetattrÚstdlib_platform)Úpy1Úpy3Úpy4Úpy5Úpy7Úpy9Úpy11Úpy13zassert %(py15)sÚpy15ÚplatformzQassert not %(py7)s
{%(py7)s = %(py5)s
{%(py5)s = (%(py0)s / %(py2)s).exists
}()
}r   )Úpy0Úpy2r   r   )r   r   r   Ú
@pytest_arÚ_call_reprcompareÚ	_safereprÚ@py_builtinsÚlocalsÚ_should_repr_global_nameÚAssertionErrorÚ_format_explanationr   Úexists)Ú@py_assert0Ú@py_assert6Ú@py_assert8Ú@py_assert10Ú@py_assert12Ú@py_assert2Ú@py_format14Ú@py_format16Ú@py_assert1Ú@py_assert3Ú@py_assert4Ú@py_format9r   r   r   Ú%test_platform_name_resolves_to_stdlib   s   þ
 Œr<   c                   C  s"   t  d¡ t  d¡ t  d¡ d S )NÚbridge_platformzapps.qr_servicezapps.messaging_service)Ú	importlibÚimport_moduler   r   r   r   Ú'test_bridge_platform_and_v1_apps_import   s   

r@   c                    sô   g } t ƒ D ]B‰ tjˆ jddtˆ ƒd}t |¡D ]-}t|tjƒr3|jp%d 	d¡r3|  
tˆ  t¡ƒ¡ t|tjƒrF|  ‡ fdd„|jD ƒ¡ qq|  }|svt dtt| ƒƒ› ¡d	 d
dt ¡ v sft | ¡rkt | ¡ndi }tt |¡ƒ‚d }d S )Núutf-8©Úencoding)Úfilenamer   ú	platform.c                 3  s*    | ]}|j  d ¡rtˆ  t¡ƒV  qdS )rE   N)ÚnameÚ
startswithr   Úrelative_tor   )Ú.0Úalias©r   r   r   Ú	<genexpr>)   s   € 
ý
ÿzBtest_no_internal_import_uses_platform_namespace.<locals>.<genexpr>z%forbidden internal platform imports: z
>assert not %(py0)sr%   Ú
violations)r   ÚastÚparseÚ	read_textr   ÚwalkÚ
isinstanceÚ
ImportFromÚmodulerG   ÚappendrH   r   ÚImportÚextendÚnamesr'   Ú_format_assertmsgÚsortedÚsetr*   r+   r,   r)   r-   r.   )rM   ÚtreeÚnoder8   Ú@py_format2r   rK   r   Ú/test_no_internal_import_uses_platform_namespace!   s   
þ€üd	r_   c                  C  sÎ  t d } tt| ƒƒ}t |¡}|j}|ƒ }dg}||k}|sVt d|fd||f¡dt 	¡ v s3t 
|¡r8t |¡ndt |¡t |¡t |¡dœ }dd|i }tt |¡ƒ‚d  } } }}| jd	d
}	d}
|
|	v}|sœt d|fd|
|	f¡t |
¡dt 	¡ v s…t 
|	¡rŠt |	¡nddœ }dd|i }tt |¡ƒ‚d  }
}| jd jd	d
}d}
|
|v}|sát d|fd|
|f¡t |
¡dt 	¡ v sÊt 
|¡rÏt |¡nddœ }dd|i }tt |¡ƒ‚d  }
}d S )Nz&bridge_platform/migrations/alembic.iniÚc9a31f2e7d44)ú==)zH%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.get_heads
}()
} == %(py7)sÚscripts)r%   r&   r   r   zassert %(py9)sr    rA   rB   ÚNUEVA_PASSWORD_FUERTEr   )z%(py1)s not in %(py3)sÚcontents)r   r   zassert %(py5)sr   zalembic/env.pyztarget_metadata = NoneÚenv_contents)r   r   r   r   Úfrom_configÚ	get_headsr'   r(   r*   r+   r,   r)   r-   r.   rP   Úparent)ÚiniÚconfigrb   r8   r9   r1   Ú@py_assert5Ú@py_format8Ú@py_format10rd   r0   r5   Ú@py_format4Ú@py_format6re   r   r   r   ÚDtest_alembic_has_one_expected_head_and_no_embedded_database_password1   s   
žx|rp   )Ú
__future__r   Úbuiltinsr*   Ú_pytest.assertion.rewriteÚ	assertionÚrewriter'   rN   r>   r$   r   Úpathlibr   Úalembic.configr   Úalembic.scriptr   r   ÚresolveÚparentsr   r   r<   r@   r_   rp   r   r   r   r   Ú<module>   s    "