B
    u9aÃR ã               @   st  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 G dd„ de j
ƒZG dd„ dƒZG dd„ deƒZG d	d
„ d
eejƒZG dd„ deejƒZG dd„ deejƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deejƒZG dd„ deejƒZG dd„ deƒZG dd„ deejƒZG dd„ deejƒZG dd „ d eƒZG d!d"„ d"eejƒZG d#d$„ d$ejƒZG d%d&„ d&eƒZG d'd(„ d(eejƒZG d)d*„ d*eejƒZG d+d,„ d,ƒZ d-d.„ Z!G d/d0„ d0ejƒZ"G d1d2„ d2ejƒZ#G d3d4„ d4ejƒZ$G d5d6„ d6ejƒZ%G d7d8„ d8ejƒZ&G d9d:„ d:eejƒZ'G d;d<„ d<ejƒZ(G d=d>„ d>ejƒZ)e*d?krpe +¡  dS )@é    N)Úsupportc               @   s@   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZeZ	dS )Ú
SortedDictc             C   s   t | j ¡ ƒS )N)ÚsortedÚdataÚitems)Úself© r   ú'/usr/lib/python3.7/test_configparser.pyr      s    zSortedDict.itemsc             C   s   t | j ¡ ƒS )N)r   r   Úkeys)r   r   r   r	   r
      s    zSortedDict.keysc             C   s   dd„ |   ¡ D ƒS )Nc             S   s   g | ]}|d  ‘qS )é   r   )Ú.0Úir   r   r	   ú
<listcomp>   s    z%SortedDict.values.<locals>.<listcomp>)r   )r   r   r   r	   Úvalues   s    zSortedDict.valuesc             C   s   t |  ¡ ƒS )N)Úiterr   )r   r   r   r	   Ú	iteritems   s    zSortedDict.iteritemsc             C   s   t |  ¡ ƒS )N)r   r
   )r   r   r   r	   Úiterkeys   s    zSortedDict.iterkeysc             C   s   t |  ¡ ƒS )N)r   r   )r   r   r   r	   Ú
itervalues   s    zSortedDict.itervaluesN)
Ú__name__Ú
__module__Ú__qualname__r   r
   r   r   r   r   Ú__iter__r   r   r   r	   r      s   r   c               @   sJ   e Zd ZdZdZdZdZdZej	Z
dZejZejZd
dd„Zddd	„ZdS )ÚCfgParserTestCaseClassF)ú=ú:)ú;ú#TNc             C   s>   t || j| j| j| j| j| j| j| j| j	d
}| j
f |Ž}|S )N)
ÚdefaultsÚallow_no_valueÚ
delimitersÚcomment_prefixesÚinline_comment_prefixesÚempty_lines_in_valuesÚ	dict_typeÚstrictÚdefault_sectionÚinterpolation)Údictr   r   r    r!   r"   r#   r$   r%   r&   Úconfig_class)r   r   Z	argumentsÚinstancer   r   r	   Ú	newconfig/   s    
z CfgParserTestCaseClass.newconfigc             C   s   |   |¡}| |¡ |S )N)r*   Úread_string)r   Ústringr   Úcfr   r   r	   Ú
fromstring?   s    

z!CfgParserTestCaseClass.fromstring)N)N)r   r   r   r   r   r    r!   r"   ÚconfigparserÚ_default_dictr#   r$   ZDEFAULTSECTr%   Ú_UNSETr&   r*   r.   r   r   r   r	   r   $   s   
r   c               @   s¼   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-S ).ÚBasicTestCasec       	   	   C   sŠ  ddddddddd	g	}| j r&| d
¡ | ¡  ddg}| ¡ }| ¡  | j}|||ƒ | d¡}| ¡  |||ƒ dd„ |D ƒ}| ¡  | | j¡ | ¡  |||ƒ |d  ¡ }tt|ƒƒ}|||ƒ | ¡ }tt|ƒƒ}|  t	|ƒt	|ƒ¡ x|D ]\}}|||j
ƒ qöW || ¡ || j ƒ || dd¡dƒ || dd¡dƒ || dd¡dƒ || dd¡dƒ || dd¡dƒ || dd¡dƒ || dd¡dƒ || dd¡dƒ || d	d¡dƒ || d	d¡dƒ |  | d	d¡d¡ || d	d¡dƒ || d	d ¡d!ƒ || d	d"¡d#ƒ | j r:|| d
d$¡d ƒ ||jdddd%dƒ ||jddddid&dƒ |  tj¡ | d'd¡ W d Q R X |  tj¡ | dd(¡ W d Q R X ||jd'ddd%dƒ ||jdd(dd%dƒ ||jddd d%dƒ ||jd)dd d%d ƒ ||jd	dd*d%dƒ ||jd	d+d*d%d*ƒ ||jd	d+d,d%d,ƒ |  tj¡ | d	d+¡ W d Q R X |  |jd	dd-d%d¡ |  |jd	d.d-d%d-¡ ||jd	d.d/d%d/ƒ |  tj¡ | d	d.¡ W d Q R X ||jd	d d0d%d!ƒ ||jd	d1d2d%d2ƒ ||jd	d1d0d%d0ƒ |  tj¡ | d	d1¡ W d Q R X ||jd3d d0d%d0ƒ | j rŠ||jd
d$d!d%d ƒ ||jd
d4d!d%d!ƒ ||d d dƒ ||d d dƒ |d }||j
dƒ |  |j|¡ |  t¡ d5|_
W d Q R X |  t¡ d6|_W d Q R X ||d dƒ ||d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d d7ƒ | j r˜||d
 d$ d ƒ ||d  dd¡dƒ ||d jddd%dƒ ||d jdddid&dƒ |  t¡ |d' d  W d Q R X |  t¡ |d d(  W d Q R X |  t¡ |d' jddd% W d Q R X ||d  d(d¡dƒ ||d jd(dd%dƒ ||d  d(¡d ƒ ||d  dd ¡dƒ ||d jdd d%dƒ |  t¡ |d)  dd ¡ W d Q R X ||d	  dd*¡dƒ ||d	 jdd*d%dƒ ||d	  d+d*¡d*ƒ ||d	 jd+d*d%d*ƒ ||d	  d+d,¡d,ƒ ||d	 jd+d,d%d,ƒ ||d	  d+¡d ƒ |  |d	  dd-¡d¡ |  |d	 jdd-d%d¡ |  |d	  d.d-¡d-¡ |  |d	 jd.d-d%d-¡ ||d	  d.d/¡d/ƒ ||d	 jd.d/d%d/ƒ ||d	  d.¡d ƒ ||d	  d d0¡d!ƒ ||d	 jd d0d%d!ƒ ||d	  d1d2¡d2ƒ ||d	 jd1d2d%d2ƒ ||d	  d1d0¡d0ƒ ||d	 jd1d0d%d0ƒ ||d	  d1¡d ƒ | j 	r*||d
  d$d!¡d ƒ ||d
 jd$d!d%d ƒ ||d
  d4d!¡d!ƒ ||d
 jd4d!d%d!ƒ d8|| j d9< d:|| j d;< |  | d¡¡ |  | dd¡¡ |  | d¡¡ |  | | j¡¡ |  | dd¡d<¡ |  | dd¡d=¡ |  | dd¡d>¡ |  | dd9¡¡ |  | dd9¡¡ |  | | jd9¡¡ |  | dd9¡¡ |  | | jd9¡¡ |  tj¡}| d?d¡ W d Q R X |  |jjd@¡ || dd¡d7ƒ |d	= |  d	|k¡ |  t¡ |d	= W d Q R X |  t ¡ || j= W d Q R X |d d= |  d|d k¡ |  t¡ |d d= W d Q R X |  d;|d k¡ |  t¡ |d d;= W d Q R X || j d;= |  d;|d k¡ |  t¡ || j d;= W d Q R X |  t¡ |d? d= W d Q R X d S )ANzCommented BarzFoo BarzInternationalized Stuffz	Long LinezSection\with$weird%characters[	ÚSpacesz
Spacey BarzSpacey Bar From The BeginningÚTypesÚNoValue)ÚbazÚqwe)ÚfooÚbar3c             S   s   g | ]}|‘qS r   r   )r   Úsectionr   r   r	   r   b   s    z,BasicTestCase.basic_test.<locals>.<listcomp>r8   Úbar1Úbar2r9   r6   r7   Úbar4zkey with spacesÚvaluezanother with spaceszsplat!Úinté*   Z42Úfloatg)\Âõ(Ü?z0.44ÚbooleanFZ123zstrange but acceptablezoption-without-value)Úfallback)ÚvarszNo Such Foo Barzno-such-foozNo Such Spacey Baré   zno-such-intZ18g        zno-such-floatz0.0Tzno-such-booleanÚyeszNo Such Typeszno-such-option-without-valuezName is read-onlyzParser 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 removedzNo Such Section)zNo Such Section)!r   ÚappendÚsortÚsectionsÚassertEqualr   r%   r   ÚlistÚlenÚnamer   ÚgetÚgetintÚassertAlmostEqualÚgetfloatÚ
getbooleanÚassertRaisesr/   ÚNoSectionErrorÚNoOptionErrorÚassertIsÚparserÚAttributeErrorÚKeyErrorÚ
assertTrueZremove_sectionÚassertFalseÚ
has_optionÚremove_optionÚ	exceptionÚargsÚ
ValueError)	r   r-   ÚEÚFÚLÚeqrO   r:   Úcmr   r   r	   Ú
basic_testG   sz   







