Your IP : 216.73.216.147


Current Path : /opt/alt/python36/lib64/python3.6/test/test_tools/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/test_tools/__pycache__/test_i18n.cpython-36.pyc

3

� f�"�@shdZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZmZe�Gdd�dej
�ZdS)	z%Tests to cover the Tools/i18n package�N)�dedent)�assert_python_ok)�skip_if_missing�toolsdir)�temp_cwd�temp_dirc@s�eZdZdZejjedd�Zdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,S)-�Test_pygettextzTests for the pygettext.py toolZi18nzpygettext.pycCsTi}xJ|jd�D]<}|s|jd�r&q|jd�}|jdd�\}}|j�||<qW|S)	z: utility: return the header of a .po file as a dictionary �
�#�msgid�msgstr�"�:�)r
rr)�split�
startswith�strip)�self�dataZheaders�line�key�val�r�>/opt/alt/python36/lib64/python3.6/test/test_tools/test_i18n.py�
get_headers
zTest_pygettext.get_headercCs�g}d}g}x�|jd�D]l}|rV|jd�r<|j|jd��n|jdj|��g}d}q|jd�r|td�d�}|j|jd��d}qW|r�|jdj|��|S)z= utility: return all msgids in .po file as a list of strings Fr	r
zmsgid NT)rr�appendr�join�len)rr�msgidsZ
reading_msgidZ	cur_msgidrrrr�
get_msgidss$

zTest_pygettext.get_msgidscCsld}td��P}t|d��}|j|�WdQRXt|jd|�td��}|j�}WdQRXWdQRX|j|�S)z: utility: return all msgids extracted from module_content ztest_docstrings.pyN�wz-Dzmessages.pot)r�open�writer�script�readr)rZmodule_content�filename�cwd�fprrrr�extract_docstrings_from_str7s

z*Test_pygettext.extract_docstrings_from_strcCs�td���}t|j�td��}|j�}WdQRX|j|�}|jd|�|jd|�|jd|�|jd|�|jd|�|jd|�|jd	|�|jd
|�|jd|�WdQRXdS)z�Make sure the required fields are in the header, according to:
           http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry
        Nzmessages.potzProject-Id-VersionzPOT-Creation-DatezPO-Revision-DatezLast-Translatorz
Language-TeamzMIME-VersionzContent-TypezContent-Transfer-EncodingzGenerated-By)rrr#r!r$r�assertIn)rr&r'r�headerrrr�test_headerBs



zTest_pygettext.test_headercCs�ddlm}td��f}t|j�td��}|j�}WdQRX|j|�}|d}|jd�rj|dtd��}|j	|d�WdQRXdS)z; Match the date format from xgettext for POT-Creation-Date r)�datetimeNzmessages.potzPOT-Creation-Datez\nz%Y-%m-%d %H:%M%z)
r,rrr#r!r$r�endswithrZstrptime)rr,r&r'rr*ZcreationDaterrr�test_POT_Creation_Date]s




z%Test_pygettext.test_POT_Creation_DatecCsFx@dD]8}|j|��$|jtd|��}|jd|�WdQRXqWdS)N�	"""doc"""�
r'''doc'''�R'doc'�u"doc"zE                def foo(bar):
                    %s
                �doc)r/r0r1r2)�subTestr(rr))rr3rrrr�test_funcdocstringns

z!Test_pygettext.test_funcdocstringcCs&|jtd��}|jdd�|D��dS)Nz5        def foo(bar):
            b"""doc"""
        cSsg|]}d|kr|�qS)r3r)�.0rrrr�
<listcomp>|sz;Test_pygettext.test_funcdocstring_bytes.<locals>.<listcomp>)r(r�assertFalse)rrrrr�test_funcdocstring_byteswsz'Test_pygettext.test_funcdocstring_bytescCs&|jtd��}|jdd�|D��dS)Nz5        def foo(bar):
            f"""doc"""
        cSsg|]}d|kr|�qS)r3r)r6rrrrr7�sz=Test_pygettext.test_funcdocstring_fstring.<locals>.<listcomp>)r(rr8)rrrrr�test_funcdocstring_fstring~sz)Test_pygettext.test_funcdocstring_fstringcCsFx@dD]8}|j|��$|jtd|��}|jd|�WdQRXqWdS)N�	"""doc"""�
r'''doc'''�R'doc'�u"doc"z@                class C:
                    %s
                r3)r;r<r=r>)r4r(rr))rr3rrrr�test_classdocstring�s

