Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_configparser.cpython-35.opt-1.pyc



��YfaI�@sRddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	Gdd�dej
�ZGdd�d�ZGdd�de�Z
Gd	d
�d
e
ej�ZGdd�de
ej�ZGd
d�de
ej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de
ej�ZGdd�de
ej�ZGdd�de�ZGdd�deej�ZGdd�de
ej�ZGdd �d e�ZGd!d"�d"eej�ZGd#d$�d$ej�ZGd%d&�d&e�ZGd'd(�d(eej�ZGd)d*�d*e
ej�ZGd+d,�d,�Z d-d.�Z!Gd/d0�d0ej�Z"Gd1d2�d2ej�Z#Gd3d4�d4ej�Z$Gd5d6�d6ej�Z%Gd7d8�d8ej�Z&Gd9d:�d:e
ej�Z'Gd;d<�d<ej�Z(e)d=krNej*�dS)>�N)�supportc@s^eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�ZeZ	d
S)�
SortedDictcCst|jj��S)N)�sorted�data�items)�self�r�;/opt/alt/python35/lib64/python3.5/test/test_configparser.pyrszSortedDict.itemscCst|jj��S)N)rr�keys)rrrr	r
szSortedDict.keyscCsdd�|j�D�S)NcSsg|]}|d�qS)�r)�.0�irrr	�
<listcomp>s	z%SortedDict.values.<locals>.<listcomp>)r)rrrr	�valuesszSortedDict.valuescCst|j��S)N)�iterr)rrrr	�	iteritemsszSortedDict.iteritemscCst|j��S)N)rr
)rrrr	�iterkeysszSortedDict.iterkeyscCst|j��S)N)rr)rrrr	�
itervaluesszSortedDict.itervaluesN)
�__name__�
__module__�__qualname__rr
rrrr�__iter__rrrr	r
src@smeZdZdZdZd
ZdZdZej	Z
dZejZ
ejZddd	�Zdd
d�ZdS)�CfgParserTestCaseClassF�=�:�;�#TNcCsstd|d|jd|jd|jd|jd|jd|jd|jd	|jd
|j	�
}|j
|�}|S)N�defaults�allow_no_value�
delimiters�comment_prefixes�inline_comment_prefixes�empty_lines_in_values�	dict_type�strict�default_section�
interpolation)�dictrrr r!r"r#r$r%r&�config_class)rrZ	arguments�instancerrr	�	newconfig/s								z CfgParserTestCaseClass.newconfigcCs |j|�}|j|�|S)N)r*�read_string)r�stringr�cfrrr	�
fromstring?s
z!CfgParserTestCaseClass.fromstring)rr)rr)rr)rrrrrr r!r"�configparser�
_default_dictr#r$ZDEFAULTSECTr%�_UNSETr&r*r.rrrr	r$s			rc@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#d$�Zd%d&�Zd'd(�Zd)d*�Zd+S),�
BasicTestCasec	�Cs�ddddddddd	g	}|jr7|jd
�|j�d>d?g}|j�}|j�|j}|||�|jd�}|j�|||�dd�|D�}|j�|j|j�|j�|||�|dj�}tt|��}|||�|j�}tt|��}|jt	|�t	|��x$|D]\}}|||j
�qSW||j�||j�||jdd
�d�||jdd
�d�||jdd
�d�||jdd�d�||jdd
�d�||jdd�d�||jdd�d�||jdd�d�||j
d	d�d�||jd	d�d�|j|jd	d�d�||jd	d�d�||jd	d�d�||jd	d �d!�|jr||jd
d"�d�||jdd
d#d�d�||jdd
d$d
di�d�|jtj��|jd%d
�WdQRX|jtj��|jdd&�WdQRX||jd%d
d#d�d�||jdd&d#d�d�||jdd
d#d�d�||jd'd
d#d�d�||j
d	dd#d(�d�||j
d	d)d#d(�d(�||j
d	d)d#d*�d*�|jtj��|j
d	d)�WdQRX|j|jd	dd#d+�d�|j|jd	d,d#d+�d+�||jd	d,d#d-�d-�|jtj��|jd	d,�WdQRX||jd	dd#d.�d�||jd	d/d#d0�d0�||jd	d/d#d.�d.�|jtj��|jd	d/�WdQRX||jd1dd#d.�d.�|jr%||jd
d"d#d�d�||jd
d2d#d�d�||dd
d�||dd
d�|d}||j
d�|j|j|�|jt��d3|_
WdQRX|jt��d4|_WdQRX||d
d�||dd�||dd
d�||ddd�||ddd�||ddd�||dd
d5�|jre||d
d"d�||djd
d�d�||djd
d#d�d�||djd
d$d
di�d�|jt��|d%d
WdQRX|jt��|dd&WdQRX|jt��|d%jd
d#d�WdQRX||djd&d�d�||djd&d#d�d�||djd&�d�||djd
d�d�||djd
d#d�d�|jt��|d'jd
d�WdQRX||d	j
dd(�d�||d	j
dd#d(�d�||d	j
d)d(�d(�||d	j
d)d#d(�d(�||d	j
d)d*�d*�||d	j
d)d#d*�d*�||d	j
d)�d�|j|d	jdd+�d�|j|d	jdd#d+�d�|j|d	jd,d+�d+�|j|d	jd,d#d+�d+�||d	jd,d-�d-�||d	jd,d#d-�d-�||d	jd,�d�||d	jdd.�d�||d	jdd#d.�d�||d	jd/d0�d0�||d	jd/d#d0�d0�||d	jd/d.�d.�||d	jd/d#d.�d.�||d	jd/�d�|jr�||d
jd"d�d�||d
jd"d#d�d�||d
jd2d�d�||d
jd2d#d�d�d6||jd7<d8||jd9<|j|jd��|j|jdd��|j|jd��|j|j|j��|j|jdd
�d:�|j|jdd
�d;�|j|jdd
�d<�|j|jdd7��|j|jdd7��|j|j|jd7��|j|jdd7��|j|j|jd7��|jtj��}|jd=d
�WdQRX|j|jjd@�||jdd
�d5�|d	=|jd	|k�|jt��|d	=WdQRX|jt ��||j=WdQRX|dd
=|jd
|dk�|jt��|dd
=WdQRX|jd9|dk�|jt��|dd9=WdQRX||jd9=|jd9|dk�|jt��||jd9=WdQRX|jt��|d=d
=WdQRXdS)ANz
Commented BarzFoo BarzInternationalized Stuffz	Long LinezSection\with$weird%characters[	�Spacesz
Spacey BarzSpacey Bar From The Beginning�Types�NoValue�baz�qwe�foo�bar3cSsg|]}|�qSrr)r�sectionrrr	rbs	z,BasicTestCase.basic_test.<locals>.<listcomp>�bar1�bar2�bar4zkey with spaces�valuezanother with spaceszsplat!�int�*Z42�floatg)\��(�?z0.44�booleanFZ123zstrange but acceptablezoption-without-value�fallback�varszNo Such Foo Barzno-such-foozNo Such Spacey Bar�zno-such-intZ18gz
no-such-floatz0.0Tzno-such-boolean�yesz
No Such Typeszno-such-option-without-valuezName is read-onlyzParser is read-onlyz7this line is much, much longer than my editor
likes it.�1Z
this_value�2Z
that_valuez4remove_option() failed to report existence of optionz'remove_option() failed to remove optionzIremove_option() failed to report non-existence of option that was removed�No Such Section)r6r7)r8r9)rI)!r�append�sort�sections�assertEqualrr%r�list�len�namer�get�getintZassertAlmostEqual�getfloat�
getboolean�assertRaisesr/�NoSectionError�
NoOptionError�assertIs�parser�AttributeError�KeyError�
assertTrueZremove_section�assertFalse�
has_option�
remove_option�	exception�args�
ValueError)	rr-�E�F�L�eqrPr:�cmrrr	�
basic_testGsz		


	






	%

	

	 &      
 
   	 
