a  zeV#@spdZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z m Z e GdddejZdS) z%Tests to cover the Tools/i18n packageN)dedent)assert_python_ok)skip_if_missingtoolsdir)temp_cwdtemp_dirc@seZdZdZejeddZddZ ddZ dd Z d d Z e ejd d ddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Z d,d-Z!d.S)/Test_pygettextzTests for the pygettext.py toolZi18nz pygettext.pycCsNi}|dD]:}|r|dr"q|d}|dd\}}|||<q|S)z: utility: return the header of a .po file as a dictionary  )#msgidZmsgstr":)split startswithstrip)selfdataZheaderslinekeyvalrM/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_tools/test_i18n.py get_headers zTest_pygettext.get_headercCsg}d}g}|dD]l}|rT|dr:||dn|d|g}d}q|dr|tdd}||dd}q|r|d||S)z= utility: return all msgids in .po file as a list of strings Fr r zmsgid NT)rrappendrjoinlen)rrmsgidsZ reading_msgidZ cur_msgidrrrr get_msgids s$  zTest_pygettext.get_msgidsc Csd}td}t|d}||Wdn1s80Yt|jd|td}|}Wdn1sv0YWdn1s0Y||S)z: utility: return all msgids extracted from module_content ztest_docstrings.pyNwz-D messages.pot)ropenwriterscriptreadr)rZmodule_contentfilenamecwdfprrrrextract_docstrings_from_str8s  ( Dz*Test_pygettext.extract_docstrings_from_strc Cstd}t|jtd}|}Wdn1s:0Y||}|d||d||d||d||d||d||d ||d ||d |Wdn1s0YdS) zMake sure the required fields are in the header, according to: http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry Nr zProject-Id-VersionPOT-Creation-DatezPO-Revision-DatezLast-Translatorz Language-Teamz MIME-Versionz Content-TypezContent-Transfer-Encodingz Generated-By)rrr#r!r$rassertIn)rr&r'rheaderrrr test_headerCs   &         zTest_pygettext.test_headerZaixzbpo-29972: broken test on AIXc Csddlm}td}t|jtd}|}Wdn1sF0Y||}|d}|dr~|dtd }| |dWdn1s0YdS)z; Match the date format from xgettext for POT-Creation-Date r)datetimeNr r)z\nz%Y-%m-%d %H:%M%z) r-rrr#r!r$rendswithrstrptime)rr-r&r'rr+Z creationDaterrrtest_POT_Creation_Date]s    &  z%Test_pygettext.test_POT_Creation_Datec CsVdD]L}||.|td|}|d|Wdq1sF0YqdS)Nz """doc"""z r'''doc'''zR'doc'zu"doc"zE def foo(bar): %s docZsubTestr(rr*rr2rrrrtest_funcdocstringps  z!Test_pygettext.test_funcdocstringcCs&|td}|dd|DdS)Nz5 def foo(bar): b"""doc""" cSsg|]}d|vr|qSr2r.0r rrr ~z;Test_pygettext.test_funcdocstring_bytes..r(r assertFalserrrrrtest_funcdocstring_bytesysz'Test_pygettext.test_funcdocstring_bytescCs&|td}|dd|DdS)Nz5 def foo(bar): f"""doc""" cSsg|]}d|vr|qSr6rr7rrrr9r:z=Test_pygettext.test_funcdocstring_fstring..r;r=rrrtest_funcdocstring_fstringsz)Test_pygettext.test_funcdocstring_fstringc CsVdD]L}||.|td|}|d|Wdq1sF0YqdS)Nr1z@ class C: %s r2r3r4rrrtest_classdocstrings  z"Test_pygettext.test_classdocstringcCs&|td}|dd|DdS)Nz0 class C: b"""doc""" cSsg|]}d|vr|qSr6rr7rrrr9r:z.r;r=rrrtest_classdocstring_bytessz(Test_pygettext.test_classdocstring_bytescCs&|td}|dd|DdS)Nz0 class C: f"""doc""" cSsg|]}d|vr|qSr6rr7rrrr9r:z>Test_pygettext.test_classdocstring_fstring..r;r=rrrtest_classdocstring_fstringsz*Test_pygettext.test_classdocstring_fstringcCs|d}|d|dS)Nz_("""doc""" r'str' u"ing")Z docstring)r(r*r=rrr test_msgidszTest_pygettext.test_msgidcCs"|d}|dd|DdS)Nz _(b"""doc""")cSsg|]}d|vr|qSr6rr7rrrr9r:z3Test_pygettext.test_msgid_bytes..r(r<r=rrrtest_msgid_bytess zTest_pygettext.test_msgid_bytescCs"|d}|dd|DdS)Nz _(f"""doc""")cSsg|]}d|vr|qSr6rr7rrrr9r:z5Test_pygettext.test_msgid_fstring..rDr=rrrtest_msgid_fstrings z!Test_pygettext.test_msgid_fstringcCs|td}|d|dS)z3 Test docstrings for functions with annotated args z9 def foo(bar: str): """doc""" r2Nr(rr*r=rrr!test_funcdocstring_annotated_argssz0Test_pygettext.test_funcdocstring_annotated_argscCs|td}|d|dS)z: Test docstrings for functions with annotated return type z; def foo(bar) -> str: """doc""" r2NrGr=rrr#test_funcdocstring_annotated_returnsz2Test_pygettext.test_funcdocstring_annotated_returncCs|td}|d|dS)z6 Test docstring for functions with default arg values z7 def foo(bar=()): """doc""" r2NrGr=rrr test_funcdocstring_defvalue_argssz/Test_pygettext.test_funcdocstring_defvalue_argscCs6|td}|d||d||d|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""" Zdoc1Zdoc2Zdoc3NrGr=rrr!test_funcdocstring_multiple_funcss  z0Test_pygettext.test_funcdocstring_multiple_funcscCs|td}|d|dS)ze Test docstring extraction for a class with colons occurring within the parentheses. z\ class D(L[1:2], F({1: 2}), metaclass=M(lambda x: x)): """doc""" r2NrGr=rrrtest_classdocstring_early_colonsz.Test_pygettext.test_classdocstring_early_colonc Csd}d}d}tdtd}ttj|dttj|ddd"}|d|d Wdn1sv0Yttj|d ttj|d d d"}|d|d Wdn1s0Yttj|d ttj|d d d"}|d|d Wdn1s00Yt|j |td}| }Wdn1sn0Y| d|d|| d|d|| ||Wdn1s0YWdn1s0YdS)zVMake sure the directories are inspected for source files bpo-31920 zText to translate1zText to translate2zText to ignoreNZpypkgzpymod.pyrz_()zpkg.pyz pymod2.pyCVSz pymod3.pyr zmsgid "r ) rrosmkdirpathrr!r"rr#r$r*Z assertNotIn)rZtext1Ztext2Ztext3ZsdirZsfiler'rrrrtest_files_lists&002  (zTest_pygettext.test_files_listN)"__name__ __module__ __qualname____doc__rOrQrrr#rrr(r,unittestZskipIfsysplatformrr0r5r>r?r@rArBrCrErFrHrIrJrKrLrRrrrrrs2      r)rVrOrXrWtextwraprZtest.support.script_helperrZtest.test_toolsrrZ test.supportrrZTestCaserrrrrs