Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_pep292.cpython-34.pyc

�
f fU&�@s�ddlZddlmZGdd�d�ZGdd�d�ZGdd�dej�Zd	d
�Zedkr}e�ndS)�N)�Templatec@seZdZdS)�BagN)�__name__�
__module__�__qualname__�rr�5/opt/alt/python34/lib64/python3.4/test/test_pep292.pyr	src@seZdZdd�ZdS)�MappingcCsX|}xK|jd�D]:}yt||�}Wqtk
rOt|��YqXqW|S)N�.)�split�getattr�AttributeError�KeyError)�self�name�obj�partrrr�__getitem__
s
zMapping.__getitem__N)rrrrrrrrr	sr	c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�TestTemplatecCsjtd�}|j|jtdddd��d�|jt|jtdd��|jttj�dS)Nz,$who likes to eat a bag of $what worth $$100�who�tim�what�hamz(tim likes to eat a bag of ham worth $100)r�assertEqual�
substitute�dict�assertRaisesr�	TypeError)r�srrr�test_regular_templatess
!z#TestTemplate.test_regular_templatescCsitd�}tdddddd�}|j|j|�d�|jt|jtdddd��dS)	Nz$who likes ${what} for ${meal}rrrr�meal�dinnerztim likes ham for dinner)rrrrrr)rr�drrr�"test_regular_templates_with_bracess
z/TestTemplate.test_regular_templates_with_bracescCso|j}td�}||jtdddd��d�td�}||jtdddd��d�dS)	Nz-$who likes to eat a bag of $$what worth $$100rrrrz*tim likes to eat a bag of $what worth $100z
$who likes $$ztim likes $)rrrr)r�eqrrrr�test_escapes&s	zTestTemplate.test_escapescCsT|j}td�}tdd�}||j|�d�||j|�d�dS)Nz%(foo)s $foo ${foo}�fooZbazz%(foo)s baz baz)rrrr�safe_substitute)rr$rr"rrr�
test_percents.s
	zTestTemplate.test_percentscCsv|j}td�}tdd�}||j|�d�||j|�d�td�}||j|�d�dS)Nz&tim has eaten $count bags of ham today�count�z!tim has eaten 7 bags of ham todayz(tim has eaten ${count} bags of ham today)rrrrr')rr$rr"rrr�test_stringification5s	z!TestTemplate.test_stringificationcCsZ|j}td�}tdd	dd
�}||j|�d�||j|�d�dS)Nz$who ate ${meal}rr�fredr r�kung paoz'('tim', 'fred') ate ('ham', 'kung pao'))ztimr,)zhamr-)rrrrr')rr$rr"rrr�test_tupleargs>s
	zTestTemplate.test_tupleargsc	Cs�|j}td�}||jtdd��d�||jtdd��d�||jtdddd	��d
�||jtdddd��d�||jtdddddd	��d�dS)
Nz$who likes ${what} for ${meal}rrztim likes ${what} for ${meal}rrz$who likes ham for ${meal}r r!z$who likes ham for dinnerztim likes ham for ${meal}ztim likes ham for dinner)rrr'r)rr$rrrr�test_SafeTemplateEs	$zTestTemplate.test_SafeTemplatecCs�|j}td�}|t|jtdd��td�}|t|jtdd��td�}|t|jtdd��dS)Nz$who likes $rrz$who likes ${what)z$who likes $100)rr�
ValueErrorrr)r�raisesrrrr�test_invalid_placeholdersQs	z&TestTemplate.test_invalid_placeholderscCs~Gdd�dt�}t�}t�|_t�|j_d|jj_d|j_|d�}|j|j|�d�dS)Nc@seZdZdZdS)z9TestTemplate.test_idpattern_override.<locals>.PathPatternz[_a-z][._a-z0-9]*N)rrrZ	idpatternrrrr�PathPattern[sr3rrz,$bag.foo.who likes to eat a bag of $bag.whatztim likes to eat a bag of ham)	rr	r�bagr&rrrr)rr3�mrrrr�test_idpattern_overrideZs	z$TestTemplate.test_idpattern_overridecCs�Gdd�dt�}t�}t�|_t�|j_d|jj_d|j_|d�}|j|j|�d�Gdd�dt�}|d�}|j	t
|ji�|j	t
|ji�dS)	Nc@seZdZdZdS)z5TestTemplate.test_pattern_override.<locals>.MyPatternz�
            (?P<escaped>@{2})                   |
            @(?P<named>[_a-z][._a-z0-9]*)       |
            @{(?P<braced>[_a-z][._a-z0-9]*)}    |
            (?P<invalid>@)
            N)rrr�patternrrrr�	MyPatternfsr8rrz,@bag.foo.who likes to eat a bag of @bag.whatztim likes to eat a bag of hamc@seZdZdZdS)z6TestTemplate.test_pattern_override.<locals>.BadPatterna
            (?P<badname>.*)                     |
            (?P<escaped>@{2})                   |
            @(?P<named>[_a-z][._a-z0-9]*)       |
            @{(?P<braced>[_a-z][._a-z0-9]*)}    |
            (?P<invalid>@)                      |
            N)rrrr7rrrr�
BadPatternusr9)rr	rr4r&rrrrrr0r')rr8r5rr9rrr�test_pattern_overridees	z"TestTemplate.test_pattern_overridecCshGdd�dt�}d}||�}|jt|ji�|jidd6�}|j|d�dS)Nc@seZdZdZdS)z5TestTemplate.test_braced_override.<locals>.MyTemplatez�
            \$(?:
              (?P<escaped>$)                     |
              (?P<named>[_a-z][_a-z0-9]*)        |
              @@(?P<braced>[_a-z][_a-z0-9]*)@@   |
              (?P<invalid>)                      |
           )
           N)rrrr7rrrr�
MyTemplate�sr;zPyCon in $@@location@@�	Cleveland�locationzPyCon in Cleveland)rrrrr)rr;�tmpl�t�valrrr�test_braced_override�s
z!TestTemplate.test_braced_overridecCshGdd�dt�}d}||�}|j|j�|�|jidd6�}|j|d�dS)Nc@seZdZdZdS)z:TestTemplate.test_braced_override_safe.<locals>.MyTemplatez�
            \$(?:
              (?P<escaped>$)                     |
              (?P<named>[_a-z][_a-z0-9]*)        |
              @@(?P<braced>[_a-z][_a-z0-9]*)@@   |
              (?P<invalid>)                      |
           )
           N)rrrr7rrrrr;�sr;zPyCon in $@@location@@r<r=zPyCon in Cleveland)rrr')rr;r>r?r@rrr�test_braced_override_safe�s
z&TestTemplate.test_braced_override_safec
CsdGdd�dt�}|d�}|jt��}|ji�WdQX|jdt|j��dS)Nc@seZdZdZdS)z;TestTemplate.test_invalid_with_no_lines.<locals>.MyTemplatez�
              (?P<invalid>) |
              unreachable(
                (?P<named>)   |
                (?P<braced>)  |
                (?P<escaped>)
              )
            N)rrrr7rrrrr;�sr;�z
line 1, col 1)rrr0rZassertIn�strZ	exception)rr;r�errrrr�test_invalid_with_no_lines�s
	z'TestTemplate.test_invalid_with_no_linescCs>td�}tdddd�}|j|j|�d�dS)Nz$who likes $whatrutÿmrufþedutÿm likes fþed)rrrr)rrr"rrr�test_unicode_values�sz TestTemplate.test_unicode_valuescCs	|j}td�}||jdddd�d�||jtdd�dd�d�||jtdddd�dddd�d�td	�}||jtd
d�dd
�d�||jtdd�dd�d�td�}||jdd
�d�dS)Nz$who likes $whatrrrrz
tim likes hamr,zkung paozthe mapping is $mappingr&�none�mapping�bozozthe mapping is bozo�one�twozthe mapping is twozthe self is $selfrzthe self is bozo)rrrr)rr$rrrr�test_keyword_arguments�s	%z#TestTemplate.test_keyword_argumentscCsM|j}|j}td�}||jdddd�d�||jtdd�dd�d�||jtdddd�dddd�d�td	�}||jtd
d�dd
�d�||jtdd�dd�d�tdd�}|t|j|i�|t|j|i�td�}||jdd
�d�dS)Nz$who likes $whatrrrrz
tim likes hamr,zkung paozthe mapping is $mappingr&rHrIrJzthe mapping is bozorKrLzthe mapping is twozthe self is $selfrzthe self is bozo)rrrr'rrr)rr$r1rr"rrr�test_keyword_arguments_safe�s$		%z(TestTemplate.test_keyword_arguments_safecCs$|j}|j}Gdd�dt�}|d�}||jdddd�d�|t|j�||jdddd�d�||j�d	�|d	�}|t|jtdddd��||j�d	�Gd
d�dt�}|d�}|j|jtdd
dd��d�dS)Nc@seZdZdZdS)z?TestTemplate.test_delimiter_override.<locals>.AmpersandTemplate�&N)rrr�	delimiterrrrr�AmpersandTemplate�srQzthis &gift is for &{who} &&ZgiftZbudrZyouzthis bud is for you &zthis &gift is for &{who} &c@seZdZdZdS)z7TestTemplate.test_delimiter_override.<locals>.PieDelims�@N)rrrrPrrrr�	PieDelims�srSz-@who likes to eat a bag of @{what} worth $100rrrz(tim likes to eat a bag of ham worth $100)rrrrrr'r0r)rr$r1rQrrSrrr�test_delimiter_override�s		"!z$TestTemplate.test_delimiter_overrideN)rrrrr#r%r(r+r.r/r2r6r:rArBrFrGrMrNrTrrrrrs"		rcCs*ddlm}tg}|j|�dS)Nr)�support)ZtestrUrZrun_unittest)rUZtest_classesrrr�	test_main�s	rV�__main__)	Zunittest�stringrrr	ZTestCaserrVrrrrr�<module>s