zBasicTestCase.basic_testcCsdj|j|j�}|jr+|d7}|j|�}|j|�|jr�|jtj	��'|j
tjdj|j���WdQRX|jtj
��'|j
tjdj|j���WdQRXnD|j
tjdj|j���|j
tjdj|j���dS)NaI[Foo Bar]
foo{0[0]}bar1
[Spacey Bar]
foo {0[0]} bar2
[Spacey Bar From The Beginning]
  foo {0[0]} bar3
  baz {0[0]} qwe
[Commented Bar]
foo{0[1]} bar4 {1[1]} comment
baz{0[0]}qwe {1[0]}another one
[Long Line]
foo{0[1]} this line is much, much longer than my editor
   likes it.
[Section\with$weird%characters[	]
[Internationalized Stuff]
foo[bg]{0[1]} Bulgarian
foo{0[0]}Default
foo[en]{0[0]}English
foo[de]{0[0]}Deutsch
[Spaces]
key with spaces {0[1]} value
another with spaces {0[0]} splat!
[Types]
int {0[1]} 42
float {0[0]} 0.44
boolean {0[0]} NO
123 {0[1]} strange but acceptable
z[NoValue]
option-without-value
z�                    [Duplicate Options Here]
                    option {0[0]} with a value
                    option {0[1]} with another value
                z�                    [And Now For Something]
                    completely different {0[0]} True
                    [And Now For Something]
                    the larch {0[1]} 1
                z�                [Duplicate Options Here]
                option {0[0]} with a value
                option {0[1]} with another value
            z�                [And Now For Something]
                completely different {0[0]} True
                [And Now For Something]
                the larch {0[1]} 1
            )�formatrr rr.rhr$rUr/�DuplicateOptionErrorr+�textwrap�dedent�DuplicateSectionError)r�
config_stringr-rrr	�
test_basic%s"	
	 zBasicTestCase.test_basiccCs�dddidddiddddd	id
dddd	iddd
ididddddddddidddddiddddd d!d"d#d$ii	}|jr�|jd%d&dii�|j�}|j|�|j|�|jrn|jtj��*|jd'd(did)d*d+ii�WdQRX|jtj	��$|jd,d-d.d/d0ii�WdQRXnD|jd1d(did2d*d+ii�|jd,d-d.d/d0ii�dS)3NzFoo Barr8r;z
Spacey Barr<zSpacey Bar From The Beginningr9r6r7z
Commented Barr=z	Long Linez7this line is much, much longer than my editor
likes it.zSection\with$weird%characters[	zInternationalized Stuffzfoo[bg]Z	BulgarianZDefaultzfoo[en]ZEnglishzfoo[de]ZDeutschr3zkey with spacesr>zanother with spaceszsplat!r4r?r@rAg)\��(�?rBF�{zstrange but acceptabler5zoption-without-valuerG�keyrZkey2�value2zDuplicate Options Here�optionzwith a valueZOPTIONzwith another valuer:ZSECTION)
r�updater*�	read_dictrhr$rUr/rmrj)r�configr-rrr	�test_basic_from_dictfsd								

	z"BasicTestCase.test_basic_from_dictcCs@|j�}|jd�|jd�|jd�|j�}|j�|j}||dddg�|jddd�||jd�dg�||jdd�dd�|jt	j
��|jddd�WdQRX|j|jdd��|j
|jdd��|jddd�x*dD]"}|j|jd|�d�q)W||jd�d	g�||jd�dg�|jdd�||jd�g�|jd
j|jd��}||jd�dg�||jdd�d�|jdj|jd�dddi�}|j|jdd��dS)N�A�a�Br>�bz@could not locate option, expecting case-insensitive option names�A-Bz	A-B value�a-b�A-b�a-Bz9has_option() returned false for option which should existz3[MySection]
Option{} first line   
	second line   
r�	MySectionrs�Optionzfirst line
second linez[section]
nekey{}nevalue
rrqr:�Key)r}r~rr|)r*�add_sectionrLrKrM�set�optionsrQrUr/rVr\r^r]r_r.rir)rr-rerf�optrrr	�test_case_sensitivity�sD



	
z#BasicTestCase.test_case_sensitivitycCs|j�}i|d<ddi|d<i|d<dd�|D�}|j�|j}|j}||tdd|jdg��||dj�dh�||dddd�|jt��d|dd<WdQRX|j	d|dk�d	|dd
<x(dD] }|j	||dkd�qW||dj�dh�||dj�dh�|dd=||dj�i�|j
dj|jd��}||dj�dh�||ddd�|j
dj|jd�dddi�}|j	d|dk�dS)Nrxrzr>rycSsg|]}|�qSrr)rr:rrr	r�s	zFBasicTestCase.test_case_sensitivity_mapping_access.<locals>.<listcomp>r{z@could not locate option, expecting case-insensitive option namesz	A-B value�A-B�a-b�A-b�a-Bz9has_option() returned false for option which should existz3[MySection]
Option{} first line   
	second line   
rr�rsr�zfirst line
second linez[section]
nekey{}nevalue
rrqr�r:)r�r�r�r�)
r*rKrMZassertCountEqualrr%r
rUr[r\r.rir)rr-rerfZelem_eqr�rrr	�$test_case_sensitivity_mapping_access�sB


		"

z2BasicTestCase.test_case_sensitivity_mapping_accesscCsr|jddi�}|j|j|jd�dd�|jddi�}|j|j|jd�dd�dS)Nr8�Bar�Fooz@could not locate option, expecting case-insensitive option namesz<could not locate option, expecting case-insensitive defaults)r*rMrQr%)rr-rrr	�test_default_case_sensitivitysz+BasicTestCase.test_default_case_sensitivitycCsN|j�}|j|tjdj|jd��|j|tjdj|jd��|j|tjd�}|j|jd�|j	sJ|j|tjd�}|j|jd
�t
jd�}|jddkr�tj}|f}ntj}|dd	f}t|d
d��}|j|||�}WdQRX|j|j|�dS)Nz[Foo]
{}val-without-opt-name
rr�No Section!
�<???>z[Foo]
  wrong-indent
zcfgparser.3rz.  # INI with as many tricky parts as possible
�encodingzutf-8)r�rr�)r�)
r*�parse_errorr/�ParsingErrorrir�MissingSectionHeaderErrorrMrarr�findfile�open)rr-�e�tricky�error�expected�frrr	�test_parse_errorss0						zBasicTestCase.test_parse_errorsc	CsTt|d�r|}ntj|�}|j|��}|j|�WdQRX|jS)N�readline)�hasattr�io�StringIOrU�	read_filer`)rr-�exc�src�siorgrrr	r�'s	zBasicTestCase.parse_errorcCs�|j�}|j|j�gd�|j|jd�d�|jtj��|jd�WdQRX|jtj��|j	ddd�WdQRX|j
|tjdd�}|j|jd�|jd�|j
|tj
dd�}|j|jd�dS)	Nz0new ConfigParser should have no defined sectionsr�z5new ConfigParser should have no acknowledged sectionsr8�barr>)r8)r�r8)r*rMrLr]Zhas_sectionrUr/rVr�r��	get_errorrar�rW)rr-r�rrr	�test_query_errors0s
zBasicTestCase.test_query_errorscCsay|j||�Wn)|k
r?}z	|SWYdd}~XnX|jd|j|jf�dS)Nzexpected exception type %s.%s)rQZfailrr)rr-r�r:rsr�rrr	r�As	zBasicTestCase.get_errorcCs�|jdjd|jd��}xntdd�D]]}|j|jdd|��|j|jdd|��|jt|jdd	|�q2WdS)
Nz�[BOOLTEST]
T1{equals}1
T2{equals}TRUE
T3{equals}True
T4{equals}oN
T5{equals}yes
F1{equals}0
F2{equals}FALSE
F3{equals}False
F4{equals}oFF
F5{equals}nO
E1{equals}2
E2{equals}foo
E3{equals}-1
E4{equals}0.1
E5{equals}FALSE AND MORE�equalsrr�ZBOOLTESTzt%dzf%dze%d)	r.rir�ranger\rTr]rUrb)rr-�xrrr	�test_booleanJs		zBasicTestCase.test_booleancCsk|j�}|jd�|jtj��}|jd�WdQRX|j}|jt|�d�|j|jd�|j	rg|jtj��6}|j
tjdj
d|jd��dd�WdQRX|j}|jt|�d�|j|jd�|jtj��&}|jd
ddd
dii�WdQRX|j}|jt|�d�|j|jd�dS)Nr�zSection 'Foo' already existsz�                    [Foo]
                    will this be added{equals}True
                    [Bar]
                    what about this{equals}True
                    [Foo]
                    oops{equals}this won't
                r�r�source�	<foo-bar>zFWhile reading from '<foo-bar>' [line  5]: section 'Foo' already existsr�r�r��val�OPTzis really `opt`zIWhile reading from '<dict>': option 'opt' in section 'Bar' already exists�<dict>)r�NN)r�r�r�)r�r�r�N)r*r�rUr/rmr`rM�strrar$r+rkrlrirrjru)rr-rgr�rrr	�test_weird_errorscs&
		*	&	zBasicTestCase.test_weird_errorscCs�dj|jd|jdd|j�}|jr;|d7}|j|�}x�d