zBasicTestCase.basic_testc          	   C   sÎ   d  | j| j¡}| jr|d7 }|  |¡}|  |¡ | jrš|  tj	¡ | 
t d  | j¡¡¡ W d Q R X |  tj¡ | 
t d  | j¡¡¡ W d Q R X n0| 
t d  | j¡¡¡ | 
t d  | j¡¡¡ d S )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
            )Úformatr   r    r   r.   rh   r$   rU   r/   ÚDuplicateOptionErrorr+   ÚtextwrapÚdedentÚDuplicateSectionError)r   Úconfig_stringr-   r   r   r	   Ú
test_basic%  s"    

zBasicTestCase.test_basicc             C   s  ddiddidddœdddœddii d	d
dddœdddœdddddœdœ	}| j rb| ddd ii¡ |  ¡ }| |¡ |  |¡ | jrâ|  tj¡ | ddiddidœ¡ W d Q R X |  tj	¡ | dddd œi¡ W d Q R X n,| ddiddid!œ¡ | dddd œi¡ d S )"Nr8   r;   r<   r9   r7   )r8   r6   r=   z7this line is much, much longer than my editor
likes it.Z	BulgarianZDefaultZEnglishZDeutsch)zfoo[bg]r8   zfoo[en]zfoo[de]r>   zsplat!)zkey with spaceszanother with spacesr@   g)\Âõ(Ü?Fzstrange but acceptable)r?   rA   rB   é{   )	zFoo Barz
Spacey BarzSpacey Bar From The BeginningzCommented Barz	Long LinezSection\with$weird%characters[	zInternationalized Stuffr3   r4   r5   zoption-without-valueÚkeyZkey2Úvalue2)rG   r   zDuplicate Options Herezwith a valuezwith another value)ÚoptionZOPTION)r:   ZSECTION)
r   Úupdater*   Ú	read_dictrh   r$   rU   r/   rm   rj   )r   Úconfigr-   r   r   r	   Útest_basic_from_dictf  sT    

z"BasicTestCase.test_basic_from_dictc          	   C   s¨  |   ¡ }| d¡ | d¡ | d¡ | ¡ }| ¡  | j}||dddgƒ | ddd¡ || d¡dgƒ || dd¡ddƒ |  t	j
¡ | ddd¡ W d Q R X |  | dd¡¡ |  | dd¡¡ | ddd¡ x d	D ]}|  | d|¡d
¡ qÞW || d¡dgƒ || d¡dgƒ | dd¡ || d¡g ƒ |  d | jd ¡¡}|| d¡dgƒ || dd¡dƒ | jd | jd ¡ddid}|  | dd¡¡ d S )NÚAÚaÚBr>   Úbz@could not locate option, expecting case-insensitive option nameszA-Bz	A-B value)za-bzA-bza-BzA-Bz9has_option() returned false for option which should existza-bz3[MySection]
Option{} first line   
	second line   
r   Ú	MySectionrs   ÚOptionzfirst line
second linez[section]
nekey{}nevalue
rq   )r   r:   ÚKey)r*   Úadd_sectionrK   rJ   rL   ÚsetÚoptionsrP   rU   r/   rV   r\   r^   r]   r_   r.   ri   r   )r   r-   re   rf   Úoptr   r   r	   Útest_case_sensitivity¯  sD    






z#BasicTestCase.test_case_sensitivityc          	   C   sœ  |   ¡ }i |d< ddi|d< i |d< dd„ |D ƒ}| ¡  | j}| j}||tdd| jdgƒƒ ||d  ¡ dhƒ ||d d ddƒ |  t¡ d|d d< W d Q R X |  	d|d k¡ d	|d d
< x dD ]}|  	||d kd¡ qÌW ||d  ¡ dhƒ ||d  ¡ dhƒ |d d= ||d  ¡ i ƒ |  
d | jd ¡¡}||d  ¡ dhƒ ||d d dƒ | j
d | jd ¡ddid}|  	d|d k¡ d S )Nrx   rz   r>   ry   c             S   s   g | ]}|‘qS r   r   )r   r:   r   r   r	   r   Þ  s    zFBasicTestCase.test_case_sensitivity_mapping_access.<locals>.<listcomp>r{   z@could not locate option, expecting case-insensitive option namesz	A-B valuezA-B)za-bzA-bza-BzA-Bz9has_option() returned false for option which should existza-bz3[MySection]
Option{} first line   
	second line   
r   r|   rs   r}   zfirst line
second linez[section]
nekey{}nevalue
rq   )r   r~   r:   )r*   rJ   rL   ZassertCountEqualr   r%   r
   rU   r[   r\   r.   ri   r   )r   r-   re   rf   Zelem_eqr‚   r   r   r	   Ú$test_case_sensitivity_mapping_accessÙ  sB    




z2BasicTestCase.test_case_sensitivity_mapping_accessc             C   sP   |   ddi¡}|  | | jd¡dd¡ |   ddi¡}|  | | jd¡dd¡ d S )Nr8   ÚBarÚFooz@could not locate option, expecting case-insensitive option namesz<could not locate option, expecting case-insensitive defaults)r*   rL   rP   r%   )r   r-   r   r   r	   Útest_default_case_sensitivity  s    z+BasicTestCase.test_default_case_sensitivityc          	   C   sð   |   ¡ }|  |tjd | jd ¡¡ |  |tjd | jd ¡¡ |  |tjd¡}|  |jd¡ | j	sì|  |tjd¡}|  |jd¡ t
 d¡}| jd d	kr¨tj}|f}ntj}|dd
f}t|dd}|  |||¡}W d Q R X |  |j|¡ d S )Nz[Foo]
{}val-without-opt-name
r   r   zNo Section!
)z<???>r   zNo Section!
z[Foo]
  wrong-indent
)z<???>zcfgparser.3r   z.  # INI with as many tricky parts as possible
zutf-8)Úencoding)r*   Úparse_errorr/   ÚParsingErrorri   r   ÚMissingSectionHeaderErrorrL   ra   r   r   ÚfindfileÚopen)r   r-   ÚeÚtrickyÚerrorÚexpectedÚfr   r   r	   Útest_parse_errors  s0    




zBasicTestCase.test_parse_errorsc          	   C   s@   t |dƒr|}n
t |¡}|  |¡}| |¡ W d Q R X |jS )NÚreadline)ÚhasattrÚioÚStringIOrU   Ú	read_filer`   )r   r-   ÚexcÚsrcÚsiorg   r   r   r	   r‰   '  s    

zBasicTestCase.parse_errorc          	   C   sÂ   |   ¡ }|  | ¡ g d¡ |  | d¡d¡ |  tj¡ | d¡ W d Q R X |  tj¡ | 	ddd¡ W d Q R X |  
|tjdd¡}|  |jd¡ | d¡ |  
|tjdd¡}|  |jd¡ d S )	Nz0new ConfigParser should have no defined sectionsr†   z5new ConfigParser should have no acknowledged sectionsr8   Úbarr>   )r8   )rœ   r8   )r*   rL   rK   r]   Zhas_sectionrU   r/   rV   r   r€   Ú	get_errorra   r   rW   )r   r-   rŽ   r   r   r	   Útest_query_errors0  s    
zBasicTestCase.test_query_errorsc          
   C   sN   y|  ||¡ W n" |k
r2 } z|S d }~X Y nX |  d|j|jf ¡ d S )Nzexpected exception type %s.%s)rP   Zfailr   r   )r   r-   r™   r:   rs   rŽ   r   r   r	   r   A  s    zBasicTestCase.get_errorc             C   sr   |   dj| jd d¡}xTtddƒD ]F}|  | dd| ¡¡ |  | dd| ¡¡ |  t|jdd	| ¡ q$W d S )
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 MOREr   )Úequalsr   é   ZBOOLTESTzt%dzf%dze%d)	r.   ri   r   Úranger\   rT   r]   rU   rb   )r   r-   Úxr   r   r	   Útest_booleanJ  s    zBasicTestCase.test_booleanc          	   C   s  |   ¡ }| d¡ |  tj¡}| d¡ W d Q R X |j}|  t|ƒd¡ |  |jd¡ | j	r|  tj¡(}|j
t dj| jd d¡dd W d Q R X |j}|  t|ƒd	¡ |  |jd
¡ |  tj¡}| ddddœi¡ W d Q R X |j}|  t|ƒd¡ |  |jd¡ d S )Nr†   zSection 'Foo' already exists)r†   NNzì                    [Foo]
                    will this be added{equals}True
                    [Bar]
                    what about this{equals}True
                    [Foo]
                    oops{equals}this won't
                r   )rŸ   z	<foo-bar>)ÚsourcezFWhile reading from '<foo-bar>' [line  5]: section 'Foo' already exists)r†   z	<foo-bar>r    r…   Úvalzis really `opt`)r‚   ZOPTzIWhile reading from '<dict>': option 'opt' in section 'Bar' already exists)r…   r‚   z<dict>N)r*   r   rU   r/   rm   r`   rL   Ústrra   r$   r+   rk   rl   ri   r   rj   ru   )r   r-   rg   rŽ   r   r   r	   Útest_weird_errorsc  s&    
