kWc@spddlZddlZddlZddlZddlZddlmZdejfdYZdejfdYZ de fdYZ d e fd YZ d e fd YZ d e fdYZ de fdYZdejfdYZdejfdYZde fdYZdejfdYZdZedkrlendS(iN(t test_supportt SortedDictcBsDeZdZdZdZdZdZeZdZRS(cCs|jj}|j|S(N(tdatatitemstsort(tselftresult((s)/usr/lib/python2.7/test/test_cfgparser.pyR s cCs|jj}|j|S(N(RtkeysR(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyRs cCs'|j}g|D]}|d^qS(Ni(R(RRti((s)/usr/lib/python2.7/test/test_cfgparser.pytvaluess cCst|jS(N(titerR(R((s)/usr/lib/python2.7/test/test_cfgparser.pyt iteritemsscCst|jS(N(R R(R((s)/usr/lib/python2.7/test/test_cfgparser.pytiterkeysscCst|jS(N(R R (R((s)/usr/lib/python2.7/test/test_cfgparser.pyt itervaluess( t__name__t __module__RRR R R t__iter__R (((s)/usr/lib/python2.7/test/test_cfgparser.pyR s     t TestCaseBasecBseZeZddZddZdZdZdZ dZ dZ dZ dZ d Zd Zd Zd Zd ZdZdZdZRS(cCsI|dkr'|jd|j|_n|j|d|j|_|jS(Ntallow_no_value(tNonet config_classRtcf(Rtdefaults((s)/usr/lib/python2.7/test/test_cfgparser.pyt newconfig#s   cCs/|j|}tj|}|j||S(N(RtStringIOtreadfp(RtstringRRtsio((s)/usr/lib/python2.7/test/test_cfgparser.pyt fromstring+s cCsd}|jr|d7}n|j|}|j}|jddddddd g}|jru|jd n|j|j}|||||jdd d ||jd d d ||jdd d ||jdd d||jddd|jr7||jd ddn|jd|j dd|j |j dd d|j |j dd d|j |j dd d|jtj|j dd ||jdd ddS(NsQ[Foo Bar] foo=bar [Spacey Bar] foo = bar [Commented Bar] foo: bar ; comment [Long Line] foo: this line is much, much longer than my editor likes it. [Section\with$weird%characters[ ] [Internationalized Stuff] foo[bg]: Bulgarian foo=Default foo[en]=English foo[de]=Deutsch [Spaces] key with spaces : value another with spaces = splat! s[NoValue] option-without-value s Commented BarsFoo BarsInternationalized Stuffs Long LinesSection\with$weird%characters[ tSpacess Spacey BartNoValuetfootbarskey with spacestvaluesanother with spacesssplat!soption-without-valueRs3__name__ "option" should not be exposed by the API!s4remove_option() failed to report existence of options'remove_option() failed to remove optionsIremove_option() failed to report non-existence of option that was removedsNo Such Sections7this line is much, much longer than my editor likes it.(RRtsectionsRtappendt assertEqualtgetRt assertNotIntoptionst assertTruet remove_optiont assertFalset has_optiont assertRaisest ConfigParsertNoSectionError(Rt config_stringRtLtEteq((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_basic1sL           cCs|j}|jd|jd|j}|j|j}||ddg|jddd||jddg||jdddd|j|j dd|jdddx*dD]"}|j|j d|d qW||jdd g||jddg|j dd||jdg|j d }||jddg||jddd|j ddidd6}|j|j dddS(NtAtatBR!tbs@could not locate option, expecting case-insensitive option namessA-Bs A-B valuesa-bsA-bsa-Bs9has_option() returned false for option which should exists,[MySection] Option: first line second line t MySectiontoptiontOptionsfirst line second lines[section] nekey=nevalue RtkeytsectiontKey(sa-bsA-bsa-BsA-B( Rt add_sectionR"RR$tsetR'R%R(R+R)R(RRR0R2topt((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_case_sensitivity{s8          cCsn|jidd6}|j|jdddd|jidd6}|j|jdddddS(NtBarRtDEFAULTtFoos@could not locate option, expecting case-insensitive option namess<could not locate option, expecting case-insensitive defaults(RR$R%(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_default_case_sensitivityscCsm|j|jtjd|jtjd|jtjd|jtjd|jtjddS(Ns[Foo] extra-spaces: splat s[Foo] extra-spaces= splat s![Foo] :value-without-option-name s![Foo] =value-without-option-name s No Section! (Rt parse_errorR-t ParsingErrortMissingSectionHeaderError(R((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_parse_errorss      cCs,tj|}|j||jj|dS(N(RR,RR(RtexctsrcR((s)/usr/lib/python2.7/test/test_cfgparser.pyRFscCs|j}|j|jgd|j|jdd|jtj|jd|jtj|j ddd|j tjdd|j d|j tj dddS(Ns0new ConfigParser should have no defined sectionsRDs5new ConfigParser should have no acknowledged sectionsRR R!( RR$R"R*t has_sectionR,R-R.R'R?t get_errorR>t NoOptionError(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_query_errorss     cCsOy|jj||Wn|k r-}|SX|jd|j|jfdS(Nsexpected exception type %s.%s(RR%tfailRR(RRJR<R9te((s)/usr/lib/python2.7/test/test_cfgparser.pyRMs  cCs|jd}xntddD]]}|j|jdd||j|jdd||jt|jdd|qWdS(Ns{[BOOLTEST] T1=1 T2=TRUE T3=True T4=oN T5=yes F1=0 F2=FALSE F3=False F4=oFF F5=nO E1=2 E2=foo E3=-1 E4=0.1 E5=FALSE AND MOREiitBOOLTESTst%dsf%dse%d(RtrangeR(t getbooleanR*R,t ValueError(RRtx((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_booleans  cCs6|j}|jd|jtj|jddS(NRD(RR>R,R-tDuplicateSectionError(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_weird_errorss   cCszd}|jr|d7}n|j|}tj}|j|d}|jr`|d7}n|j|j|dS(Nss[Long Line] foo: this line is much, much longer than my editor likes it. [DEFAULT] foo: another very long line s![Valueless] option-without-value su[DEFAULT] foo = another very long line [Long Line] foo = this line is much, much longer than my editor likes it. s"[Valueless] option-without-value (RRRtwriteR$tgetvalue(RR/Rtoutputt expect_string((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_writes      cCs|jd}dtfdY}|jddd|jdd|d|jddd|jdd|ddS(Ns[sect] option1=foo tmystrcBseZRS((RR(((s)/usr/lib/python2.7/test/test_cfgparser.pyR_stsecttoption1tsplattoption2(RtstrR?(RRR_((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_set_string_typess cCsnytWntk r(|jdnX|jd}|jddtd|jddtddS(Nsno unicode supports[sect] option1=foo R`RaRbRc(tunicodet NameErrortskipTestRR?(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_set_unicode s cCstjd}|j}|j|dg}|j||g|j|jddd|j}|j|}|j||g|j|jddd|j}|jdg}|j|g|j}|jg}|j|gdS(Ns cfgparser.1snonexistent-filesFoo BarRtnewbar(RtfindfileRtreadR$R%(Rtfile1Rt parsed_files((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_read_returns_file_list+s    cCs|jddidd6S(Ns[Foo] bar=something %(with1)s interpolation (1 step) bar9=something %(with9)s lots of interpolation (9 steps) bar10=something %(with10)s lots of interpolation (10 steps) bar11=something %(with11)s lots of interpolation (11 steps) with11=%(with10)s with10=%(with9)s with9=%(with8)s with8=%(With7)s with7=%(WITH6)s with6=%(with5)s With5=%(with4)s WITH4=%(with3)s with3=%(with2)s with2=%(with1)s with1=with [Mutual Recursion] foo=%(bar)s bar=%(foo)s [Interpolation Error] name=%(reference)s Rs %(__name__)stgetname(R(R((s)/usr/lib/python2.7/test/test_cfgparser.pytget_interpolation_configAscCsO|jddidd6}t|jd}|j|j||dS(NsY[section] name = value key: |%(name)s| getdefault: |%(default)s| getname: |%(__name__)s|Rs tdefaultR<(RtlistRRR$(RtexpectedRR0((s)/usr/lib/python2.7/test/test_cfgparser.pytcheck_items_config]s  N(RRtFalseRRRRR3RARERIRFRORMRWRYR^ReRiRoRqRu(((s)/usr/lib/python2.7/test/test_cfgparser.pyR s$   J #     $  tConfigParserTestCasecBs;eZejZeZdZdZdZdZ RS(cCsidtj6dtj6}|j}|j}||jddd||jddd||jddd||jdd d |jtjdd dS( Ns5something %(with11)s lots of interpolation (11 steps)s %(with1)sRDRpR s%something with interpolation (1 step)tbar9s.something with lots of interpolation (9 steps)tbar10s/something with lots of interpolation (10 steps)tbar11(R-tSafeConfigParserRqR$R%RMtInterpolationDepthError(RtrawvalRR2((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_interpolationns    cCs_|j|jtjdd}|j|jd|j|jd|j|jddS(NsInterpolation Errortnamet reference(RqRMR-tInterpolationErrorR$RR<R9(RRQ((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_interpolation_missing_value~s    cCs |jd d d ddgdS(NRrs t getdefaults ||Rps |section|R;s|value|RR!(sdefaults (Rs ||(sgetnames |section|(skeys|value|(snamesvalue(Ru(R((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_itemss  c Cs|j}|jd|jddd|jddddddddd d d g |jdd id d6dd 6dd6|jddd|jdd|j|jdddtd|jt|jdd|j|jdddtddddddd d d g |jt|jdd|j|jdd dtid d6dd 6dd6|jt|jdd |j|jdddtd|jt|jdddt |j|jddddS(Ns non-stringtintiRsiiiiii s%(tdictgn! @tpis%(list)tstring_with_interpolations%(list)ssno-valuetraw( RR>R?R$R%tTrueR,t TypeErrorRURvR(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_set_nonstring_typess*  . ""  ( RRR-RRRR~RRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRwjs     tMultilineValuesTestCasecBs>eZejZdjddZdZdZdZRS(sSI'm having spam spam spam spam spam spam spam beaked beans spam spam spam and spam!t s cCs|j}xftdD]X}dj|}|j|x3tdD]%}|j|dj||jqHWqWttjd}|j |WdQXdS(Nids section{}i s lovely_spam{}tw( RRStformatR>R?twonderful_spamtopenRtTESTFNRZ(RRRtstjtf((s)/usr/lib/python2.7/test/test_cfgparser.pytsetUps  'cCstjtjdS(N(tostunlinkRR(R((s)/usr/lib/python2.7/test/test_cfgparser.pyttearDownscCs`|j}ttj}|j|WdQX|j|jdd|jjdddS(Ntsection8t lovely_spam4s s ( RRRRRR$R%Rtreplace(Rt cf_from_fileR((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_dominating_multiline_valuess  ( RRR-RRRRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRs    tRawConfigParserTestCasecBs,eZejZdZdZdZRS(cCs|j}|j}||jddd||jddd||jddd||jddd ||jdd d dS( NRDRps %(__name__)sR s*something %(with1)s interpolation (1 step)Rxs3something %(with9)s lots of interpolation (9 steps)Rys5something %(with10)s lots of interpolation (10 steps)Rzs5something %(with11)s lots of interpolation (11 steps)(RqR$R%(RRR2((s)/usr/lib/python2.7/test/test_cfgparser.pyR~s  cCs |jd d d ddgdS(NRrs Rs |%(default)s|Rps|%(__name__)s|R;s |%(name)s|RR!(sdefaults (s getdefaults |%(default)s|(sgetnames|%(__name__)s|(skeys |%(name)s|(snamesvalue(Ru(R((s)/usr/lib/python2.7/test/test_cfgparser.pyRs  c Cs|j}|jd|jddd|jddddddddd d g|jdd id d 6|j|jddd|j|jddddddddd d g|j|jdd id d 6dS(Ns non-stringRiRsiiiiii Rgn! @R(RR>R?R$R%(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyRs  +(RRR-tRawConfigParserRR~RR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRs  tSafeConfigParserTestCasecBs>eZejZdZdZdZdZdZ RS(cCsK|jd}|j|jddd|j|jddddS(NsW[section] option1=xxx option2=%(option1)s/xxx ok=%(option1)s/%%s not_ok=%(option2)s/%%sR<toksxxx/%stnot_oks xxx/xxx/%s(RR$R%(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_safe_interpolationscCs|jd}|j|jddd|jt|jddd|jt|jddd|jt|jddd|j|jddd|jddd |j|jddd dS( Ns[sect] option1=foo R`RaRs%foosfoo%sf%ooRcsfoo%%barsfoo%bar(RR$R%R,RUR?(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyt#test_set_malformatted_interpolationscCs|jd}|jt|jddd|jt|jddd|jt|jddt|jt|jddd|jt|jddd|jt|jddtdS(Ns[sect] option1=foo R`Raig?Rc(RR,RR?tobject(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyRscCs&|j}|jt|jddS(NRr(RR,RUR>(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_add_section_default_1 s cCs&|j}|jt|jddS(NRC(RR,RUR>(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_add_section_default_2s ( RRR-R{RRRRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRs    tSafeConfigParserTestCaseNoValuecBseZeZRS((RRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRst TestChainMapcBseZdZRS(c Cs7tdddd}tdddd}|j}|j|tj||}|j|jt|jt |jt |j|jt |j t |j |jt |j t |j |jt |t ||j|||jg|D]}||^q|j dj }|jg|D]}|j |d ^qUg|D]}|j |d ^qw|jg|D]}||k^qg|D]}||k^qtjM|jg|D]}|j|^qg|D]}|j|^qWdQXdS( Ntreditgreeniitblueisred green blue black browni (RtcopytupdateR-t _ChainmaptassertIsInstanceRRsR$R?R RtsplitR%Rtcheck_py3k_warningsthas_key(Rtd1td2tdcombtcmtktklist((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_issue_12717s(  (((- (&"  %(RRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRstIssue7005TestCasecBs/eZdZdZdZdZdZRS(srTest output when None is set() as a value and allow_no_value == False. http://bugs.python.org/issue7005 s[section] option = None cCsR|dt}|jd|jdddtj}|j||jS(NRR<R9(RvR>R?RRRZR[(RRtcpR((s)/usr/lib/python2.7/test/test_cfgparser.pytprepare8s    cCs)|jtj}|j||jdS(N(RR-R$texpected_output(RR\((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_none_as_value_stringifiedAscCs)|jtj}|j||jdS(N(RR-RR$R(RR\((s)/usr/lib/python2.7/test/test_cfgparser.pyt"test_none_as_value_stringified_rawEs(RRt__doc__RRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyR/s  tSortedTestCasecBseZddZdZRS(cCs"|jd|dt|_|jS(NRt dict_type(RRR(RR((s)/usr/lib/python2.7/test/test_cfgparser.pyRKscCsC|jdtj}|jj||j|jddS(Ns [b] o4=1 o3=2 o2=3 o1=4 [a] k=v s,[a] k = v [b] o1 = 4 o2 = 3 o3 = 2 o4 = 1 (RRRRZR$R[(RR\((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_sortedOs   N(RRRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRJs tExceptionPicklingTestCasecBsheZdZdZdZdZdZdZdZdZ dZ d Z d Z RS( sBTests for issue #13760: ConfigParser exceptions are not picklable.cCsoddl}tjd}|j|}|j|}|j|j|j|jt|t|dS(NiR!(tpickleR-tErrortdumpstloadsR$tmessagetrepr(RRte1tpickledte2((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_errorfs  cCsddl}tjd}|j|}|j|}|j|j|j|j|j|j|j|j|j|jt |t |dS(NiR<( RR-R.RRR$RtargsR<R(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_nosectionerrorns cCsddl}tjdd}|j|}|j|}|j|j|j|j|j|j|j|j|j|j|j |j |jt |t |dS(NiR9R<( RR-RNRRR$RRR<R9R(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_nooptionerrorxs cCsddl}tjd}|j|}|j|}|j|j|j|j|j|j|j|j|j|jt |t |dS(NiR<( RR-RXRRR$RRR<R(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_duplicatesectionerrors cCsddl}tjddd}|j|}|j|}|j|j|j|j|j|j|j|j|j|j|j |j |jt |t |dS(NiR9R<tmsg( RR-RRRR$RRR<R9R(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_interpolationerrors cCsddl}tjdddd}|j|}|j|}|j|j|j|j|j|j|j|j|j|j|j |j |j|j |j |jt |t |dS(NiR9R<R}R( RR-tInterpolationMissingOptionErrorRRR$RRR<R9RR(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyt$test_interpolationmissingoptionerrors   cCsddl}tjddd}|j|}|j|}|j|j|j|j|j|j|j|j|j|j|j |j |jt |t |dS(NiR9R<R( RR-tInterpolationSyntaxErrorRRR$RRR<R9R(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_interpolationsyntaxerrors cCsddl}tjddd}|j|}|j|}|j|j|j|j|j|j|j|j|j|j|j |j |jt |t |dS(NiR9R<R}( RR-R|RRR$RRR<R9R(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_interpolationdeptherrors   cCsddl}tjd}|jdd|jdd|jdd|j|}|j|}|j|j|j|j|j|j|j|j |j |j|j |j |jt |t |dS( Nitsourceitline1itline2itline3( RR-RGR#RRR$RRtfilenameterrorsR(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_parsingerrors cCsddl}tjddd}|j|}|j|}|j|j|j|j|j|j|j|j|j|j|j |j |j|j |j |jt |t |dS(NiRi{tline( RR-RHRRR$RRRRtlinenoR(RRRRR((s)/usr/lib/python2.7/test/test_cfgparser.pyttest_missingsectionheadererrors ( RRRRRRRRRRRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyRcs  c Cs)tjtttttttt t dS(N( Rt run_unittestRwRRRRRRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyt test_mainst__main__(R-RRtunittesttUserDictttestRRtTestCaseRRwRRRRRRRRRR(((s)/usr/lib/python2.7/test/test_cfgparser.pyts(     K:#2t