D]�}tj�}|j|d|�|jd}|r�d	j|�}d
jd|d|j�}|jr�|d7}|j	|j
�|�qQWdS)Na8[Long Line]
foo{0[0]} this line is much, much longer than my editor
   likes it.
[{default_section}]
foo{0[1]} another very
 long line
[Long Line - With Comments!]
test {0[1]} we        {comment} can
            also      {comment} place
            comments  {comment} in
            multiline {comment} values
Zcommentrr%z![Valueless]
option-without-value
TF�space_around_delimitersz {} z�[{default_section}]
foo{equals}another very
	long line

[Long Line]
foo{equals}this line is much, much longer than my editor
	likes it.

[Long Line - With Comments!]
test{equals}we
	also
	comments
	multiline

r�z"[Valueless]
option-without-value

)TF)rirr r%rr.r�r��writerM�getvalue)rrnr-r��outputZ	delimiterZ
expect_stringrrr	�
test_write�s(	

	
	zBasicTestCase.test_writecCs�|jdjd|jd��}Gdd�dt�}|jddd�|jdd|d��|jdd	d�|jdd	|d��|jddd�|jdd	d�dS)
Nz[sect]
option1{eq}foo
rfrc@seZdZdS)z2BasicTestCase.test_set_string_types.<locals>.mystrN)rrrrrrr	�mystr�sr��sect�option1Zsplat�option2)r.rirr�r�)rr-r�rrr	�test_set_string_types�sz#BasicTestCase.test_set_string_typescCs&|jddkr |jd�tjd�}|j�}|j|dg�}|j||g�|j|jdd�d�|j�}|j|�}|j||g�|j|jdd�d�|j�}|jdg�}|j|g�|j�}|jg�}|j|g�dS)	Nrrzincompatible formatzcfgparser.1znonexistent-filezFoo Barr8�newbar)r�skipTestrr�r*�readrMrQ)rZfile1r-�parsed_filesrrr	�test_read_returns_file_list�s"
z)BasicTestCase.test_read_returns_file_listcCs |jdjd|jd��S)Nah[Foo]
bar{equals}something %(with1)s interpolation (1 step)
bar9{equals}something %(with9)s lots of interpolation (9 steps)
bar10{equals}something %(with10)s lots of interpolation (10 steps)
bar11{equals}something %(with11)s lots of interpolation (11 steps)
with11{equals}%(with10)s
with10{equals}%(with9)s
with9{equals}%(with8)s
with8{equals}%(With7)s
with7{equals}%(WITH6)s
with6{equals}%(with5)s
With5{equals}%(with4)s
WITH4{equals}%(with3)s
with3{equals}%(with2)s
with2{equals}%(with1)s
with1{equals}with

[Mutual Recursion]
foo{equals}%(bar)s
bar{equals}%(foo)s

[Interpolation Error]
name{equals}%(reference)s
r�r)r.rir)rrrr	�get_interpolation_config�s	z&BasicTestCase.get_interpolation_configc	Cs�|jdj|j�dddi�}t|jddddi��}|j�|j||�|jtj	��|jd�WdQRXdS)	Nz�
            [section]
            name {0[0]} %(value)s
            key{0[1]} |%(name)s|
            getdefault{0[1]} |%(default)s|
        r�defaultz	<default>r:rDr>zno such section)
r.rirrNrrKrMrUr/rV)rr�r-rerrr	�check_items_config�s!!
z BasicTestCase.check_items_configc	Cs�|jdj|j�dddi�}|j|j�dd�|j|j�dd�|j|j�dd�|jt��|j�WdQRXdS)	Nz�
            [section1]
            name1 {0[0]} value1
            [section2]
            name2 {0[0]} value2
            [section3]
            name3 {0[0]} value3
        rr�z	<default>r�section1�section2�section3)r.rirrM�popitemrUr[)rr-rrr	�test_popitems!zBasicTestCase.test_popitemcCs�|jddi�}|j|j|jd�dd�ddddi|d	<|j|j�d	g�|jt|d	j��dddh�|j�|jt|j��t��|jt||jj��dh�dS)
Nr8r�r�z@could not locate option, expecting case-insensitive option namesr��value1r�rrZzing)r*rMrQr%rLr�r
�clear)rr-rrr	�
test_clears)
zBasicTestCase.test_clearcCs�|jdj|j�dddi�}|jt|dj��ddh�|jt|dj��d	dh�|jt|d
j��ddh�|j|ddd�|j|dd	d
�|j|d
dd�|j|j�ddd
g�ddi|d<|jt|dj��ddh�|j|ddd�|jd	|d�|j|j�ddd
g�i|d
<|jt|d
j��dh�|jd|d
�|j|j�ddd
g�i||j<|jt||jj��t��|jt|dj��dh�|jt|dj��dh�|jt|d
j��t��|j|j�ddd
g�dS)Nz�
            [section1]
            name1 {0[0]} value1
            [section2]
            name2 {0[0]} value2
            [section3]
            name3 {0[0]} value3
        rZnameDZvalueDr�Zname1Znamedr�Zname2r�Zname3r�rrZvalue3Zname22Zvalue22)	r.rirrMr�r
rL�assertNotInr%)rr-rrr	�test_setitem!s0!&&&&
#
&###zBasicTestCase.test_setitemcCs�|jr|jd�tjdj|jd��}|j�}|jtj	��|j
|�WdQRX|j|jdd�d�|j|ddd�dS)Nz2if no_value is allowed, ParsingError is not raisedzC            [DEFAULT]
            test {0} test
            invalidrZDEFAULT�test)
rr�rkrlrirr*rUr/r�r+rMrQ)rZinvalidr-rrr	�test_invalid_multiline_valueAs	
z*BasicTestCase.test_invalid_multiline_valueN)rrrrhrorwr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr	r2Es*�AI*(
		6
 r2c@seZdZejZdZdS)�StrictTestCaseTN)rrrr/�RawConfigParserr(r$rrrr	r�Qs	r�c@smeZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZdS)�ConfigParserTestCasecCs�|j�}|j}||jdd�d�||jdd�d�||jdd�d�|j|tjdd�}|jtjkr�|j|jd