$zBasicTestCase.test_weird_errorsc             C   s    dj | j| jd | jd}| jr(|d7 }|  |¡}xhdD ]`}t ¡ }|j||d | jd }|rjd  |¡}dj || jd	}| jrˆ|d
7 }|  	| 
¡ |¡ q8W d S )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
r   )Úcommentr%   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Ÿ   r%   z"[Valueless]
option-without-value

)ri   r   r    r%   r   r.   r–   r—   ÚwriterL   Úgetvalue)r   rn   r-   r©   ÚoutputZ	delimiterZexpect_stringr   r   r	   Ú
test_write‚  s(    





zBasicTestCase.test_writec             C   sˆ   |   dj| jd d¡}G dd„ dtƒ}| ddd¡ | dd|dƒ¡ | dd	d¡ | dd	|dƒ¡ | ddd¡ | dd	d¡ d S )
Nz[sect]
option1{eq}foo
r   )rf   c               @   s   e Zd ZdS )z2BasicTestCase.test_set_string_types.<locals>.mystrN)r   r   r   r   r   r   r	   Úmystr½  s   r®   ÚsectÚoption1ZsplatÚoption2)r.   ri   r   r¦   r€   )r   r-   r®   r   r   r	   Útest_set_string_types¸  s    z#BasicTestCase.test_set_string_typesc             C   sJ  | j d dkr|  d¡ t d¡}|  ¡ }| |dg¡}|  ||g¡ |  | dd¡d¡ |  ¡ }| |¡}|  ||g¡ |  | dd¡d¡ |  ¡ }| t 	|¡¡}|  ||g¡ |  | dd¡d¡ |  ¡ }| t 	|¡|g¡}|  |||g¡ |  | dd¡d¡ |  ¡ }| dg¡}|  |g ¡ |  ¡ }| g ¡}|  |g ¡ d S )	Nr   r   zincompatible formatzcfgparser.1znonexistent-filezFoo Barr8   Únewbar)
r   ÚskipTestr   rŒ   r*   ÚreadrL   rP   ÚpathlibZPath)r   Zfile1r-   Úparsed_filesr   r   r	   Útest_read_returns_file_listÆ  s2    



z)BasicTestCase.test_read_returns_file_listc             C   sŒ   | j d dkr|  d¡ t d¡ ¡ }|  ¡ }| |¡}|  ||g¡ |  ¡ }| d¡}|  |g ¡ |  ¡ }| |dg¡}|  ||g¡ d S )Nr   r   zincompatible formatzcfgparser.1s   nonexistent-file)r   r´   r   rŒ   Úencoder*   rµ   rL   )r   Zfile1_bytestringr-   r·   r   r   r	   Ú0test_read_returns_file_list_with_bytestring_pathç  s    


z>BasicTestCase.test_read_returns_file_list_with_bytestring_pathc             C   s   |   dj| jd d¡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.   ri   r   )r   r   r   r	   Úget_interpolation_configù  s    z&BasicTestCase.get_interpolation_configc          	   C   sj   | j d | j¡ddid}t|jdddidƒ}| ¡  |  ||¡ |  tj	¡ | d¡ W d Q R X d S )	Nz
            [section]
            name {0[0]} %(value)s
            key{0[1]} |%(name)s|
            getdefault{0[1]} |%(default)s|
        Údefaultz	<default>)r   r:   r>   )rD   zno such section)
r.   ri   r   rM   r   rJ   rL   rU   r/   rV   )r   r‘   r-   re   r   r   r	   Úcheck_items_config  s    z BasicTestCase.check_items_configc          	   C   sx   | j d | j¡ddid}|  | ¡ d d¡ |  | ¡ d d¡ |  | ¡ d d¡ |  t¡ | ¡  W d Q R X d S )	Nz®
            [section1]
            name1 {0[0]} value1
            [section2]
            name2 {0[0]} value2
            [section3]
            name3 {0[0]} value3
        r¼   z	<default>)r   r   Úsection1Úsection2Úsection3)r.   ri   r   rL   ÚpopitemrU   r[   )r   r-   r   r   r	   Útest_popitem!  s    zBasicTestCase.test_popitemc             C   s¢   |   ddi¡}|  | | jd¡dd¡ dddœ|d< |  | ¡ dg¡ |  t|d  ¡ ƒd	d
dh¡ | ¡  |  t| ¡ ƒtƒ ¡ |  t|| j  ¡ ƒdh¡ d S )Nr8   r…   r†   z@could not locate option, expecting case-insensitive option namesÚvalue1rr   )r°   r±   Zzingr°   r±   )r*   rL   rP   r%   rK   r€   r
   Úclear)r   r-   r   r   r	   Ú
test_clear0  s    zBasicTestCase.test_clearc             C   sø  | j d | j¡ddid}|  t|d  ¡ ƒddh¡ |  t|d  ¡ ƒd	dh¡ |  t|d
  ¡ ƒddh¡ |  |d d d¡ |  |d d	 d¡ |  |d
 d d¡ |  | ¡ ddd
g¡ ddi|d< |  t|d  ¡ ƒddh¡ |  |d d d¡ |  d	|d ¡ |  | ¡ ddd
g¡ i |d
< |  t|d
  ¡ ƒdh¡ |  d|d
 ¡ |  | ¡ ddd
g¡ i || j< |  t|| j  ¡ ƒtƒ ¡ |  t|d  ¡ ƒdh¡ |  t|d  ¡ ƒdh¡ |  t|d
  ¡ ƒtƒ ¡ |  | ¡ ddd
g¡ d S )Nz®
            [section1]
            name1 {0[0]} value1
            [section2]
            name2 {0[0]} value2
            [section3]
            name3 {0[0]} value3
        ZnameDZvalueD)r   r¾   Zname1Znamedr¿   Zname2rÀ   Zname3rÃ   rr   Zvalue3Zname22Zvalue22)	r.   ri   r   rL   r€   r
   rK   ÚassertNotInr%   )r   r-   r   r   r	   Útest_setitem<  s0    
zBasicTestCase.test_setitemc          	   C   s|   | j r|  d¡ t d | jd ¡¡}|  ¡ }|  tj	¡ | 
|¡ W d Q R X |  | dd¡d¡ |  |d d d¡ d S )Nz2if no_value is allowed, ParsingError is not raisedzC            [DEFAULT]
            test {0} test
            invalidr   ZDEFAULTÚtest)r   r´   rk   rl   ri   r   r*   rU   r/   rŠ   r+   rL   rP   )r   Zinvalidr-   r   r   r	   Útest_invalid_multiline_value\  s    
z*BasicTestCase.test_invalid_multiline_valueN)r   r   r   rh   ro   rw   rƒ   r„   r‡   r“   r‰   rž   r   r£   r§   r­   r²   r¸   rº   r»   r½   rÂ   rÅ   rÇ   rÉ   r   r   r   r	   r2   E   s.    _AI*(
		6! r2   c               @   s   e Zd ZejZdZdS )ÚStrictTestCaseTN)r   r   r   r/   ÚRawConfigParserr(   r$   r   r   r   r	   rÊ   l  s   rÊ   c               @   sR   e Zd ZejZdd„ Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ ZdS )ÚConfigParserTestCasec             C   s’   |   ¡ }| j}|| dd¡dƒ || dd¡dƒ || dd¡dƒ |  |tjdd¡}| jtjkrr|  |jd	¡ nt	| jtj
ƒrŽ|  |jd	¡ d S )
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)rÏ   r†   z5something %(with11)s lots of interpolation (11 steps))r»   rL   rP   r   r/   ÚInterpolationDepthErrorr&   r1   ra   Ú
isinstanceÚLegacyInterpolation)r   r-   rf   rŽ   r   r   r	   Útest_interpolationt  s    z'ConfigParserTestCase.test_interpolationc             C   s€   |   ¡ }|  |tjdd¡}|  |jd¡ |  |jd¡ |  |jd¡ | jtj	kr`|  |j
d¡ nt| jtjƒr||  |j
d¡ d S )NzInterpolation ErrorrO   Ú	reference)rO   zInterpolation Errorz%(reference)srÔ   )r»   r   r/   ÚInterpolationMissingOptionErrorrL   rÔ   r:   rs   r&   r1   ra   rÑ   rÒ   )r   r-   rŽ   r   r   r	   Ú test_interpolation_missing_value„  s    
z5ConfigParserTestCase.test_interpolation_missing_valuec             C   s   |   dddddg¡ d S )N)r¼   z	<default>)Ú
getdefaultz|<default>|)rq   z|value|)rO   r>   )r>   r>   )r½   )r   r   r   r	   Ú
test_items’  s
    zConfigParserTestCase.test_itemsc          	   C   s‚   |   dj| jd d¡}|  | dd¡d¡ | jtjkrN|  | dd¡d¡ n0t| jtj	ƒr~|  