z"Test_pygettext.test_classdocstringcCs&|jtd��}|jdd�|D��dS)Nz0        class C:
            b"""doc"""
        cSsg|]}d|kr|�qS)r3r)r6rrrrr7�sz<Test_pygettext.test_classdocstring_bytes.<locals>.<listcomp>)r(rr8)rrrrr�test_classdocstring_bytes�sz(Test_pygettext.test_classdocstring_bytescCs&|jtd��}|jdd�|D��dS)Nz0        class C:
            f"""doc"""
        cSsg|]}d|kr|�qS)r3r)r6rrrrr7�sz>Test_pygettext.test_classdocstring_fstring.<locals>.<listcomp>)r(rr8)rrrrr�test_classdocstring_fstring�sz*Test_pygettext.test_classdocstring_fstringcCs|jd�}|jd|�dS)Nz_("""doc""" r'str' u"ing")Z	docstring)r(r))rrrrr�
test_msgid�szTest_pygettext.test_msgidcCs"|jd�}|jdd�|D��dS)Nz
_(b"""doc""")cSsg|]}d|kr|�qS)r3r)r6rrrrr7�sz3Test_pygettext.test_msgid_bytes.<locals>.<listcomp>)r(r8)rrrrr�test_msgid_bytes�s
zTest_pygettext.test_msgid_bytescCs"|jd�}|jdd�|D��dS)Nz
_(f"""doc""")cSsg|]}d|kr|�qS)r3r)r6rrrrr7�sz5Test_pygettext.test_msgid_fstring.<locals>.<listcomp>)r(r8)rrrrr�test_msgid_fstring�s
z!Test_pygettext.test_msgid_fstringcCs|jtd��}|jd|�dS)z3 Test docstrings for functions with annotated args z9        def foo(bar: str):
            """doc"""
        r3N)r(rr))rrrrr�!test_funcdocstring_annotated_args�sz0Test_pygettext.test_funcdocstring_annotated_argscCs|jtd��}|jd|�dS)z: Test docstrings for functions with annotated return type z;        def foo(bar) -> str:
            """doc"""
        r3N)r(rr))rrrrr�#test_funcdocstring_annotated_return�sz2Test_pygettext.test_funcdocstring_annotated_returncCs|jtd��}|jd|�dS)z6 Test docstring for functions with default arg values z7        def foo(bar=()):
            """doc"""
        r3N)r(rr))rrrrr� test_funcdocstring_defvalue_args�sz/Test_pygettext.test_funcdocstring_defvalue_argscCs6|jtd��}|jd|�|jd|�|jd|�dS)z� Test docstring extraction for multiple functions combining
        annotated args, annotated return types and default arg values
        z�        def foo1(bar: tuple=()) -> str:
            """doc1"""

        def foo2(bar: List[1:2]) -> (lambda x: x):
            """doc2"""

        def foo3(bar: 'func'=lambda x: x) -> {1: 2}:
            """doc3"""
        Zdoc1Zdoc2Zdoc3N)r(rr))rrrrr�!test_funcdocstring_multiple_funcs�s
	z0Test_pygettext.test_funcdocstring_multiple_funcscCs|jtd��}|jd|�dS)zd Test docstring extraction for a class with colons occuring within
        the parentheses.
        z\        class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)):
            """doc"""
        r3N)r(rr))rrrrr�test_classdocstring_early_colon�sz.Test_pygettext.test_classdocstring_early_colonc.Cspd}d}d}td���Ptd���:}tjtjj|d��ttjj|dd�d��}|jd|�d	��WdQRXtjtjj|d
��ttjj|d
d�d��}|jd|�d	��WdQRXtjtjj|d��ttjj|dd
�d��}|jd|�d	��WdQRXt|j	|�td��}|j
�}WdQRX|jd|�d�|�|jd|�d�|�|j||�WdQRXWdQRXdS)zVMake sure the directories are inspected for source files
           bpo-31920
        zText to translate1zText to translate2zText to ignoreNZpypkgzpymod.pyr z_(�)zpkg.pyz	pymod2.pyZCVSz	pymod3.pyzmessages.potzmsgid "r
)
rr�os�mkdir�pathrr!r"rr#r$r)ZassertNotIn)rZtext1Ztext2Ztext3ZsdirZsfiler'rrrr�test_files_list�s&
zTest_pygettext.test_files_listN)�__name__�
__module__�__qualname__�__doc__rKrMrrr#rrr(r+r.r5r9r:r?r@rArBrCrDrErFrGrHrIrNrrrrrs,		
r)rRrKZunittest�textwraprZtest.support.script_helperrZtest.test_toolsrrZtest.supportrrZTestCaserrrrr�<module>s