�n(t	|jtj
�r�|j|jd�dS)Nr�r�z%something with interpolation (1 step)�bar9z.something with lots of interpolation (9 steps)�bar10z/something with lots of interpolation (10 steps)�bar11�5something %(with11)s lots of interpolation (11 steps))r�r�r�)r�r�r�)r�rMrQr�r/�InterpolationDepthErrorr&r1ra�
isinstance�LegacyInterpolation)rr-rfr�rrr	�test_interpolationYs	
z'ConfigParserTestCase.test_interpolationcCs�|j�}|j|tjdd�}|j|jd�|j|jd�|j|jd�|jtj	kr�|j|j
d�n(t|jtj�r�|j|j
d�dS)N�Interpolation ErrorrP�	reference�
%(reference)s)rPr�r�r�)rPr�r�r�)
r�r�r/�InterpolationMissingOptionErrorrMr�r:rsr&r1rar�r�)rr-r�rrr	� test_interpolation_missing_valueis
z5ConfigParserTestCase.test_interpolation_missing_valuecCs |jd	d
ddd
g�dS)Nr��	<default>�
getdefault�|<default>|rq�|value|rPr>)r�r�)r�r�)rqr�)rPr>)r>r>)r�)rrrr	�
test_itemsws
	zConfigParserTestCase.test_itemsc
Cs�|jdjd|jd��}|j|jdd�d�|jtjkro|j|jdd�d�n<t|jtj	�r�|j
t��|jdd�WdQRXdS)	Nzc[section]
option1{eq}xxx
option2{eq}%(option1)s/xxx
ok{eq}%(option1)s/%%s
not_ok{eq}%(option2)s/%%srfrr:�okzxxx/%sZnot_okz
xxx/xxx/%s)r.rirrMrQr&r/r1r�r�rU�	TypeError)rr-rrr	�test_safe_interpolation~sz,ConfigParserTestCase.test_safe_interpolationcCs�|jdjd|jd��}|j|jdd�d�|jt|jddd�|jt|jddd�|jt|jddd	�|j|jdd�d�|jdd
d�|j|jdd
�d�dS)
Nz[sect]
option1{eq}foo
rfrr�r�r8z%foozfoo%zf%oor�zfoo%%barzfoo%bar)r.rirrMrQrUrbr�)rr-rrr	�#test_set_malformatted_interpolation�sz8ConfigParserTestCase.test_set_malformatted_interpolationcCs|jdjd|jd��}|jt|jddd�|jt|jddd�|jt|jddt��|jt|jddd�|jt|jddd�|jt|jddt��|jt|jdd	d
�|jt|jd	�dS)Nz[sect]
option1{eq}foo
rfrr�r�rg�?r�rpzinvalid opt name!)r.rirrUr�r��objectr�)rr-rrr	�test_set_nonstring_types�sz-ConfigParserTestCase.test_set_nonstring_typescCs)|j�}|jt|j|j�dS)N)r*rUrbr�r%)rr-rrr	�test_add_section_default�sz-ConfigParserTestCase.test_add_section_defaultN)
rrrr/�ConfigParserr(r�r�r�r�r�r�r�rrrr	r�Vs	r�c@sdeZdZejZdZejd�j	�Z
dd�Zdd�Zdd�Z
d	d
�ZdS)�#ConfigParserTestCaseNoInterpolationNz�
        [numbers]
        one = 1
        two = %(one)s * 2
        three = ${common:one} * 3

        [hexen]
        sixteen = ${numbers:two} * 8
    cCsd|j|ddd�|j|ddd�|j|ddd�|j|dd	d
�dS)NZnumbers�onerG�twoz%(one)s * 2�threez${common:one} * 3ZhexenZsixteenz${numbers:two} * 8)rM)rr-rrr	�assertMatchesIni�sz4ConfigParserTestCaseNoInterpolation.assertMatchesInicCs#|j|j�}|j|�dS)N)r.�inir�)rr-rrr	�test_no_interpolation�sz9ConfigParserTestCaseNoInterpolation.test_no_interpolationcCs&|j�}|j|jd��dS)N�)r*�assertIsNoner+)rr-rrr	�test_empty_case�sz3ConfigParserTestCaseNoInterpolation.test_empty_casecCsCGdd�dtj�}|�}|j|j�|j|�dS)Nc@seZdZdZdS)zbConfigParserTestCaseNoInterpolation.test_none_as_default_interpolation.<locals>.CustomConfigParserN)rrrZ_DEFAULT_INTERPOLATIONrrrr	�CustomConfigParser�sr�)r/r�r+r�r�)rr�r-rrr	�"test_none_as_default_interpolation�s	zFConfigParserTestCaseNoInterpolation.test_none_as_default_interpolation)rrrr/r�r(r&rkrl�stripr�r�r�r�r�rrrr	r��s	r�c@s1eZdZejZej�Zdd�ZdS)�'ConfigParserTestCaseLegacyInterpolationcCs�|jdjd|jd��}|j|jdd�d�|jddd�|j|jdd�d�|jddd�|j|jdd�d�|jddd	�|j|jdd�d	�|jdd
d�|j|jdd
�d�dS)Nz[sect]
option1{eq}foo
rfrr�r�r8z%foozfoo%zf%oor�zfoo%%bar)r.rirrMrQr�)rr-rrr	r��szKConfigParserTestCaseLegacyInterpolation.test_set_malformatted_interpolationN)	rrrr/r�r(r�r&r�rrrr	r��s	r�c@s"eZdZdZdZdZdS)	�)ConfigParserTestCaseNonStandardDelimiters�:=�$�//�"N)r�r)rr)rr)rrrrr r!rrrr	r��sr�c@seZdZdZdS)�-ConfigParserTestCaseNonStandardDefaultSectionZgeneralN)rrrr%rrrr	r�src@sOeZdZejZdjdd�Zdd�Zdd�Z	dd	�Z
d
S)�MultilineValuesTestCasezSI'm having spam spam spam spam spam spam spam beaked beans spam spam spam and spam!� z	
c	Cs�|j�}xftd�D]X}dj|�}|j|�x3td�D]%}|j|dj|�|j�qHWqWttjd��}|j	|�WdQRXdS)N�dz	section{}�
z
lovely_spam{}�w)
r*r�rir�r��wonderful_spamr�r�TESTFNr�)rr-r
�s�jr�rrr	�setUp�s
'zMultilineValuesTestCase.setUpcCstjtj�dS)N)�os�unlinkrr
)rrrr	�tearDownsz MultilineValuesTestCase.tearDowncCsa|j�}ttj��}|j|�WdQRX|j|jdd�|jjdd��dS)NZsection8Zlovely_spam4z	
�
)	r*r�rr
r�rMrQr	�replace)rZcf_from_filer�rrr	� test_dominating_multiline_valuess
z8MultilineValuesTestCase.test_dominating_multiline_valuesN)rrrr/r�r(rr	r
rrrrrr	r�s	
rc@s=eZdZejZdd�Zdd�Zdd�ZdS)�RawConfigParserTestCasecCs}|j�}|j}||jdd�d�||jdd�d�||jdd�d�||jdd�d	�dS)
Nr�r�z*something %(with1)s interpolation (1 step)r�z3something %(with9)s lots of interpolation (9 steps)r�z5something %(with10)s lots of interpolation (10 steps)r�z5something %(with11)s lots of interpolation (11 steps))r�rMrQ)rr-rfrrr	r�s	z*RawConfigParserTestCase.test_interpolationcCs |jd
ddd
dg�dS)Nr��	<default>r��
|%(default)s|rq�
|%(name)s|rP�	%(value)sr>)r�r)r�r)rqr)rPr)r>r>)r�)rrrr	r� s
	z"RawConfigParserTestCase.test_itemscCsr|j�}|jd�|jddd�|jddddddddd	d