t¡ | dd¡ W d Q R X d S )	Nzc[section]
option1{eq}xxx
option2{eq}%(option1)s/xxx
ok{eq}%(option1)s/%%s
not_ok{eq}%(option2)s/%%sr   )rf   r:   Úokzxxx/%sZnot_okz
xxx/xxx/%s)r.   ri   r   rL   rP   r&   r/   r1   rÑ   rÒ   rU   Ú	TypeError)r   r-   r   r   r	   Útest_safe_interpolation™  s    z,ConfigParserTestCase.test_safe_interpolationc             C   s¢   |   dj| jd d¡}|  | dd¡d¡ |  t|jddd¡ |  t|jddd¡ |  t|jddd	¡ |  | dd¡d¡ | dd
d¡ |  | dd
¡d¡ d S )Nz[sect]
option1{eq}foo
r   )rf   r¯   r°   r8   z%foozfoo%zf%oor±   zfoo%%barzfoo%bar)r.   ri   r   rL   rP   rU   rb   r€   )r   r-   r   r   r	   Ú#test_set_malformatted_interpolation¨  s    z8ConfigParserTestCase.test_set_malformatted_interpolationc             C   s¼   |   dj| jd d¡}|  t|jddd¡ |  t|jddd¡ |  t|jddtƒ ¡ |  t|jddd¡ |  t|jddd¡ |  t|jddtƒ ¡ |  t|jdd	d
¡ |  t|jd	¡ d S )Nz[sect]
option1{eq}foo
r   )rf   r¯   r°   r   g      ð?r±   rp   zinvalid opt name!)r.   ri   r   rU   rÚ   r€   Úobjectr   )r   r-   r   r   r	   Útest_set_nonstring_types¸  s    z-ConfigParserTestCase.test_set_nonstring_typesc             C   s   |   ¡ }|  t|j| j¡ d S )N)r*   rU   rb   r   r%   )r   r-   r   r   r	   Útest_add_section_defaultÆ  s    z-ConfigParserTestCase.test_add_section_defaultc             C   s€   | j ddid}|  || j d d¡ |  || j  d¡d¡ | j ddid}|  || j d d	¡ |  || j  d¡d¡ d
S )zbpo-23835 fix for ConfigParserr   g333333@)r   rG   z2.4rx   gÍÌÌÌÌÌ@ry   z5.2N)r*   rL   r%   rR   rS   )r   r-   r   r   r	   Útest_defaults_keywordÊ  s    z*ConfigParserTestCase.test_defaults_keywordN)r   r   r   r/   ÚConfigParserr(   rÓ   rÖ   rØ   rÛ   rÜ   rÞ   rß   rà   r   r   r   r	   rÌ   q  s   rÌ   c               @   sD   e Zd ZejZdZe d¡ 	¡ Z
dd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú#ConfigParserTestCaseNoInterpolationNz™
        [numbers]
        one = 1
        two = %(one)s * 2
        three = ${common:one} * 3

        [hexen]
        sixteen = ${numbers:two} * 8
    c             C   sT   |   |d d d¡ |   |d d d¡ |   |d d d¡ |   |d d	 d
¡ d S )NZnumbersÚonerG   Útwoz%(one)s * 2Úthreez${common:one} * 3ZhexenZsixteenz${numbers:two} * 8)rL   )r   r-   r   r   r	   ÚassertMatchesIniá  s    z4ConfigParserTestCaseNoInterpolation.assertMatchesInic             C   s   |   | j¡}|  |¡ d S )N)r.   Úiniræ   )r   r-   r   r   r	   Útest_no_interpolationç  s    z9ConfigParserTestCaseNoInterpolation.test_no_interpolationc             C   s   |   ¡ }|  | d¡¡ d S )NÚ )r*   ÚassertIsNoner+   )r   r-   r   r   r	   Útest_empty_caseë  s    z3ConfigParserTestCaseNoInterpolation.test_empty_casec             C   s2   G dd„ dt jƒ}|ƒ }| | j¡ |  |¡ d S )Nc               @   s   e Zd ZdZdS )zbConfigParserTestCaseNoInterpolation.test_none_as_default_interpolation.<locals>.CustomConfigParserN)r   r   r   Z_DEFAULT_INTERPOLATIONr   r   r   r	   ÚCustomConfigParserð  s   rì   )r/   rá   r+   rç   ræ   )r   rì   r-   r   r   r	   Ú"test_none_as_default_interpolationï  s    zFConfigParserTestCaseNoInterpolation.test_none_as_default_interpolation)r   r   r   r/   rá   r(   r&   rk   rl   Ústriprç   ræ   rè   rë   rí   r   r   r   r	   râ   Ô  s   
râ   c               @   s"   e Zd ZejZe ¡ Zdd„ ZdS )Ú'ConfigParserTestCaseLegacyInterpolationc             C   s¸   |   dj| jd d¡}|  | dd¡d¡ | ddd¡ |  | dd¡d¡ | ddd¡ |  | dd¡d¡ | ddd	¡ |  | dd¡d	¡ | dd
d¡ |  | dd
¡d¡ d S )Nz[sect]
option1{eq}foo
r   )rf   r¯   r°   r8   z%foozfoo%zf%oor±   zfoo%%bar)r.   ri   r   rL   rP   r€   )r   r-   r   r   r	   rÜ   ü  s    zKConfigParserTestCaseLegacyInterpolation.test_set_malformatted_interpolationN)	r   r   r   r/   rá   r(   rÒ   r&   rÜ   r   r   r   r	   rï   ø  s   rï   c               @   s   e Zd ZdZdZdZdS )Ú)ConfigParserTestCaseNonStandardDelimiters)z:=ú$)z//ú"N)r   r   r   r   r    r!   r   r   r   r	   rð     s   rð   c               @   s   e Zd ZdZdS )Ú-ConfigParserTestCaseNonStandardDefaultSectionZgeneralN)r   r   r   r%   r   r   r   r	   ró     s   ró   c               @   s6   e Zd ZejZd dd¡Zdd„ Zdd„ Z	dd	„ Z
d
S )ÚMultilineValuesTestCasezSI'm having spam spam spam spam spam spam spam beaked beans spam spam spam and spam!ú z	
c          	   C   s|   |   ¡ }xLtdƒD ]@}d |¡}| |¡ x&tdƒD ]}| |d |¡| j¡ q4W qW ttjdƒ}| 	|¡ W d Q R X d S )Néd   z	section{}é
   zlovely_spam{}Úw)
r*   r¡   ri   r   r€   Úwonderful_spamr   r   ÚTESTFNrª   )r   r-   r   ÚsÚjr’   r   r   r	   ÚsetUp  s    

zMultilineValuesTestCase.setUpc             C   s   t  tj¡ d S )N)ÚosÚunlinkr   rú   )r   r   r   r	   ÚtearDown(  s    z MultilineValuesTestCase.tearDownc          	   C   sJ   |   ¡ }ttjƒ}| |¡ W d Q R X |  | dd¡| j dd¡¡ d S )NZsection8Zlovely_spam4z	
Ú
)	r*   r   r   rú   r˜   rL   rP   rù   Úreplace)r   Zcf_from_filer’   r   r   r	   Ú test_dominating_multiline_values+  s
    z8MultilineValuesTestCase.test_dominating_multiline_valuesN)r   r   r   r/   rá   r(   r  rù   rý   r   r  r   r   r   r	   rô     s   
rô   c               @   s2   e Zd ZejZdd„ Zdd„ Zdd„ Zdd„ Z	d	S )
ÚRawConfigParserTestCasec             C   sZ   |   ¡ }| j}|| dd¡dƒ || dd¡dƒ || dd¡dƒ || dd¡d	ƒ d S )
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»   rL   rP   )r   r-   rf   r   r   r	   rÓ   8  s    z*RawConfigParserTestCase.test_interpolationc             C   s   |   dddddg¡ d S )N)r¼   z	<default>)r×   z|%(default)s|)rq   z
|%(name)s|)rO   z	%(value)s)r>   r>   )r½   )r   r   r   r	   rØ   D  s
    z"RawConfigParserTestCase.test_itemsc             C   s
  |   ¡ }| d¡ | ddd¡ | ddddddddd	d
g¡ | ddddi¡ |  | dd¡d¡ |  | dd¡ddddddd	d
g¡ |  | dd¡ddi¡ | d¡ | ddd¡ |  | dd¡d¡ |jtjkrdd„ |_| ddd¡ |  | dd¡d¡ d S )Nz
non-stringr?   r   rM   r   é   é   r    é   é   r'   Zpign†ðù!	@rp   zthis is sickTc             S   s   | S )Nr   )r¢   r   r   r	   Ú<lambda>[  ó    zBRawConfigParserTestCase.test_set_nonstring_types.<locals>.<lambda>)	r*   r   r€   rL   rP   Z_dictr/   r0   Úoptionxform)r   r-   r   r   r	   rÞ   K  s     


