B
    u9a…'  ã               @   sd  d dl Z d dlZd dlZd dlZd dlZej d¡Zddddddœgd	d
ddœgddddddœgdddœgd	dddœddddœgdddœgddd	dd d!œgd"d	d#d$d%œgd&d'dœgd(d)dœgd*d+dœgd,d-d d.œgd&d/dœgd0œZ	e 
e	¡Zx*e ¡ D ]ZxeD ]Ze d1¡ q W qöW G d2d3„ d3ejƒZG d4d5„ d5ejƒZG d6d7„ d7ejƒZed8kr`e ¡  dS )9é    Nzmailcap.txtzmoviemaker %sz""/usr/lib/Zmail/bitmaps/movie.xbm"z"Movie"zmovieplayer %sé   )Úcomposez
x11-bitmapÚdescriptionÚviewÚlinenoÚ z?echo "This is \"%t\" but        is 50 \% Greek to me" \; cat %sé   )Úcopiousoutputr   r   zaudiocompose %sz"An audio fragment"zshowaudio %sé   )Úeditr   r   r   r   zmpeg_play %sé   )r   r   zps-to-terminal %sé   )Úneedsterminalr   r   zidraw %sé   )r   r   r   zxdvi %sé   zextcompose %sz4"A reference to data stored in an external location"zQshowexternal %s %{access-type} %{name} %{site}     %{directory} %{mode} %{server}é
   )Úcomposetypedr   r   r   r   z?test "`echo     %{charset} | tr '[A-Z]' '[a-z]'`"  = iso-8859-8z)shownonascii iso-8859-8 -e richtext -p %sé   )Útestr	   r   r   z
display %sé	   z/usr/local/bin/showaudio %té   z
animate %sé   z"cat %s | lp"zshowframe %s)Úprintr   r   é   )zapplication/x-moviezapplication/*zaudio/basicz
video/mpegzapplication/postscriptzapplication/x-dvizmessage/external-bodyztext/richtextzimage/x-xwindowdumpzaudio/*zvideo/*zapplication/framez	image/rgbr   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚHelperFunctionTestc          	   C   sŽ   t  ¡ }|  |t¡ x|D ]}|  |t¡ qW tj ¡ @}d|krT|d  t	j
¡}n ddg}t	j
 |¡|d< t  ¡ }W d Q R X |  ||¡ d S )NÚMAILCAPSz/testdir1/.mailcapz/testdir2/mailcap)ÚmailcapÚlistmailcapfilesÚassertIsInstanceÚlistÚstrr   ÚsupportÚEnvironmentVarGuardÚsplitÚosÚpathsepÚjoinÚassertEqual)ÚselfZmcfilesÚmÚenvZenv_mailcaps© r+   ú"/usr/lib/python3.7/test_mailcap.pyÚtest_listmailcapfilesE   s    
z(HelperFunctionTest.test_listmailcapfilesc          
   C   sF   t tdƒ&}|  t¡ t |¡}W d Q R X W d Q R X |  |t¡ d S )NÚr)ÚopenÚMAILCAPFILEZassertWarnsÚDeprecationWarningr   ZreadmailcapfileÚassertDictEqualÚMAILCAPDICT_DEPRECATED)r(   ÚmcfÚdr+   r+   r,   Útest_readmailcapfileX   s    z'HelperFunctionTest.test_readmailcapfilec             C   sˆ   dddœdddœg}t  td¡}|  ||¡ d}ddd	d
ddœg}t  td|¡}|  ||¡ ddiddig}t  td¡}|  ||¡ d S )Nz
animate %sr   )r   r   zmpeg_play %sr   z
video/mpegr   zaudiocompose %sz"An audio fragment"zshowaudio %sr
   )r   r   r   r   r   zaudio/basicr   )r   ÚlookupÚMAILCAPDICTZassertListEqualr3   )r(   ZexpectedÚactualÚkeyr+   r+   r,   Útest_lookup_   s    
zHelperFunctionTest.test_lookupc          
   C   s’   dddg}dddgdfdddgdfdddgd	fd
ddgdfdddgd
fddd|gdfddd|gdfg}x&|D ]}|   tj|d Ž |d ¡ qlW d S )Nzid=1znumber=2ztotal=3r   zaudio/*zfoo.txtzecho foozecho %szecho foo.txtzecho %tzecho audio/*zecho \%tzecho %{total}zecho 3r   r   )r'   r   Zsubst)r(   ÚplistZ
test_casesZtcr+   r+   r,   Ú
test_substu   s    

zHelperFunctionTest.test_substN)Ú__name__Ú
__module__Ú__qualname__r-   r6   r;   r=   r+   r+   r+   r,   r   C   s   r   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚGetcapsTestc          	   C   s6   t j ¡ "}t|d< t ¡ }|  |t¡ W d Q R X d S )Nr   )r   r!   r"   r0   r   Úgetcapsr2   r8   )r(   r*   Úcapsr+   r+   r,   Útest_mock_getcaps‡   s    zGetcapsTest.test_mock_getcapsc             C   sˆ   t  ¡ }|  |t¡ t  ¡ }dd„ |D ƒ}|rxxT| ¡ D ]:\}}|  |t¡ |  |t¡ x|D ]}|  |t¡ q^W q8W n|  i |¡ d S )Nc             S   s   g | ]}t j |¡r|‘qS r+   )r$   ÚpathÚexists)Ú.0r4   r+   r+   r,   ú
<listcomp>•   s    z3GetcapsTest.test_system_mailcap.<locals>.<listcomp>)	r   rB   r   Údictr   Úitemsr    r   r'   )r(   rC   ZmailcapfilesZexistingmcfilesÚkÚvÚer+   r+   r,   Útest_system_mailcap   s    
zGetcapsTest.test_system_mailcapN)r>   r?   r@   rD   rN   r+   r+   r+   r,   rA   …   s   	rA   c               @   s6   e Zd Zdd„ Ze ejdkd¡dd„ ƒZdd„ Z	d	S )
ÚFindmatchTestc       	      C   s:  t }d}ddddddg}ddd	d
ddœ}dddœ}dddœ}ddddddœ}i dgi df|dgi df|dgi d|ff|ddgi d|ff|ddgi d|ff|dd gi d	|ff|dd!gi df|d"gd#|id| |ff|ddgd#|id| |ff|dgd |d$œd	|ff|d%gd#|id&|ff|d'gd(|id)|ffg}|  |¡ d S )*Nzfoo.txtzaccess-type=defaultz	name=johnzsite=python.orgzdirectory=/tmpzmode=fooz
server=barzaudiocompose %sz"An audio fragment"zshowaudio %sr
   )r   r   r   r   r   z/usr/local/bin/showaudio %tr   )r   r   z
animate %sr   zextcompose %sz4"A reference to data stored in an external location"r   zQshowexternal %s %{access-type} %{name} %{site}     %{directory} %{mode} %{server}r   )r   r   r   r   r   z
video/mpeg)NNzfoo/barzanimate /dev/nullzaudio/basicr   zaudiocompose /dev/nullr   r   Zfoobarzvideo/*Úfilename)r:   rP   zaudio/*z /usr/local/bin/showaudio audio/*zmessage/external-bodyr<   z?showexternal /dev/null default john python.org     /tmp foo bar)r8   Ú
_run_cases)	r(   ÚcZfnamer<   Zaudio_basic_entryZaudio_entryZvideo_entryZmessage_entryÚcasesr+   r+   r,   Útest_findmatch¤   sH    


zFindmatchTest.test_findmatchÚposixz!Requires 'test' command on systemc             C   sL   ddigddigdœ}|ddgi dddiff|ddgi dfg}|   |¡ d S )Nr   ztest 1 -eq 1ztest 1 -eq 0)z	test/passz	test/failz	test/passz	test/fail)NN)rQ   )r(   rC   rS   r+   r+   r,   Ú	test_test×   s
    zFindmatchTest.test_testc             C   s2   x,|D ]$}|   tj|d |d Ž|d ¡ qW d S )Nr   r   r   )r'   r   Z	findmatch)r(   rS   rR   r+   r+   r,   rQ   é   s    
zFindmatchTest._run_casesN)
r>   r?   r@   rT   ÚunittestZ
skipUnlessr$   ÚnamerV   rQ   r+   r+   r+   r,   rO   ¢   s   3rO   Ú__main__)r   r$   ÚcopyZtest.supportr   rW   r!   Zfindfiler0   r8   Zdeepcopyr3   ÚvaluesZ
entry_listÚentryÚpopZTestCaser   rA   rO   r>   Úmainr+   r+   r+   r,   Ú<module>   sZ   







BL