g�|jdddd
i�|j|jdd�d�|j|jdd�ddddddd	d
g�|j|jdd�dd
i�|jd�|jddd�|j|jdd�d�|jtjkrndd�|_|jddd�|j|jdd�d�dS)Nz
non-stringr?rrNr��r���
r'Zpign��!	@rpzthis is sickTcSs|S)Nr)r�rrr	�<lambda>7szBRawConfigParserTestCase.test_set_nonstring_types.<locals>.<lambda>)	r*r�r�rMrQZ_dictr/r0�optionxform)rr-rrr	r�'s 
+"
z0RawConfigParserTestCase.test_set_nonstring_typesN)	rrrr/r�r(r�r�r�rrrr	rs	rc@s"eZdZdZdZdZdS)	�,RawConfigParserTestCaseNonStandardDelimiters�:=r�//rN)r r)r!r)r!r)rrrrr r!rrrr	r<src@s7eZdZejZd	Zd
ZdZdd�Z	dS)�RawConfigParserTestSambaConfrr�----�//FcCs�tjd�}|j�}|j|dgdd�}|j||g�ddddd	d
dg}|j|j�|�|j|jdd�d
�|j|jdd�d�|j|jdd�d�|j|jd
d�d�dS)Nzcfgparser.2znonexistent-filer�zutf-8�globalZhomesZprinterszprint$z
pdf-generatorZtmpZAgustinZ	workgroupZMDKGROUPzmax log size�2zhosts allowz127.zecho commandz
cat %s; rm %s)rr�r*r�rMrLrQrR)rZsmbconfr-r�rLrrr	�test_readingHs	z)RawConfigParserTestSambaConf.test_readingN)rrr#)r$)
rrrr/r�r(r r!r"r'rrrr	r"Bs
	r"c@s�eZdZejZej�ZdZdZ	dddd�Z
dd�Zdd	�Zd
d�Z
dd
�Zdd�Zdd�ZdS)�)ConfigParserTestCaseExtendedInterpolation�commonTNcCs/|j|�}|r||_|j|�|S)N)r*rr+)rr,rrr-rrr	r.\s
	
z4ConfigParserTestCaseExtendedInterpolation.fromstringcCs�|jtjd�j��}|j}||ddd�||ddd�||ddd�||ddd�||ddd	�||dd
d�||ddd
�||ddd�||ddd�||ddd�||ddd�||ddd�||ddd�||ddd�||ddd�||dd
d�||ddd�dS)Na
            [common]
            favourite Beatle = Paul
            favourite color = green

            [tom]
            favourite band = ${favourite color} day
            favourite pope = John ${favourite Beatle} II
            sequel = ${favourite pope}I

            [ambv]
            favourite Beatle = George
            son of Edward VII = ${favourite Beatle} V
            son of George V = ${son of Edward VII}I

            [stanley]
            favourite Beatle = ${ambv:favourite Beatle}
            favourite pope = ${tom:favourite pope}
            favourite color = black
            favourite state of mind = paranoid
            favourite movie = soylent ${common:favourite color}
            favourite song = ${favourite color} sabbath - ${favourite state of mind}
        r)zfavourite BeatleZPaulzfavourite colorZgreenZtomzfavourite bandz	green dayzfavourite popezJohn Paul IIZsequelz
John Paul IIIZambvZGeorgezson of Edward VIIzGeorge Vzson of George Vz	George VIZstanleyZblackzfavourite state of mindZparanoidzfavourite moviez
soylent greenzfavourite songzblack sabbath - paranoid)r.rkrlr�rM)rr-rfrrr	�test_extended_interpolationcs*	zEConfigParserTestCaseExtendedInterpolation.test_extended_interpolationcCsn|jtjd�j��}|jtj��|ddWdQRX|jtj��|ddWdQRXdS)Nz�
            [one for you]
            ping = ${one for me:pong}

            [one for me]
            pong = ${one for you:ping}

            [selfish]
            me = ${me}
        zone for youZpingZselfish�me)r.rkrlr�rUr/r�)rr-rrr	�test_endless_loop�s	z;ConfigParserTestCaseExtendedInterpolation.test_endless_loopc