z0RawConfigParserTestCase.test_set_nonstring_typesc          	   C   sf   |   t¡}| jddid W dQ R X |j}|  t|ƒd¡ | jddid}|  || j d d¡ dS )	z-bpo-23835 legacy behavior for RawConfigParserr   g333333@)r   Nz%'int' object has no attribute 'lower'rx   gÍÌÌÌÌÌ@ry   )rU   rZ   r*   r`   rL   r¦   rR   r%   )r   ZctxÚerrr-   r   r   r	   rà   _  s    z-RawConfigParserTestCase.test_defaults_keywordN)
r   r   r   r/   rË   r(   rÓ   rØ   rÞ   rà   r   r   r   r	   r  5  s
   r  c               @   s   e Zd ZdZdZdZdS )Ú,RawConfigParserTestCaseNonStandardDelimiters)z:=rñ   )z//rò   N)r   r   r   r   r    r!   r   r   r   r	   r  i  s   r  c               @   s&   e Zd ZejZdZdZdZdd„ Z	dS )ÚRawConfigParserTestSambaConf)r   r   z----)z//Fc             C   s¨   t  d¡}|  ¡ }|j|dgdd}|  ||g¡ ddddd	d
dg}|  | ¡ |¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | d
d¡d¡ d S )Nzcfgparser.2znonexistent-filezutf-8)rˆ   ÚglobalZhomesZprinterszprint$zpdf-generatorZtmpZAgustinZ	workgroupZMDKGROUPzmax log sizeé2   zhosts allowz127.zecho commandzcat %s; rm %s)r   rŒ   r*   rµ   rL   rK   rP   rQ   )r   Zsmbconfr-   r·   rK   r   r   r	   Útest_readingu  s    
z)RawConfigParserTestSambaConf.test_readingN)
r   r   r   r/   rË   r(   r    r!   r"   r  r   r   r   r	   r  o  s
   r  c               @   s\   e Zd ZejZe ¡ ZdZdZ	ddd„Z
dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ ZdS )Ú)ConfigParserTestCaseExtendedInterpolationÚcommonTNc             C   s"   |   |¡}|r||_| |¡ |S )N)r*   r  r+   )r   r,   r   r  r-   r   r   r	   r.   ‰  s
    

z4ConfigParserTestCaseExtendedInterpolation.fromstringc             C   sP  |   t d¡ ¡ ¡}| j}||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d d	ƒ ||d d
 dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d dƒ ||d d
 dƒ ||d d dƒ d S )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  zfavourite BeatleZPaulzfavourite colorZgreenZtomzfavourite bandz	green dayzfavourite popezJohn Paul IIZsequelzJohn Paul IIIZambvZGeorgezson of Edward VIIzGeorge Vzson of George Vz	George VIZstanleyZblackzfavourite state of mindZparanoidzfavourite moviezsoylent greenzfavourite songzblack sabbath - paranoid)r.   rk   rl   rî   rL   )r   r-   rf   r   r   r	   Útest_extended_interpolation  s*    zEConfigParserTestCaseExtendedInterpolation.test_extended_interpolationc          	   C   s`   |   t d¡ ¡ ¡}|  tj¡ |d d  W d Q R X |  tj¡ |d d  W d Q R X d S )Nz¸
            [one for you]
            ping = ${one for me:pong}

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

            [selfish]
            me = ${me}
        zone for youZpingZselfishÚme)r.   rk   rl   rî   rU   r/   rÐ   )r   r-   r   r   r	   Útest_endless_loop½  s    	z;ConfigParserTestCaseExtendedInterpolation.test_endless_loopc          	   C   s–   |   d¡}|  |d d d¡ |  |d d d¡ |  |d d d¡ tj}|  |¡}|d d	  W d Q R X |  |jjd
¡ |  |jjd d¡ d S )Nzì
            [dollars]
            $var = $$value
            $var2 = ${$var}
            ${sick} = cannot interpolate me

            [interpolated]
            $other = ${dollars:$var}
            $trying = ${dollars:${sick}}
        Zdollarsz$varz$valueZinterpolatedz$otherz${sick}zcannot interpolate mez$tryingzdollars:${sickr  z${dollars:${sick}})r.   rL   r/   rÕ   rU   r`   rÔ   ra   )r   r-   Zexception_classrg   r   r   r	   Útest_strange_optionsÎ  s    	z>ConfigParserTestCaseExtendedInterpolation.test_strange_optionsc             C   sŽ   t  d¡ ¡ }|  |¡}| j}||d d dƒ ||d d dƒ ||d d dƒ ||d d d	ƒ ||d
 d dƒ ||d
 d dƒ d S )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  Zoptionlowerr>   ZOptionUpperÚValueÚCommonza better valuezA Better ValueÚrandomZfoolowerzvalue redefinedZFooUpperzA Better Value Redefined)rk   rl   rî   r.   rL   )r   rç   r-   rf   r   r   r	   Útest_case_sensitivity_basicã  s    

zEConfigParserTestCaseExtendedInterpolation.test_case_sensitivity_basicc          	   C   s¸   t  d¡ ¡ }|  tj¡ |  |¡}W d Q R X | j|dd„ d}| j}||d d dƒ ||d d d	ƒ ||d
 d dƒ ||d
 d dƒ ||d d dƒ ||d d dƒ d S )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
        c             S   s   | S )Nr   )r‚   r   r   r	   r	    r
  z[ConfigParserTestCaseExtendedInterpolation.test_case_sensitivity_conflicts.<locals>.<lambda>)r  r  rs   r>   r}   r  r  za better valuezA Better Valuer  r8   zvalue redefinedr†   zA Better Value Redefined)rk   rl   rî   rU   r/   rj   r.   rL   )r   rç   r-   rf   r   r   r	   Útest_case_sensitivity_conflictsû  s    
zIConfigParserTestCaseExtendedInterpolation.test_case_sensitivity_conflictsc          	   C   sä   |   d¡}|  tj¡ |d d  W d Q R X |  tj¡ |d d  W d Q R X |  tj¡ |d d  W d Q R X |  tj¡ |d d  W d Q R X |  tj¡ |d d  W d Q R X |  t¡ d|d d	< W d Q R X d S )
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!
        zinterpolation failZcase1Zcase2Zcase3Zcase4Zcase5zBLACK $ABBATHZcase6)r.   rU   r/   ÚInterpolationSyntaxErrorrÕ   rb   )r   r-   r   r   r	   Útest_other_errors  s    z;ConfigParserTestCaseExtendedInterpolation.test_other_errors)NN)r   r   r   r/   rá   r(   ÚExtendedInterpolationr&   r%   r$   r.   r  r  r  r  r  r  r   r   r   r	   r  ƒ  s   
-r  c               @   s   e Zd ZdZdS )ÚConfigParserTestCaseNoValueTN)r   r   r   r   r   r   r   r	   r   .  s   r   c               @   s2   e Zd ZejZdhZdhZdZdd„ Z	dd„ Z
dS )	ÚConfigParserTestCaseTrickyFiler   r   Tc          
   C   s|  t  d¡}|  ¡ }|  t|j|ddƒd¡ |  | ¡ ddddd	d
dg¡ |  |j| jdddidd¡ |  	t
¡ |j| jddddid W d Q R X |  t| dd¡ d¡ƒd¡ |  t| dd¡ d¡ƒd¡ d}|  | |d¡¡ |  | |d¡d¡ |  t| d¡ƒd¡ |  	tj¡ | d	¡ W d Q R X |  | d
d¡d¡ |  | d
d¡| d
d¡¡ |  | dd¡d¡ d S )Nzcfgparser.3zutf-8)rˆ   r   ZstrangeZ
corruptionz&yeah, sections can be indented as wellzanother one!zno values hereztricky interpolationzmore interpolationZgoZinterpolatez-1)rD   éÿÿÿÿT)ÚrawrD   Úotherr  é   r>   r÷   zare they subsectionszlets use some Unicodeu	   ç‰‡ä»®år    Zletszdo thiszgo shopping)r   rŒ   r*   rL   rN   rµ   rK   rQ   r%   rU   rb   rP   Úsplitr]   rT   r   r/   rÕ   )r   r   r-   Zlongnamer   r   r	   Útest_cfgparser_dot_38  s6    
z3ConfigParserTestCaseTrickyFile.test_cfgparser_dot_3c          	   C   s:   t  d¡}|  ¡ }|  t¡ |j|dd W d Q R X d S )Nzcfgparser.3Úascii)rˆ   )r   rŒ   r*   rU   ÚUnicodeDecodeErrorrµ   )r   r   r-   r   r   r	   Útest_unicode_failureX  s    
z3ConfigParserTestCaseTrickyFile.test_unicode_failureN)r   r   r   r/   rá   r(   r   r    r   r'  r*  r   r   r   r	   r!  2  s    r!  c               @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚIssue7005TestCasezrTest output when None is set() as a value and allow_no_value == False.

    http://bugs.python.org/issue7005

    z[section]
option = None

c             C   s<   |dd}|  d¡ | ddd ¡ t ¡ }| |¡ | ¡ S )NF)r   r:   rs   )r   r€   r–   r—   rª   r«   )r   r(   Úcpr›   r   r   r	   Úprepareh  s    


zIssue7005TestCase.preparec          	   C   s>   t jdd}| d¡ |  t¡ | ddd ¡ W d Q R X d S )NF)r   r:   rs   )r/   rá   r   rU   rÚ   r€   )r   r,  r   r   r	   Útest_none_as_value_stringifiedq  s    
z0Issue7005TestCase.test_none_as_value_stringifiedc             C   s   |   tj¡}|  || j¡ d S )N)r-  r/   rË   rL   Úexpected_output)r   r¬   r   r   r	   Ú"test_none_as_value_stringified_raww  s    z4Issue7005TestCase.test_none_as_value_stringified_rawN)r   r   r   Ú__doc__r/  r-  r.  r0  r   r   r   r	   r+  _  s
   	r+  c               @   s   e Zd ZeZdd„ ZdS )ÚSortedTestCasec             C   s0   |   d¡}t ¡ }| |¡ |  | ¡ d¡ d S )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ª   rL   r«   )r   r-   r¬   r   r   r	   Útest_sorted  s
    


zSortedTestCase.test_sortedN)r   r   r   r   r#   r3  r   r   r   r	   r2  |  s   r2  c               @   s"   e Zd ZejZdZdZdd„ ZdS )ÚCompatibleTestCasez#;r   c             C   sT   t  d¡}|  |¡}|  | dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ d S )	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 Barr8   zbar # not a comment!r6   r7   Zquirkzthis;is not a comment)rk   rl   r.   rL   rP   )r   rn   r-   r   r   r	   Útest_comment_handling˜  s    
z(CompatibleTestCase.test_comment_handlingN)	r   r   r   r/   rË   r(   r    r!   r5  r   r   r   r	   r4  “  s   r4  c               @   s   e Zd ZejZddd„ZdS )ÚCopyTestCaseNc             C   sx   |   |¡}| |¡ |   ¡ }| |¡ xL| ¡ D ]@}|j| jkrBq0x,|| j  ¡ D ]\}}|| |krR||= qRW q0W |S )N)r*   r+   ru   r   rO   r%   r   )r   r,   r   r-   Zcf_copyr:   r¼   r>   r   r   r	   r.   ¬  s    


zCopyTestCase.fromstring)N)r   r   r   r/   rá   r(   r.   r   r   r   r	   r6  ©  s   r6  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚFakeFilec          	   C   s6   t  d¡}t|ƒ}| ¡ | _| j ¡  W d Q R X d S )Nzcfgparser.1)r   rŒ   r   Ú	readlinesÚlinesÚreverse)r   Ú	file_pathr’   r   r   r	   Ú__init__½  s    


zFakeFile.__init__c             C   s   t | jƒr| j ¡ S dS )Nré   )rN   r9  Úpop)r   r   r   r	   r”   Ã  s    

zFakeFile.readlineN)r   r   r   r<  r”   r   r   r   r	   r7  ¼  s   r7  c             c   s$   |   ¡ }x|r|V  |   ¡ }q
W dS )z+As advised in Doc/library/configparser.rst.N)r”   )r’   Úliner   r   r	   Úreadline_generatorÉ  s    r?  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚReadFileTestCasec          
   C   s¢   t  d¡g}y| |d  d¡¡ W n tk
r8   Y nX xb|D ]Z}t ¡ }t|ƒ}| |¡ W d Q R X |  	d|¡ |  	d|d ¡ |  
|d d d¡ q@W d S )Nzcfgparser.1r   Úutf8zFoo Barr8   r³   )r   rŒ   rI   r¹   ÚUnicodeEncodeErrorr/   rá   r   r˜   ÚassertInrL   )r   Z
file_pathsr;  rY   r’   r   r   r	   Ú	test_fileÒ  s    

zReadFileTestCase.test_filec             C   sZ   t  d¡ ¡  d¡}t ¡ }| |¡ |  d|¡ |  d|d ¡ |  |d d d¡ d S )Nz%
        [Foo Bar]
        foo=newbarr  zFoo Barr8   r³   )	rk   rl   rî   r&  r/   rá   r˜   rC  rL   )r   r9  rY   r   r   r	   Útest_iterableà  s    
zReadFileTestCase.test_iterablec          	   C   sn   t  ¡ }|  t¡ | tƒ ¡ W dQ R X | ttƒ ƒ¡ |  d|¡ |  d|d ¡ |  |d d d¡ dS )zIssue #11670.NzFoo Barr8   r³   )	r/   rá   rU   rÚ   r˜   r7  r?  rC  rL   )r   rY   r   r   r	   Útest_readline_generatorê  s    z(ReadFileTestCase.test_readline_generatorc          	   C   sT  t  d¡ ¡  d¡}t ¡ }|  tj¡}|j|dd W dQ R X |  	t
|jƒd¡ t  d¡ ¡  d¡}t ¡ }|  tj¡}|j|dd W dQ R X |  	t
|jƒd¡ t  d	¡ ¡  d¡}t ¡ }|  tj¡}|j|dd W dQ R X |  	t
|jƒd
¡ t  d¡ ¡  d¡}t ¡ }|  tj¡}|j|dd W dQ R X |  	t
|jƒd¡ dS )zIssue #18260.z"
        [badbad]
        [badbad]r  s   badbad)r¤   NzGWhile 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')rk   rl   rî   r&  r/   rá   rU   rm   r˜   rL   r¦   r`   rj   rŠ   r‹   )r   r9  rY   Zdser   r   r	   Útest_source_as_bytesô  s@    z%ReadFileTestCase.test_source_as_bytesN)r   r   r   rD  rE  rF  rG  r   r   r   r	   r@  Ñ  s   

