
    ;bh/                        	 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  ed        ee      j                   dz  j#                         Z ee      dz  Zed	z  Zd
 Z G d dej,                        Z G d dej,                        Zd Zedk(  rR eej8                        dkD  r+ej8                  d   dk(  r e         ej:                  d         ej<                          yy)    N)GNUTranslations)Path)temp_cwd)assert_python_failureassert_python_ok)skip_if_missingtoolsdiri18nmsgfmt_dataz	msgfmt.pyc                 (    t        t        d||        y )Nz-o)r   msgfmt)po_filemo_files     E/opt/python-3.12.12/usr/lib/python3.12/test/test_tools/test_msgfmt.pycompile_messagesr      s    VT7G4    c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)CompilationTestc           	      "   d | _         t               5  t        j                  d      D ]  }| j	                  |      5  |j                  d      }t        |d      5 }t        |      }d d d        |j                  }t        ||       t        |d      5 }t        |      }d d d        | j                  j                  j                         d d d         	 d d d        y # 1 sw Y   {xY w# 1 sw Y   OxY w# 1 sw Y   xY w# 1 sw Y   y xY w)N*.po)r   .morb)maxDiffr   data_dirglobsubTestwith_suffixopenr   namer   assertDictEqual_catalog)selfr   r   fexpectedtmp_mo_fileactuals          r   test_compilationz CompilationTest.test_compilation   s    Z#==0\\'\2%11%8Ggt,#21#5 - #*,,K$Wk:k40A!0!3 1 (((:K:KL 32 1 Z -,
 10 32 ZsR   +DC9C!	',C9C-	.C9
D!C*&C9-C62C99D>DDc                 Z   t        t        dz  d      5 }t        |      }d d d        | j                  j	                  d      d       | j                  |j	                  d      d       | j                  |j                  dd      d       | j                  |j                  dd      d       | j                  |j	                  d      d	       | j                  |j	                  d
      d       | j                  |j	                  d      d       | j                  |j                  ddd      d       | j                  |j                  ddd      d       | j                  |j                  dddd      d       | j                  |j                  dddd      d       y # 1 sw Y   xY w)Nz
general.mor   foobarbazabcxyzMultilinestringMultilinetranslationz	"escapes"z"translated"z
 newlines 
z
 translated 
zOne email sent.z%d emails sent.      )r   r   r   assertEqualgettextpgettextngettext	npgettext)r"   r#   ts      r   test_translationsz!CompilationTest.test_translations+   sv   (\)40A"A 1 	5)515)51E5159E5159#457MN;/@#346HI$57H!L*	,$57H!L*	,U,=%6;*	, 	U,=%6;*	,# 10s   F  F*c                     t               5  t        d      j                  d       t        t        d      }|j
                  j                  d      }| j                  d|       d d d        y # 1 sw Y   y xY w)N
invalid.poz+msgid_plural "plural"
msgstr[0] "singular"
utf-8z"msgid_plural not preceded by msgidr   r   
write_textr   r   errdecodeassertInr"   resr>   s      r   test_invalid_msgid_pluralz)CompilationTest.test_invalid_msgid_pluralA   sX    Z)) + 
 (=C''..)CMM>D ZZ   AA,,A5c                     t               5  t        d      j                  d       t        t        d      }|j
                  j                  d      }| j                  d|       d d d        y # 1 sw Y   y xY w)Nr:   zmsgid "foo"
msgstr[0] "bar"
r;   zplural without msgid_pluralr<   rA   s      r    test_plural_without_msgid_pluralz0CompilationTest.test_plural_without_msgid_pluralL   sX    Z)) + 
 (=C''..)CMM7= ZZrD   c                     t               5  t        d      j                  d       t        t        d      }|j
                  j                  d      }| j                  d|       d d d        y # 1 sw Y   y xY w)Nr:   z-msgid "foo"
msgid_plural "foos"
msgstr "bar"
r;   z"indexed msgstr required for pluralr<   rA   s      r   (test_indexed_msgstr_without_msgid_pluralz8CompilationTest.test_indexed_msgstr_without_msgid_pluralW   sX    Z)) +  (=C''..)CMM>D ZZrD   c                     t               5  t        d      j                  d       t        t        d      }|j
                  j                  d      }| j                  d|       d d d        y # 1 sw Y   y xY w)Nr:   z"foo"
r;   zSyntax errorr<   rA   s      r   test_generic_syntax_errorz)CompilationTest.test_generic_syntax_errorc   sW    Z)) +  (=C''..)CMM.#. ZZrD   N)	__name__
__module____qualname__r'   r8   rC   rF   rH   rJ    r   r   r   r      s#    M ,,	E	>
E/r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)CLITestc                     dD ]?  }t        t        |      }|j                  j                  d      }| j	                  d|       A y )N)z--helpz-hr;   EGenerate binary message catalog from textual translation description.)r   r   r>   r?   r@   )r"   optionrB   r>   s       r   	test_helpzCLITest.test_helpo   s:    &F"662C''..)CMMacfg 'r   c                     dD ]M  }t        t        |      }|j                  j                  d      j	                         }| j                  d|       O y )N)z	--versionz-Vr;   zmsgfmt.py 1.2)r   r   outr?   stripr2   )r"   rS   rB   rV   s       r   test_versionzCLITest.test_versionu   sC    )F"662C''..)//1C_c2 *r   c                     t        t        d      }|j                  j                  d      }| j	                  d|       | j	                  d|       y )Nz--invalid-optionr;   rR   z&option --invalid-option not recognized)r   r   r>   r?   r@   rA   s      r   test_invalid_optionzCLITest.test_invalid_option{   s@    #F,>?ggnnW%]_bc>Dr   c                     t        t              }|j                  j                  d      j	                  dd      }| j                  d|       y )Nr;   z

z=No input file given
Try `msgfmt --help' for more information.)r   r   r>   r?   replacer@   rA   s      r   test_no_input_filezCLITest.test_no_input_file   sA    v&ggnnW%--fd; BCF	Hr   c                 $    t        t        d       y )Nznonexistent.po)r   r   )r"   s    r   test_nonexistent_filezCLITest.test_nonexistent_file   s    f&67r   N)rK   rL   rM   rT   rX   rZ   r^   r`   rN   r   r   rP   rP   m   s    h3EH8r   rP   c                     t         j                  d      D ]  } | j                  d      }t        | |       t	        |d      5 }t        |      }d d d        | j                  d      }t	        |d      5 }j                  j                         }t        |d       }t        j                  ||d	       |j                  d
       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Nr   r   r   z.jsonwc                 2    t        | d   t              | d   fS )Nr   )
isinstancetuple)xs    r   <lambda>z*update_catalog_snapshots.<locals>.<lambda>   s    z!A$/F!.Mr   )key   )indentr\   )r   r   r   r   r   r   r!   itemssortedjsondumpwrite)r   r   r#   translationscatalog_filedatas         r   update_catalog_snapshotsrs      s    ==(%%e,'* '4 A*1-L !**73,$((..0D$$MNDIIdAa(GGDM	 %$ )
 !  %$s   C3ACC	C%	__main__r0   z--snapshot-update)rm   sysunittestr3   r   pathlibr   test.support.os_helperr   test.support.script_helperr   r   test.test_toolsr   r	   __file__parentresolver   
script_dirr   r   TestCaser   rP   rs   rK   lenargvexitmainrN   r   r   <module>r      s    .  
  #  + N 5  N!!M1::<(^f$
	k	!5R/h'' R/h8h 8<  z
388}qSXXa[,?? "HMMO	 r   