Cs�|jd�}|j|ddd�|j|ddd�|j|ddd�tj}|j|��}|dd	WdQRX|j|jjd
�|j|jjdd�dS)
Nz�
            [dollars]
            $var = $$value
            $var2 = ${$var}
            ${sick} = cannot interpolate me

            [interpolated]
            $other = ${dollars:$var}
            $trying = ${dollars:${sick}}
        Zdollarsz$varz$valueZinterpolatedz$otherz${sick}zcannot interpolate mez$tryingzdollars:${sickrz${dollars:${sick}})r.rMr/r�rUr`r�ra)rr-Zexception_classrgrrr	�test_strange_options�s			z>ConfigParserTestCaseExtendedInterpolation.test_strange_optionscCs�tjd�j�}|j|�}|j}||ddd�||ddd�||ddd�||ddd	�||d
dd�||d
d
d�dS)Naj
            [common]
            optionlower = value
            OptionUpper = Value

            [Common]
            optionlower = a better ${common:optionlower}
            OptionUpper = A Better ${common:OptionUpper}

            [random]
            foolower = ${common:optionlower} redefined
            FooUpper = ${Common:OptionUpper} Redefined
        r)Zoptionlowerr>ZOptionUpper�Value�Commonza better valuezA Better Value�randomZfoolowerzvalue redefinedZFooUpperzA Better Value Redefined)rkrlr�r.rM)rr�r-rfrrr	�test_case_sensitivity_basic�s	zEConfigParserTestCaseExtendedInterpolation.test_case_sensitivity_basiccCs�tjd�j�}|jtj��|j|�}WdQRX|j|ddd��}|j}||ddd�||ddd	�||d
dd�||d
dd�||d
dd�||d
dd�dS)Na8
            [common]
            option = value
            Option = Value

            [Common]
            option = a better ${common:option}
            Option = A Better ${common:Option}

            [random]
            foo = ${common:option} redefined
            Foo = ${Common:Option} Redefined
        rcSs|S)Nr)r�rrr	r�sz[ConfigParserTestCaseExtendedInterpolation.test_case_sensitivity_conflicts.<locals>.<lambda>r)rsr>r�r.r/za better valuezA Better Valuer0r8zvalue redefinedr�zA Better Value Redefined)rkrlr�rUr/rjr.rM)rr�r-rfrrr	�test_case_sensitivity_conflicts�s	zIConfigParserTestCaseExtendedInterpolation.test_case_sensitivity_conflictsc-Cs�|jd�}|jtj��|ddWdQRX|jtj��|ddWdQRX|jtj��|ddWdQRX|jtj��|ddWdQRX|jtj��|ddWdQRX|jt��d|dd	<WdQRXdS)
Na
            [interpolation fail]
            case1 = ${where's the brace
            case2 = ${does_not_exist}
            case3 = ${wrong_section:wrong_value}
            case4 = ${i:like:colon:characters}
            case5 = $100 for Fail No 5!
        zinterpolation failZcase1Zcase2Zcase3Zcase4Zcase5z
BLACK $ABBATHZcase6)r.rUr/�InterpolationSyntaxErrorr�rb)rr-rrr	�test_other_errors�s	z;ConfigParserTestCaseExtendedInterpolation.test_other_errors)rrrr/r�r(�ExtendedInterpolationr&r%r$r.r*r,r-r1r2r4rrrr	r(Vs	-r(c@seZdZdZdS)�ConfigParserTestCaseNoValueTN)rrrrrrrr	r6sr6c@sIeZdZejZdhZdhZdZdd�Z	dd�Z
dS)	�ConfigParserTestCaseTrickyFilerrTcCs
tjd�}|j�}|jt|j|dd��d�|j|j�ddddd	d
dg�|j|j|jdd
ddi�d�|j	t
��*|j|jdddd
ddi�WdQRX|jt|jdd�jd��d�|jt|jdd�jd��d�d}|j
|j|d��|j|j|d�d�|jt|jd��d�|j	tj��|jd	�WdQRX|j|jd
d�d�|j|jd
d�|jd
d��|j|jdd�d�dS)Nzcfgparser.3r�zutf-8rZstrangeZ
corruptionz&yeah, sections can be indented as wellzanother one!zno values hereztricky interpolationzmore interpolationZgorDZinterpolatez-1�rawT�otherr�r>rzare they subsectionszlets use some Unicodeu	片仮名r�Zletszdo thiszgo shopping���)rr�r*rMrOr�rLrRr%rUrbrQ�splitr]rTrr/r�)rr�r-Zlongnamerrr	�test_cfgparser_dot_3s6%
++z3ConfigParserTestCaseTrickyFile.test_cfgparser_dot_3cCsItjd�}|j�}|jt��|j|dd�WdQRXdS)Nzcfgparser.3r��ascii)rr�r*rU�UnicodeDecodeErrorr�)rr�r-rrr	�test_unicode_failure+sz3ConfigParserTestCaseTrickyFile.test_unicode_failureN)rrrr/r�r(rr rr=r@rrrr	r7s			 r7c@s@eZdZdZdZdd�Zdd�Zdd�Zd	S)
�Issue7005TestCasezrTest output when None is set() as a value and allow_no_value == False.

    http://bugs.python.org/issue7005

    z[section]
option = None

cCsR|dd�}|jd�|jddd�tj�}|j|�|j�S)NrFr:rs)r�r�r�r�r�r�)rr(�cpr�rrr	�prepare;s

zIssue7005TestCase.preparecCsMtjdd�}|jd�|jt��|jddd�WdQRXdS)NrFr:rs)r/r�r�rUr�r�)rrBrrr	�test_none_as_value_stringifiedDs
z0Issue7005TestCase.test_none_as_value_stringifiedcCs)|jtj�}|j||j�dS)N)rCr/r�rM�expected_output)rr�rrr	�"test_none_as_value_stringified_rawJsz4Issue7005TestCase.test_none_as_value_stringified_rawN)rrr�__doc__rErCrDrFrrrr	rA2s
	rAc@s"eZdZeZdd�ZdS)�SortedTestCasecCsB|jd�}tj�}|j|�|j|j�d�dS)Nz [b]
o4=1
o3=2
o2=3
o1=4
[a]
k=v
z,[a]
k = v

[b]
o1 = 4
o2 = 3
o3 = 2
o4 = 1

)r.r�r�r�rMr�)rr-r�rrr	�test_sortedRs

zSortedTestCase.test_sortedN)rrrrr#rIrrrr	rHOsrHc@s1eZdZejZdZdZdd�ZdS)�CompatibleTestCasez#;rcCsvtjd�}|j|�}|j|jdd�d�|j|jdd�d�|j|jdd�d�dS)	Nz�        [Commented Bar]
        baz=qwe ; a comment
        foo: bar # not a comment!
        # but this is a comment
        ; another comment
        quirk: this;is not a comment
        ; a space must precede an inline comment
        z
Commented Barr8zbar # not a comment!r6r7Zquirkzthis;is not a comment)rkrlr.rMrQ)rrnr-rrr	�test_comment_handlingks	z(CompatibleTestCase.test_comment_handlingN)	rrrr/r�r(r r!rKrrrr	rJfs	rJc@s(eZdZejZddd�ZdS)�CopyTestCaseNcCs�|j|�}|j|�|j�}|j|�xd|j�D]V}|j|jkr]qBx8||jj�D]#\}}|||krq||=qqWqBW|S)N)r*r+rurrPr%r)rr,rr-Zcf_copyr:r�r>rrr	r.s

 zCopyTestCase.fromstring)rrrr/r�r(r.rrrr	rL|s	rLc@s(eZdZdd�Zdd�ZdS)�FakeFilec	CsEtjd�}t|��#}|j�|_|jj�WdQRXdS)Nzcfgparser.1)rr�r��	readlines�lines�reverse)r�	file_pathr�rrr	�__init__�szFakeFile.__init__cCs t|j�r|jj�SdS)Nr�)rOrO�pop)rrrr	r��s
zFakeFile.readlineN)rrrrRr�rrrr	rM�srMccs.|j�}x|r)|V|j�}qWdS)z+As advised in Doc/library/configparser.rst.N)r�)r��linerrr	�readline_generator�s	rUc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ReadFileTestCasecCs�tjd�g}y|j|djd��Wntk
rDYnXxy|D]q}tj�}t|��}|j|�WdQRX|j	d|�|j	d|d�|j
|ddd�qLWdS)Nzcfgparser.1r�utf8zFoo Barr8r�)rr�rJ�encode�UnicodeEncodeErrorr/r�r�r��assertInrM)rZ
file_pathsrQrYr�rrr	�	test_file�s

zReadFileTestCase.test_filecCswtjd�j�jd�}tj�}|j|�|jd|�|jd|d�|j|ddd�dS)Nz%
        [Foo Bar]
        foo=newbarrzFoo Barr8r�)	rkrlr�r<r/r�r�rZrM)rrOrYrrr	�
test_iterable�s
zReadFileTestCase.test_iterablecCs�tj�}|jt��|jt��WdQRX|jtt���|jd|�|jd|d�|j|ddd�dS)z
Issue #11670.NzFoo Barr8r�)	r/r�rUr�r�rMrUrZrM)rrYrrr	�test_readline_generator�sz(ReadFileTestCase.test_readline_generatorc Cs�tjd�j�jd�}tj�}|jtj��}|j|dd�WdQRX|j	t
|j�d�tjd�j�jd�}tj�}|jtj��}|j|dd�WdQRX|j	t
|j�d�tjd	�j�jd�}tj�}|jtj
��}|j|dd�WdQRX|j	t
|j�d
�tjd�j�jd�}tj�}|jtj��}|j|dd�WdQRX|j	t
|j�d�dS)
z
Issue #18260.z"
        [badbad]
        [badbad]rr�sbadbadNzGWhile reading from b'badbad' [line  2]: section 'badbad' already existsz5
        [badbad]
        bad = bad
        bad = badzWWhile reading from b'badbad' [line  3]: option 'bad' in section 'badbad' already existsz
        [badbad]
        = badz=Source contains parsing errors: b'badbad'
	[line  2]: '= bad'z"
        [badbad
        bad = badzDFile contains no section headers.
file: b'badbad', line: 1
'[badbad')rkrlr�r<r/r�rUrmr�rMr�r`rjr�r�)rrOrYZdserrr	�test_source_as_bytes�s@z%ReadFileTestCase.test_source_as_bytesN)rrrr[r\r]r^rrrr	rV�s

rVc@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�CoverageOneHundredTestCasez"Covers edge cases in the codebase.cCs�tjdd�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|jt|�d�dS)Nr:rsz3Option 'option' in section 'section' already exists)r:rsNN)	r/rjrMr:rsr��linenorar�)rr�rrr	�test_duplicate_option_error�sz6CoverageOneHundredTestCase.test_duplicate_option_errorcCsRtjddd�}|j|jd�|j|jd�|j|jd�dS)Nrsr:�rawval)rsr:rb)r/r�rMrarsr:)rr�rrr	�test_interpolation_depth_errors
	z9CoverageOneHundredTestCase.test_interpolation_depth_errorcCs/|jt��}tj�WdQRX|jt|j�d�|jt��}tjdddd�WdQRX|jt|j�d�tjdd�}|j|jd�tj	dd��F}tj