r@  c               @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚCoverageOneHundredTestCasez"Covers edge cases in the codebase.c             C   sf   t  dd¡}|  |jd¡ |  |jd¡ |  |jd ¡ |  |jd ¡ |  |jd¡ |  t|ƒd¡ d S )Nr:   rs   )r:   rs   NNz3Option 'option' in section 'section' already exists)	r/   rj   rL   r:   rs   r¤   Úlinenora   r¦   )r   r   r   r   r	   Útest_duplicate_option_error'  s    z6CoverageOneHundredTestCase.test_duplicate_option_errorc             C   s<   t  ddd¡}|  |jd¡ |  |jd¡ |  |jd¡ d S )Nrs   r:   Úrawval)rs   r:   rK  )r/   rÐ   rL   ra   rs   r:   )r   r   r   r   r	   Útest_interpolation_depth_error1  s
    z9CoverageOneHundredTestCase.test_interpolation_depth_errorc          	   C   sè   |   t¡}t ¡  W d Q R X |  t|jƒd¡ |   t¡}tjddd W d Q R X |  t|jƒd¡ tjdd}|  |jd¡ tj	dd4}t 
d	t¡ |  |jd¡ d|_|  |jd¡ W d Q R X x|D ]}|  |jtk¡ qÌW d S )
Nz%Required argument `source' not given.r¤   Úfilename)r¤   rM  z:Cannot specify both `filename' and `source'. Use `source'.)rM  T)ÚrecordÚalways)rU   rb   r/   rŠ   rL   r¦   r`   r¤   ÚwarningsÚcatch_warningsÚsimplefilterÚDeprecationWarningrM  r\   Úcategory)r   rg   r   rø   Úwarningr   r   r	   Útest_parsing_error8  s    
z-CoverageOneHundredTestCase.test_parsing_errorc          	   C   s‚   t  ¡ }| d¡ |  t j¡}|d d  W d Q R X |  t|jƒd¡ |  t j¡}|d d  W d Q R X |  t|jƒd¡ d S )Nz–
            [section]
            invalid_percent = %
            invalid_reference = %(()
            invalid_variable = %(does_not_exist)s
        r:   Zinvalid_percentz.'%' must be followed by '%' or '(', found: '%'Zinvalid_referencez+bad interpolation variable reference '%(()')r/   rá   r+   rU   r  rL   r¦   r`   )r   rY   rg   r   r   r	   Útest_interpolation_validationK  s    z8CoverageOneHundredTestCase.test_interpolation_validationc          	   C   sŠ   t  d¡}t ¡ }tjdd }t dt¡ |j|dd W d Q R X x|D ]}|  	|j
tk¡ qJW |  t|ƒd¡ |  |d d	 d
¡ d S )Nz2
        [section]
        option = value
        T)rN  rO  r—   )rM  r  r:   rs   r>   )r–   r—   r/   rá   rP  rQ  rR  rS  Zreadfpr\   rT  rL   rN   )r   r›   rY   rø   rU  r   r   r	   Útest_readfp_deprecation\  s    
z2CoverageOneHundredTestCase.test_readfp_deprecationc          	   C   sN   t jdd}t  dt¡ t ¡ }W d Q R X x|D ]}|  |jtk¡ q2W d S )NT)rN  rO  )rP  rQ  rR  rS  r/   ZSafeConfigParserr\   rT  )r   rø   rY   rU  r   r   r	   Ú!test_safeconfigparser_deprecationj  s
    
z<CoverageOneHundredTestCase.test_safeconfigparser_deprecationc             C   s*   t  ¡ }| d¡ |  t|d ƒd¡ d S )Nz7
            [section]
            key = value
        r:   z<Section: section>)r/   rá   r+   rL   Úrepr)r   rY   r   r   r	   Útest_sectionproxy_reprq  s    z1CoverageOneHundredTestCase.test_sectionproxy_reprc          	   C   s@  t  ¡ }dd l}|j|jd< | d¡ |  d|j¡ |  | dd¡d¡ |  | dd¡d	¡ |  |d  d¡d¡ |  |d  d¡d	¡ |`|  	t