dt�|j|jd�d|_|j|jd�WdQRXx$|D]}|j
|jtk�qWdS)Nz%Required argument `source' not given.r��filenamez:Cannot specify both `filename' and `source'. Use `source'.�recordT�always)rUrbr/r�rMr�r`r��warnings�catch_warnings�simplefilter�DeprecationWarningrdr\�category)rrgr�r�warningrrr	�test_parsing_errors	
z-CoverageOneHundredTestCase.test_parsing_errorcCs�tj�}|jd�|jtj��}|ddWdQRX|jt|j�d�|jtj��}|ddWdQRX|jt|j�d�dS)Nz�
            [section]
            invalid_percent = %
            invalid_reference = %(()
            invalid_variable = %(does_not_exist)s
        r:Zinvalid_percentz.'%' must be followed by '%' or '(', found: '%'Zinvalid_referencez+bad interpolation variable reference '%(()')r/r�r+rUr3rMr�r`)rrYrgrrr	�test_interpolation_validationsz8CoverageOneHundredTestCase.test_interpolation_validationcCs�tjd�}tj�}tjdd��*}tjdt�|j|dd�WdQRXx$|D]}|j	|j
tk�qaW|jt|�d�|j|dd	d
�dS)Nz2
        [section]
        option = value
        reTrfrdr�rr:rsr>)
r�r�r/r�rgrhrirjZreadfpr\rkrMrO)rr�rYrrlrrr	�test_readfp_deprecation/s	
z2CoverageOneHundredTestCase.test_readfp_deprecationcCsctjdd��#}tjdt�tj�}WdQRXx$|D]}|j|jtk�q?WdS)NreTrf)rgrhrirjr/ZSafeConfigParserr\rk)rrrYrlrrr	�!test_safeconfigparser_deprecation=s

z<CoverageOneHundredTestCase.test_safeconfigparser_deprecationcCs7tj�}|jd�|jt|d�d�dS)Nz7
            [section]
            key = value
        r:z<Section: section>)r/r�r+rM�repr)rrYrrr	�test_sectionproxy_reprDsz1CoverageOneHundredTestCase.test_sectionproxy_reprcCs�tj�}ddl}|j|jd<|jd�|jd|j�|j|jdd�d�|j|jdd�d	�|j|djd�d�|j|djd�d	�|`|j	t
��|jdd�WdQRX|jd|j�|jd=|jd|j�|j	t
��|jdd�WdQRX|j	t
��|djd�WdQRX|j	t
��|djd�WdQRXdS)
Nr�decimalzS
            [s1]
            one = 1
            [s2]
            two = 2
        �s1r�r�s2r�r)r/r�rs�Decimal�
convertersr+rZrM�
getdecimalrUrZr�)rrYrsrrr	�"test_inconsistent_converters_stateLs,
z=CoverageOneHundredTestCase.test_inconsistent_converters_stateN)rrrrGrarcrmrnrorprrryrrrr	r_�s
r_c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ExceptionPicklingTestCasezBTests for issue #13760: ConfigParser exceptions are not picklable.cCs�ddl}tjd�}xnt|jd�D]Y}|j||�}|j|�}|j|j|j�|jt	|�t	|��q/WdS)Nrr>r)
�pickler/�Errorr��HIGHEST_PROTOCOL�dumps�loadsrM�messagerq)rr{�e1�proto�pickled�e2rrr	�
test_errorlsz$ExceptionPicklingTestCase.test_errorcCs�ddl}tjd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|jt|�t|��q/WdS)Nrr:r)r{r/rVr�r}r~rrMr�rar:rq)rr{r�r�r�r�rrr	�test_nosectionerrorusz-ExceptionPicklingTestCase.test_nosectionerrorcCs�ddl}tjdd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|jt|�t|��q2WdS)Nrrsr:r)
r{r/rWr�r}r~rrMr�rar:rsrq)rr{r�r�r�r�rrr	�test_nooptionerror�sz,ExceptionPicklingTestCase.test_nooptionerrorcCs�ddl}tjddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|j|j|j�|jt
|�t
|��q5WdS)Nrr:r�rpr)r{r/rmr�r}r~rrMr�rar:r�r`rq)rr{r�r�r�r�rrr	�test_duplicatesectionerror�sz4ExceptionPicklingTestCase.test_duplicatesectionerrorcCsddl}tjdddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|j|j|j�|j|j
|j
�|jt|�t|��q8WdS)Nrr:rsr�rpr)r{r/rjr�r}r~rrMr�rar:rsr�r`rq)rr{r�r�r�r�rrr	�test_duplicateoptionerror�s	z3ExceptionPicklingTestCase.test_duplicateoptionerrorcCs�ddl}tjddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|jt|�t|��q5WdS)Nrrsr:�msgr)
r{r/ZInterpolationErrorr�r}r~rrMr�rar:rsrq)rr{r�r�r�r�rrr	�test_interpolationerror�sz1ExceptionPicklingTestCase.test_interpolationerrorcCs�ddl}tjdddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|j|j|j�|jt
|�t
|��q8WdS)Nrrsr:rbr�r)r{r/r�r�r}r~rrMr�rar:rsr�rq)rr{r�r�r�r�rrr	�$test_interpolationmissingoptionerror�sz>ExceptionPicklingTestCase.test_interpolationmissingoptionerrorcCs�ddl}tjddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|jt|�t|��q5WdS)Nrrsr:r�r)
r{r/r3r�r}r~rrMr�rar:rsrq)rr{r�r�r�r�rrr	�test_interpolationsyntaxerror�sz7ExceptionPicklingTestCase.test_interpolationsyntaxerrorcCs�ddl}tjddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|jt|�t|��q5WdS)Nrrsr:rbr)
r{r/r�r�r}r~rrMr�rar:rsrq)rr{r�r�r�r�rrr	�test_interpolationdeptherror�s	z6ExceptionPicklingTestCase.test_interpolationdeptherrorcCs�ddl}tjd�}|jdd�|jdd�|jdd�x�t|jd�D]�}|j||�}|j|�}|j|j	|j	�|j|j
|j
�|j|j|j�|j|j|j�|jt
|�t
|��q_Wtjd	d	�}|jdd�|jdd�|jdd�x�t|jd�D]�}|j||�}|j|�}|j|j	|j	�|j|j
|j
�|j|j|j�|j|j|j�|jt
|�t
|��qTWdS)
Nrr�rZline1rZline2rZline3rd)r{r/r�rJr�r}r~rrMr�rar��errorsrq)rr{r�r�r�r�rrr	�test_parsingerror�s2 z+ExceptionPicklingTestCase.test_parsingerrorcCs�ddl}tjddd�}x�t|jd�D]�}|j||�}|j|�}|j|j|j�|j|j	|j	�|j|j
|j
�|j|j|j�|j|j|j�|jt
|�t
|��q5WdS)NrrdrprTr)r{r/r�r�r}r~rrMr�rarTr�r`rq)rr{r�r�r�r�rrr	�test_missingsectionheadererror�sz8ExceptionPicklingTestCase.test_missingsectionheadererrorN)rrrrGr�r�r�r�r�r�r�r�r�r�r�rrrr	rzis	

rzc@s"eZdZdZdd�ZdS)�InlineCommentStrippingTestCasez}Tests for issue #14590: ConfigParser doesn't strip inline comment when
    delimiter occurs earlier without preceding space..cCs�tjdd�}|jd�|d}|j|dd�|j|d	d
�|j|dd�|j|d
d�|j|dd�|j|dd�|j|dd�|d}|j|dd�|j|d	d
�|j|dd�dS)Nr!rr�//a�
        [section]
        k1 = v1;still v1
        k2 = v2 ;a comment
        k3 = v3 ; also a comment
        k4 = v4;still v4 ;a comment
        k5 = v5;still v5 ; also a comment
        k6 = v6;still v6; and still v6 ;a comment
        k7 = v7;still v7; and still v7 ; also a comment

        [multiprefix]
        k1 = v1;still v1 #a comment ; yeah, pretty much
        k2 = v2 // this already is a comment ; continued
        k3 = v3;#//still v3# and still v3 ; a comment
        r:Zk1zv1;still v1Zk2Zv2Zk3Zv3Zk4zv4;still v4Zk5zv5;still v5Zk6zv6;still v6; and still v6Zk7zv7;still v7; and still v7Zmultiprefixzv3;#//still v3# and still v3)rrr�)r/r�r+rM)r�cfgrrrr	�test_strippings 		

z-InlineCommentStrippingTestCase.test_strippingN)rrrrGr�rrrr	r�sr�c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�ExceptionContextTestCasezO Test that implementation details doesn't leak
    through raising exceptions. c
Csctj�}|jd�|jtj�}|�|jdd�WdQRX|j|jjd�dS)Nz�
        [Paths]
        home_dir: /Users
        my_dir: %(home_dir1)s/lumberjack
        my_pictures: %(my_dir)s/Pictures
        �Paths�my_dirT)	r/r�r+rUr�rQrXr`�__suppress_context__)rrYrgrrr	�test_get_basic_interpolation,sz5ExceptionContextTestCase.test_get_basic_interpolationc
Csotjdtj��}|jd�|jtj�}|�|jdd�WdQRX|j|jj	d�dS)Nr&z�
        [Paths]
        home_dir: /Users
        my_dir: ${home_dir1}/lumberjack
        my_pictures: ${my_dir}/Pictures
        r�r�T)
r/r�r5r+rUr�rQrXr`r�)rrYrgrrr	�test_get_extended_interpolation9s	z8ExceptionContextTestCase.test_get_extended_interpolationc
Cs\tj�}|jd�|jtj��}|jd�WdQRX|j|jjd�dS)Nz2
        [Paths]
        home_dir: /Users
        r�T)	r/r�r+rUrVr�rXr`r�)rrYrgrrr	�test_missing_optionsGsz-ExceptionContextTestCase.test_missing_optionscCsUtj�}|jtj��}|jddd�WdQRX|j|jjd�dS)N�Section1�an_intZ15T)r/r�rUrVr�rXr`r�)rrvrgrrr	�test_missing_sectionQsz-ExceptionContextTestCase.test_missing_sectionc
CsRtj�}|jtj��}|jdd�WdQRX|j|jjd�dS)Nr�r�T)r/r�rUrVr_rXr`r�)rrvrgrrr	�test_remove_optionWsz+ExceptionContextTestCase.test_remove_optionN)	rrrrGr�r�r�r�r�rrrr	r�(s

r�cs@eZdZdZejZd�fdd�Zdd�Z�S)�ConvertersTestCasez Introduced in 3.5, issue #18159.Ncs,t�jd|�}dd�|jd<|S)NrcSsdd�|j�D�S)NcSs(g|]}|j�r|j��qSr)r�)rr�rrr	res	zBConvertersTestCase.newconfig.<locals>.<lambda>.<locals>.<listcomp>)r<)�vrrr	resz.ConvertersTestCase.newconfig.<locals>.<lambda>rN)�superr*rw)rrr))�	__class__rr	r*cszConvertersTestCase.newconfigcACs�|j�}|jd|j�|jd|j�|j|jd�|j|jd�|j|jd�|j|jd�|jt|j�d�|jt��dd�|jd<WdQRX|jt��d	d�|jd<WdQRX|j	d
�|d}|j|dd
�|j|dd�|j|dd�|j|dd�|j|dd�|j|j
dd�d
�|j|j
dd�d�|j|j
dd�d�|j|j
dd�d�|j|j
dd�d�|j|j
dd�d
�|j|jdd�d�|j|jdd�d�|j|j
dd�dddddddg�|j|jdd�d�|j|j
d�d
�|j|jd�d�|j|jd�d�|j|j
d�dddddddg�|j|jd�d�|jt��|jdd�WdQRX|jt��|jd�WdQRXddl}|j|jd<|jd|j�|j|jd�|jt|j�d�|jd�}|j|jdd�|�|j|jd�|�|jd=|jd|j�|jt|j�d�|jt��|jdd�WdQRX|jt��|jd�WdQRX|jt��|jd=WdQRX|jt��|jd=WdQRX|jt��|jd=WdQRXdS) NrBrNr?rAr:cSs|S)Nr)r�rrr	rssz4ConvertersTestCase.test_converters.<locals>.<lambda>r�cSs|S)Nr)r�rrr	rusz~
        [s]
        str = string
        int = 1
        float = 0.5
        list = a b c d e f g
        bool = yes
        rr�r,rGz0.5z
a b c d e f g�boolrFrg�?ryr{�c�dr�r��gTrrsr�)r*rZrwr��assertIsNotNonerMrOrUrbr+rQrRrSZgetlistrTrZrxrsrvr�r[)rr�rrsZdec0_5rrr	�test_convertersis|
!
z"ConvertersTestCase.test_converters)	rrrrGr/r�r(r*r�rr)r�r	r�^s	r�c@sLeZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�!BlatantOverrideConvertersTestCasez}What if somebody overrode a getboolean()? We want to make sure that in
    this case the automatic converters do not kick in.z�
        [one]
        one = false
        two = false
        three = long story short

        [two]
        one = false
        two = false
        three = four
    cCsMtjddti�}|j|j�|j|�|j|jd�dS)NrwrO)r/r�rOr+rv�	_test_lenr�rw)rr�rrr	�test_converters_at_init�s
z9BlatantOverrideConvertersTestCase.test_converters_at_initcCs/Gdd�dtj�}|�}|j|j�|j|�|j|jd�|j|jdd��|j|jdd��|j	|jdd��|j	|jdd��|j
|jd<|j	|jdd��|j	|jdd��|j	|jdd��|j	|jdd��dS)Nc	s^eZdZdZdddddej�fdd�Zdddddejd	d
�Z�S)zOBlatantOverrideConvertersTestCase.test_inheritance.<locals>.StrangeConfigParserz0a historic borough in south central Pennsylvaniar8FrDNrCc	s5||krdSt�j||d|d|d|�S)NTr8rDrC)r�rT)rr:rsr8rDrC)r�rr	rT�szZBlatantOverrideConvertersTestCase.test_inheritance.<locals>.StrangeConfigParser.getbooleanc
Ss%|j||td|d|d|�S)Nr8rDrC)Z	_get_convrO)rr:rsr8rDrCrrr	�getlen�szVBlatantOverrideConvertersTestCase.test_inheritance.<locals>.StrangeConfigParser.getlen)rrrZ
gettysburgr/r1rTr�rr)r�r	�StrangeConfigParser�s
r�rOr�r�rB)r/r�r+rvr�r�rwr\rTr]�_convert_to_boolean)rr�r�rrr	�test_inheritance�s	
z2BlatantOverrideConvertersTestCase.test_inheritancecCsq|jt|j�d�|jd|j�|jd|j�|jd|j�|j|jd�|j|jd�|j|jd�|j|jdd�d�|j|jdd	�d�|j|jdd
�d�|j|jd	d�d�|j|jd	d	�d�|j|jd	d
�d�|j|jd	dd
d�d�|jtj	��|jd	d�WdQRX|j|djd�d�|j|djd	�d�|j|djd
�d�|j|d	jd�d�|j|d	jd	�d�|j|d	jd
�d�|j|d	jdd�d�|j|d	jd�d�dS)Nr:rBrOZtysburgr?rAr�r�r�r��ZfourrCr)
rMrOrwrZr�r�r�rUr/rW)rr�rrr	r��s0" z+BlatantOverrideConvertersTestCase._test_lencs�tj��dd��_�fdd��_�j|j�|jt�j�d�|j	d�j�|j
d�j�|j�jd�|j�jd�|j�jd�|j�jd	d	��|j�jd
d
��|j�jd	d
��|j�jd
d	���j
�jd<|j�jd	d	��|j�jd
d
��|j�jd	d
��|j�jd
d	��|j�jd	d	�d�|j�jd	d
�d�|j�jd	d�d
�|j�jd
d	�d�|j�jd
d
�d�|j�jd
d�d�|jt��"|j�d	jd	�d�WdQRX|jt��"|j�d
jd	�d�WdQRXdS)NcSsdS)NTr)r:rsrrr	r�szLBlatantOverrideConvertersTestCase.test_instance_assignment.<locals>.<lambda>cst�||�S)N)rO)r:rs)r�rr	rsrrBrOr?rAr�r�r�r�r�r:)r/r�rTr�r+rvrMrOrwrZr�r�r\r�r]rUrZ)rr)r�r	�test_instance_assignment�s:$z:BlatantOverrideConvertersTestCase.test_instance_assignmentN)	rrrrGrvr�r�r�r�rrrr	r��sr��__main__)+�collectionsr/r�r�sysrkZunittestrgr�r�UserDictrrr2ZTestCaser�r�r�r�r�rrrrr"r(r6r7rArHrJrLrMrUrVr_rzr�r�r�r�r�mainrrrr	�<module>sT!���Z$+�-
Sr�$6Ro