¡ | dd¡ W d Q R X |  d|j¡ |jd= |  d|j¡ |  	t
¡ | dd¡ W d Q R X |  	t
¡ |d  d¡ W d Q R X |  	t
¡ |d  d¡ W d Q R X d S )
Nr   ÚdecimalzS
            [s1]
            one = 1
            [s2]
            two = 2
        Ús1rã   r   Ús2rä   r  )r/   rá   r\  ÚDecimalÚ
convertersr+   rC  rL   Ú
getdecimalrU   rZ   rÆ   )r   rY   r\  r   r   r	   Ú"test_inconsistent_converters_statey  s,    z=CoverageOneHundredTestCase.test_inconsistent_converters_stateN)r   r   r   r1  rJ  rL  rV  rW  rX  rY  r[  rb  r   r   r   r	   rH  $  s   
rH  c               @   sh   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚExceptionPicklingTestCasezBTests for issue #13760: ConfigParser exceptions are not picklable.c             C   sh   dd l }t d¡}xPt|jd ƒD ]>}| ||¡}| |¡}|  |j|j¡ |  t	|ƒt	|ƒ¡ q"W d S )Nr   r>   r   )
Úpickler/   ÚErrorr¡   ÚHIGHEST_PROTOCOLÚdumpsÚloadsrL   ÚmessagerZ  )r   rd  Úe1ÚprotoÚpickledÚe2r   r   r	   Ú
test_error™  s    

z$ExceptionPicklingTestCase.test_errorc             C   sˆ   dd l }t d¡}xpt|jd ƒD ]^}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  t|ƒt|ƒ¡ q"W d S )Nr   r:   r   )rd  r/   rV   r¡   rf  rg  rh  rL   ri  ra   r:   rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_nosectionerror¢  s    

z-ExceptionPicklingTestCase.test_nosectionerrorc             C   sš   dd l }t dd¡}x€t|jd ƒD ]n}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  t|ƒt|ƒ¡ q$W d S )Nr   rs   r:   r   )rd  r/   rW   r¡   rf  rg  rh  rL   ri  ra   r:   rs   rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_nooptionerror­  s    
z,ExceptionPicklingTestCase.test_nooptionerrorc             C   s¬   dd l }t ddd¡}xt|jd ƒD ]~}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  |j|j¡ |  t|ƒt|ƒ¡ q&W d S )Nr   r:   r¤   rp   r   )rd  r/   rm   r¡   rf  rg  rh  rL   ri  ra   r:   r¤   rI  rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_duplicatesectionerror¹  s    
z4ExceptionPicklingTestCase.test_duplicatesectionerrorc             C   s¾   dd l }t dddd¡}x t|jd ƒD ]Ž}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  |j|j¡ |  |j|j¡ |  t|ƒt|ƒ¡ q(W d S )Nr   r:   rs   r¤   rp   r   )rd  r/   rj   r¡   rf  rg  rh  rL   ri  ra   r:   rs   r¤   rI  rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_duplicateoptionerrorÆ  s    

z3ExceptionPicklingTestCase.test_duplicateoptionerrorc             C   sœ   dd l }t ddd¡}x€t|jd ƒD ]n}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  t|ƒt|ƒ¡ q&W d S )Nr   rs   r:   Úmsgr   )rd  r/   ZInterpolationErrorr¡   rf  rg  rh  rL   ri  ra   r:   rs   rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_interpolationerrorÕ  s    
z1ExceptionPicklingTestCase.test_interpolationerrorc             C   s®   dd l }t dddd¡}xt|jd ƒD ]~}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  |j|j¡ |  t|ƒt|ƒ¡ q(W d S )Nr   rs   r:   rK  rÔ   r   )rd  r/   rÕ   r¡   rf  rg  rh  rL   ri  ra   r:   rs   rÔ   rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Ú$test_interpolationmissingoptionerrorá  s    
z>ExceptionPicklingTestCase.test_interpolationmissingoptionerrorc             C   sœ   dd l }t ddd¡}x€t|jd ƒD ]n}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  t|ƒt|ƒ¡ q&W d S )Nr   rs   r:   rs  r   )rd  r/   r  r¡   rf  rg  rh  rL   ri  ra   r:   rs   rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_interpolationsyntaxerrorï  s    
z7ExceptionPicklingTestCase.test_interpolationsyntaxerrorc             C   sœ   dd l }t ddd¡}x€t|jd ƒD ]n}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  t|ƒt|ƒ¡ q&W d S )Nr   rs   r:   rK  r   )rd  r/   rÐ   r¡   rf  rg  rh  rL   ri  ra   r:   rs   rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_interpolationdeptherrorû  s    
z6ExceptionPicklingTestCase.test_interpolationdeptherrorc             C   sn  dd l }t d¡}| dd¡ | dd¡ | dd¡ x€t|jd ƒD ]n}| ||¡}| |¡}|  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  |j|j¡ |  t|ƒt|ƒ¡ qFW tjd	d
}| dd¡ | dd¡ | dd¡ x€t|jd ƒD ]n}| ||¡}| |¡}|  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  |j|j¡ |  t|ƒt|ƒ¡ qøW d S )Nr   r¤   r   Zline1r  Zline2r  Zline3rM  )rM  )rd  r/   rŠ   rI   r¡   rf  rg  rh  rL   ri  ra   r¤   ÚerrorsrZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_parsingerror  s2    


z+ExceptionPicklingTestCase.test_parsingerrorc             C   s¬   dd l }t ddd¡}xt|jd ƒD ]~}| ||¡}| |¡}|  |j|j¡ |  |j	|j	¡ |  |j
|j
¡ |  |j|j¡ |  |j|j¡ |  t|ƒt|ƒ¡ q&W d S )Nr   rM  rp   r>  r   )rd  r/   r‹   r¡   rf  rg  rh  rL   ri  ra   r>  r¤   rI  rZ  )r   rd  rj  rk  rl  rm  r   r   r	   Útest_missingsectionheadererror#  s    
z8ExceptionPicklingTestCase.test_missingsectionheadererrorN)r   r   r   r1  rn  ro  rp  rq  rr  rt  ru  rv  rw  ry  rz  r   r   r   r	   rc  –  s   	rc  c               @   s   e Zd ZdZdd„ ZdS )ÚInlineCommentStrippingTestCasez}Tests for issue #14590: ConfigParser doesn't strip inline comment when
    delimiter occurs earlier without preceding space..c             C   sÊ   t jdd}| d¡ |d }|  |d d¡ |  |d d¡ |  |d	 d
¡ |  |d d¡ |  |d d¡ |  |d d¡ |  |d d¡ |d }|  |d d¡ |  |d d¡ |  |d	 d¡ d S )N)r   r   z//)r!   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:   Zk1zv1;still v1Zk2Zv2Zk3Zv3Zk4zv4;still v4Zk5zv5;still v5Zk6zv6;still v6; and still v6Zk7zv7;still v7; and still v7Zmultiprefixzv3;#//still v3# and still v3)r/   rá   r+   rL   )r   Úcfgrû   r   r   r	   Útest_stripping5  s    z-InlineCommentStrippingTestCase.test_strippingN)r   r   r   r1  r}  r   r   r   r	   r{  1  s   r{  c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚExceptionContextTestCasezO Test that implementation details doesn't leak
    through raising exceptions. c          	   C   sN   t  ¡ }| d¡ |  t j¡}| | dd¡ W d Q R X |  |jjd¡ d S )Nz„
        [Paths]
        home_dir: /Users
        my_dir: %(home_dir1)s/lumberjack
        my_pictures: %(my_dir)s/Pictures
        ÚPathsÚmy_dirT)	r/   rá   r+   rU   rÕ   rP   rX   r`   Ú__suppress_context__)r   rY   rg   r   r   r	   Útest_get_basic_interpolationY  s    z5ExceptionContextTestCase.test_get_basic_interpolationc          	   C   sV   t jt  ¡ d}| d¡ |  t j¡}| | dd¡ W d Q R X |  |jj	d¡ d S )N)r&   z‚
        [Paths]
        home_dir: /Users
        my_dir: ${home_dir1}/lumberjack
        my_pictures: ${my_dir}/Pictures
        r  r€  T)
r/   rá   r  r+   rU   rÕ   rP   rX   r`   r  )r   rY   rg   r   r   r	   Útest_get_extended_interpolationf  s    z8ExceptionContextTestCase.test_get_extended_interpolationc          	   C   sH   t  ¡ }| d¡ |  t j¡}| d¡ W d Q R X |  |jjd¡ d S )Nz2
        [Paths]
        home_dir: /Users
        rÈ   T)	r/   rá   r+   rU   rV   r   rX   r`   r  )r   rY   rg   r   r   r	   Útest_missing_optionst  s    z-ExceptionContextTestCase.test_missing_optionsc          	   C   sB   t  ¡ }|  t j¡}| ddd¡ W d Q R X |  |jjd¡ d S )NÚSection1Úan_intZ15T)r/   rá   rU   rV   r€   rX   r`   r  )r   rv   rg   r   r   r	   Útest_missing_section~  s    z-ExceptionContextTestCase.test_missing_sectionc          	   C   s@   t  ¡ }|  t j¡}| dd¡ W d Q R X |  |jjd¡ d S )Nr…  r†  T)r/   rá   rU   rV   r_   rX   r`   r  )r   rv   rg   r   r   r	   Útest_remove_option„  s    z+ExceptionContextTestCase.test_remove_optionN)	r   r   r   r1  r‚  rƒ  r„  r‡  rˆ  r   r   r   r	   r~  U  s   
r~  c                   s0   e Zd ZdZejZd‡ fdd„	Zdd„ Z‡  Z	S )ÚConvertersTestCasez Introduced in 3.5, issue #18159.Nc                s    t ƒ j|d}dd„ |jd< |S )N)r   c             S   s   dd„ |   ¡ D ƒS )Nc             S   s   g | ]}|  ¡ r|  ¡ ‘qS r   )rî   )r   rŽ   r   r   r	   r   ’  s    zBConvertersTestCase.newconfig.<locals>.<lambda>.<locals>.<listcomp>)r&  )Úvr   r   r	   r	  ’  r
  z.ConvertersTestCase.newconfig.<locals>.<lambda>rM   )Úsuperr*   r`  )r   r   r)   )Ú	__class__r   r	   r*     s    zConvertersTestCase.newconfigc          
   C   sÜ  |   ¡ }|  d|j¡ |  d|j¡ |  |jd ¡ |  |jd ¡ |  |jd ¡ |  |jd ¡ |  t|jƒd¡ |  t¡ dd„ |jd< W d Q R X |  t¡ d	d„ |jd < W d Q R X | 	d
¡ |d }|  |d d¡ |  |d d¡ |  |d d¡ |  |d d¡ |  |d d¡ |  | 
dd¡d¡ |  | 
dd¡d¡ |  | 
dd¡d¡ |  | 
dd¡d¡ |  | 
dd¡d¡ |  | 
dd¡d¡ |  | dd¡d¡ |  | dd¡d¡ |  | dd¡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g¡ |  | d¡d¡ |  t¡ | dd¡ W d Q R X |  t¡ | d¡ W d Q R X dd l}|j|jd< |  d|j¡ |  |jd ¡ |  t|jƒd¡ | d¡}|  | dd¡|¡ |  | d¡|¡ |jd= |  d|j¡ |  t|jƒd¡ |  t¡ | dd¡ W d Q R X |  t¡ | d¡ W d Q R X |  t¡ |jd= W d Q R X |  t¡ |jd= W d Q R X |  t¡ |jd = W d Q R X d S ) NrB   rM   r?   rA   r%  c             S   s   | S )Nr   )rŠ  r   r   r	   r	     r
  z4ConvertersTestCase.test_converters.<locals>.<lambda>ré   c             S   s   | S )Nr   )rŠ  r   r   r	   r	  ¢  r
  z~
        [s]
        str = string
        int = 1
        float = 0.5
        list = a b c d e f g
        bool = yes
        rû   r¦   r,   rG   z0.5za b c d e f gÚboolrF   r   g      à?ry   r{   ÚcÚdrŽ   r’   ÚgTr   r\  r    )r*   rC  r`  rê   ÚassertIsNotNonerL   rN   rU   rb   r+   rP   rQ   rS   ZgetlistrT   rZ   ra  r\  r_  rÆ   r[   )r   r|  rû   r\  Zdec0_5r   r   r	   Útest_converters–  s|    
z"ConvertersTestCase.test_converters)N)
r   r   r   r1  r/   rá   r(   r*   r’  Ú__classcell__r   r   )rŒ  r	   r‰  ‹  s   r‰  c               @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )Ú!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
    c             C   s:   t jdtid}| | j¡ |  |¡ |  |jd ¡ d S )NrN   )r`  )r/   rá   rN   r+   rv   Ú	_test_lenr‘  r`  )r   r|  r   r   r	   Útest_converters_at_inití  s    
z9BlatantOverrideConvertersTestCase.test_converters_at_initc             C   sÞ   G dd„ dt jƒ}|ƒ }| | j¡ |  |¡ |  |jd ¡ |  | dd¡¡ |  | dd¡¡ |  	| dd¡¡ |  	| dd¡¡ |j
|jd< |  	| dd¡¡ |  	| dd¡¡ |  	| dd¡¡ |  	| dd¡¡ d S )Nc                   s@   e Zd ZdZddejdœ‡ fdd„
Zddejdœdd„Z‡  ZS )	zOBlatantOverrideConvertersTestCase.test_inheritance.<locals>.StrangeConfigParserz0a historic borough in south central PennsylvaniaFN)r#  rD   rC   c               s"   ||krdS t ƒ j|||||dS )NT)r#  rD   rC   )r‹  rT   )r   r:   rs   r#  rD   rC   )rŒ  r   r	   rT   ÷  s    zZBlatantOverrideConvertersTestCase.test_inheritance.<locals>.StrangeConfigParser.getbooleanc            S   s   | j ||t|||dS )N)r#  rD   rC   )Z	_get_convrN   )r   r:   rs   r#  rD   rC   r   r   r	   Úgetlený  s    zVBlatantOverrideConvertersTestCase.test_inheritance.<locals>.StrangeConfigParser.getlen)	r   r   r   Z
gettysburgr/   r1   rT   r—  r“  r   r   )rŒ  r	   ÚStrangeConfigParserô  s
   r˜  rN   rã   rä   rB   )r/   rá   r+   rv   r•  rê   r`  r\   rT   r]   Ú_convert_to_boolean)r   r˜  r|  r   r   r	   Útest_inheritanceó  s    
z2BlatantOverrideConvertersTestCase.test_inheritancec          	   C   sÖ  |   t|jƒd¡ |  d|j¡ |  d|j¡ |  d|j¡ |  |jd ¡ |  |jd ¡ |  |jd ¡ |   | dd¡d¡ |   | dd	¡d¡ |   | dd
¡d¡ |   | d	d¡d¡ |   | d	d	¡d¡ |   | d	d
¡d¡ |   |jd	dddd¡ |  tj	¡ | d	d¡ W d Q R X |   |d  d¡d¡ |   |d  d	¡d¡ |   |d  d
¡d¡ |   |d	  d¡d¡ |   |d	  d	¡d¡ |   |d	  d
¡d¡ |   |d	  dd¡d¡ |   |d	  d¡d ¡ d S )Nr%  rB   rN   Ztysburgr?   rA   rã   r    rä   rå   é   Zfourr   )rC   )
rL   rN   r`  rC  rÆ   rê   r—  rU   r/   rW   )r   r|  r   r   r	   r•    s0    z+BlatantOverrideConvertersTestCase._test_lenc          	      sú  t  ¡ ‰ dd„ ˆ _‡ fdd„ˆ _ˆ  | j¡ |  tˆ jƒd¡ |  	dˆ j¡ |  
dˆ j¡ |  ˆ jd ¡ |  ˆ jd ¡ |  ˆ jd ¡ |  ˆ  d	d	¡¡ |  ˆ  d
d
¡¡ |  ˆ  d	d
¡¡ |  ˆ  d
d	¡¡ ˆ jˆ jd< |  ˆ  d	d	¡¡ |  ˆ  d
d
¡¡ |  ˆ  d	d
¡¡ |  ˆ  d
d	¡¡ |  ˆ  d	d	¡d¡ |  ˆ  d	d
¡d¡ |  ˆ  d	d¡d¡ |  ˆ  d
d	¡d¡ |  ˆ  d
d
¡d¡ |  ˆ  d
d¡d¡ |  t¡ |  ˆ d	  d	¡d¡ W d Q R X |  t¡ |  ˆ d
  d	¡d¡ W d Q R X d S )Nc             S   s   dS )NTr   )r:   rs   r   r   r	   r	  ,  r
  zLBlatantOverrideConvertersTestCase.test_instance_assignment.<locals>.<lambda>c                s   t ˆ |  | ƒS )N)rN   )r:   rs   )r|  r   r	   r	  -  r
  r  rB   rN   r?   rA   rã   rä   r    rå   r›  r%  )r/   rá   rT   r—  r+   rv   rL   rN   r`  rC  rÆ   rê   r\   r™  r]   rU   rZ   )r   r   )r|  r	   Útest_instance_assignment*  s:    
 z:BlatantOverrideConvertersTestCase.test_instance_assignmentN)	r   r   r   r1  rv   r–  rš  r•  rœ  r   r   r   r	   r”  Ý  s   r”  c               @   s   e Zd Zdd„ ZdS )ÚMiscTestCasec             C   s   dh}t j| t|d d S )Nre  )Ú	blacklist)r   Zcheck__all__r/   )r   rž  r   r   r	   Útest__all__M  s    zMiscTestCase.test__all__N)r   r   r   rŸ  r   r   r   r	   r  L  s   r  Ú__main__),Úcollectionsr/   r–   rþ   r¶   rk   ZunittestrP  rÈ   r   ÚUserDictr   r   r2   ZTestCaserÊ   rÌ   râ   rï   rð   ró   rô   r  r  r  r  r   r!  r+  r2  r4  r6  r7  r?  r@  rH  rc  r{  r~  r‰  r”  r  r   Úmainr   r   r   r	   Ú<module>   s`   !      -c$4 ,-Sr $6Ro
