mò
­fIc           @   s¨   d  k  Z  d  k Z d  k Z d k l Z d e i f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ	 d
 „  Z
 e d j o e
 ƒ  n d  S(   N(   s   test_supportt   TestCaseBasec           B   sž   t  Z d  d „ Z d  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   Nc         C   s9   | d  j o |  i ƒ  |  _ n |  i | ƒ |  _ |  i S(   N(   t   defaultst   Nonet   selft   config_classt   cf(   R   R   (    (    t0   /mit/python/lib/python2.4/test/test_cfgparser.pyt	   newconfig	   s    c         C   s/   |  i | ƒ } t i | ƒ } | i | ƒ | S(   N(   R   R   R   R   t   StringIOt   stringt   siot   readfp(   R   R	   R   R   R
   (    (    R   t
   fromstring   s    c      	   C   sy  |  i d ƒ } | i ƒ  } | i ƒ  |  i } | | d d d d d d d g ƒ | | i d d	 ƒ d
 ƒ | | i d d	 ƒ d
 ƒ | | i d d	 ƒ d
 ƒ | | i d d ƒ d ƒ | | i d d ƒ d ƒ |  i	 d | i
 d ƒ j d ƒ |  i | i d d	 ƒ d ƒ |  i	 | i d d	 ƒ d ƒ |  i	 | i d d	 ƒ d ƒ |  i t i | i d d	 ƒ | | i d d	 ƒ d ƒ d  S(   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   Commented Bars   Foo Bars   Internationalized Stuffs	   Long Lines   Section\with$weird%characters[	t   Spacess
   Spacey Bart   foot   bars   key with spacest   values   another with spacess   splat!t   __name__s3   __name__ "option" should not be exposed by the API!s4   remove_option() failed to report existance of options'   remove_option() failed to remove optionsI   remove_option() failed to report non-existance of option that was removeds   No Such Sections7   this line is much, much longer than my editor
likes it.(   R   R   R   t   sectionst   Lt   sortt   assertEqualt   eqt   gett   failIft   optionst
   failUnlesst   remove_optiont
   has_optiont   assertRaisest   ConfigParsert   NoSectionError(   R   R   R   R   (    (    R   t
   test_basic   s,    
	"c         C   sÍ  |  i ƒ  } | i d ƒ | i d ƒ | i ƒ  } | i ƒ  |  i } | | d d g ƒ | i	 d d d ƒ | | i
 d ƒ d g ƒ | | i d d ƒ d d ƒ |  i | i d d ƒ ƒ | i	 d d d ƒ x* d D]" } |  i | i d | ƒ d ƒ qÓ W| | i
 d ƒ d	 g ƒ | | i
 d ƒ d g ƒ | i d d ƒ | | i
 d ƒ g  ƒ |  i d ƒ } | | i
 d ƒ d g ƒ | | i d d ƒ d ƒ |  i d d h  d d <ƒ} |  i | i d d ƒ ƒ d  S(   Nt   At   at   BR   t   bs@   could not locate option, expecting case-insensitive option namess   A-Bs	   A-B values   a-bs   A-bs   a-Bs9   has_option() returned false for option which should exists,   [MySection]
Option: first line
	second line
t	   MySectiont   optiont   Options   first line
second lines   [section]
nekey=nevalue
R   t   keyt   sectiont   Key(   s   a-bs   A-bs   a-Bs   A-B(   R   R   R   t   add_sectionR   R   R   R   R   t   setR   R   R   R   t   optR   R   (   R   R-   R   R   R   (    (    R   t   test_case_sensitivityS   s6    
	 	c         C   sr   |  i h  d d <ƒ } |  i | i d d ƒ d d ƒ |  i h  d d <ƒ } |  i | i d d ƒ d d ƒ d  S(   NR   t   Bart   DEFAULTt   Foos@   could not locate option, expecting case-insensitive option namess<   could not locate option, expecting case-insensitive defaults(   R   R   R   R   R   (   R   R   (    (    R   t   test_default_case_sensitivityv   s    c         C   s€   |  i ƒ  |  i t i d ƒ |  i t i d ƒ |  i t i d ƒ |  i t i d ƒ |  i t i d ƒ |  i t i d ƒ d  S(   Ns   [Foo]
  extra-spaces: splat
s   [Foo]
  extra-spaces= splat
s   [Foo]
option-without-value
s!   [Foo]
:value-without-option-name
s!   [Foo]
=value-without-option-name
s   No Section!
(   R   R   t   parse_errorR   t   ParsingErrort   MissingSectionHeaderError(   R   (    (    R   t   test_parse_errors€   s    
c         C   s,   t  i  | ƒ } |  i | |  i i | ƒ d  S(   N(   R   t   srcR
   R   R   t   excR   R   (   R   R8   R7   R
   (    (    R   R3      s    c         C   s³   |  i ƒ  } |  i | i ƒ  g  d ƒ |  i | i d ƒ d ƒ |  i t i	 | i
 d ƒ |  i t i	 | i d d d ƒ |  i t i	 d d ƒ | i d ƒ |  i t i d d ƒ d  S(   Ns0   new ConfigParser should have no defined sectionsR1   s5   new ConfigParser should have no acknowledged sectionsR   R   R   (   R   R   R   R   R   R   t   has_sectionR   R   R   R   R,   t	   get_errorR+   t   NoOptionError(   R   R   (    (    R   t   test_query_errors“   s    c         C   sT   y |  i i | | ƒ Wn | j
 o } | Sn X|  i d | i | i	 f ƒ d  S(   Ns   expected exception type %s.%s(
   R   R   R   R)   R&   R8   t   et   failt
   __module__R   (   R   R8   R)   R&   R=   (    (    R   R:   ¡   s
    	c         C   s„   |  i d ƒ } xn t d d ƒ D]] } |  i | i d d | ƒ ƒ |  i | i d d | ƒ ƒ |  i t	 | i d d | ƒ q Wd  S(   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 MOREi   i   t   BOOLTESTs   t%ds   f%ds   e%d(
   R   R   R   t   ranget   xR   t
   getbooleanR   R   t
   ValueError(   R   RB   R   (    (    R   t   test_booleanª   s     	c         C   s6   |  i ƒ  } | i d ƒ |  i t i | i d ƒ d  S(   NR1   (   R   R   R   R+   R   R   t   DuplicateSectionError(   R   R   (    (    R   t   test_weird_errorsÃ   s    c         C   sB   |  i d ƒ } t i ƒ  } | i | ƒ |  i | i ƒ  d ƒ d  S(   Nsr   [Long Line]
foo: this line is much, much longer than my editor
   likes it.
[DEFAULT]
foo: another very
 long linesu   [DEFAULT]
foo = another very
	long line

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

(   R   R   R   R   t   outputt   writeR   t   getvalue(   R   RH   R   (    (    R   t
   test_writeÉ   s
    c         C   sÑ   |  i d ƒ } d t f d „  ƒ  Y} | i d d d ƒ | i d d | d ƒ ƒ | i d d d ƒ | i d d | d ƒ ƒ y t Wn t j
 o n4 X| i d d t d ƒ ƒ | i d d t d ƒ ƒ d  S(   Ns   [sect]
option1=foo
t   mystrc           B   s   t  Z RS(   N(   R   R?   (    (    (    R   RL   å   s   t   sectt   option1t   splatt   option2(   R   R   R   t   strRL   R,   t   unicodet	   NameError(   R   R   RL   (    (    R   t   test_set_string_typesà   s    c         C   s  t  i d ƒ } |  i ƒ  } | i | d g ƒ } |  i | | g ƒ |  i | i	 d d ƒ d ƒ |  i ƒ  } | i | ƒ } |  i | | g ƒ |  i | i	 d d ƒ d ƒ |  i ƒ  } | i d g ƒ } |  i | g  ƒ |  i ƒ  } | i g  ƒ } |  i | g  ƒ d  S(   Ns   cfgparser.1s   nonexistant-files   Foo BarR   t   newbar(
   t   test_supportt   findfilet   file1R   R   R   t   readt   parsed_filesR   R   (   R   RZ   RX   R   (    (    R   t   test_read_returns_file_listó   s    c         C   s   |  i d d h  d d <ƒS(   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
R   t   getnames   %(__name__)s(   R   R   (   R   (    (    R   t   get_interpolation_config	  s    	c         C   sQ   |  i d d h  d d <ƒ} t | i d ƒ ƒ } | i ƒ  |  i | | ƒ d  S(   NsY   [section]
name = value
key: |%(name)s| 
getdefault: |%(default)s|
getname: |%(__name__)s|R   t   defaults	   <default>R)   (	   R   R   R   t   listt   itemsR   R   R   t   expected(   R   Ra   R   R   (    (    R   t   check_items_config%  s
    	
(   R   R?   R   R   R   R    R.   R2   R6   R3   R<   R:   RE   RG   RK   RT   R[   R]   Rb   (    (    (    R   R       s    	=	#	
											t   ConfigParserTestCasec           B   s5   t  Z e i Z d „  Z d „  Z d „  Z d „  Z RS(   Nc         C   s“   |  i ƒ  } |  i } | | i d d ƒ d ƒ | | i d d ƒ d ƒ | | i d d ƒ d ƒ | | i d d ƒ d ƒ |  i t i d d	 ƒ d  S(
   NR1   R\   R   s%   something with interpolation (1 step)t   bar9s.   something with lots of interpolation (9 steps)t   bar10s/   something with lots of interpolation (10 steps)t   bar11(	   R   R]   R   R   R   R   R:   R   t   InterpolationDepthError(   R   R   R   (    (    R   t   test_interpolation5  s    	c         C   sa   |  i ƒ  } |  i t i d d ƒ } |  i | i d ƒ |  i | i	 d ƒ |  i | i
 d ƒ d  S(   Ns   Interpolation Errort   namet	   reference(   R   R]   R   R:   R   t   InterpolationErrorR=   R   Rj   R)   R&   (   R   R=   R   (    (    R   t    test_interpolation_missing_value@  s    c         C   s    |  i d d d d d g ƒ d  S(   NR^   s	   <default>t
   getdefaults   |<default>|R\   s	   |section|R(   s   |value|Ri   R   (   s   defaults	   <default>(   Rm   s   |<default>|(   s   getnames	   |section|(   s   keys   |value|(   s   names   value(   R   Rb   (   R   (    (    R   t
   test_itemsH  s    c         C   sÇ  |  i ƒ  } | i d ƒ | i d d d ƒ | i d d d d d d d d d	 d
 d g	 ƒ | i d d h  d d <d d <d d <ƒ | i d d d ƒ |  i | i d d d t ƒd ƒ |  i t	 | i d d ƒ |  i | i d d d t ƒd d d d d d d	 d
 d g	 ƒ |  i t	 | i d d ƒ |  i | i d d d t ƒh  d d <d d <d d <ƒ |  i t	 | i d d ƒ |  i | i d d d t ƒd ƒ |  i t
 | i d d d t ƒd  S(   Ns
   non-stringt   inti   R_   i    i   i   i   i   i   s   %(t   dictt   pif3.1415899999999999s   %(list)t   string_with_interpolations   %(list)st   raw(   R   R   R   R+   R,   R   R   t   TrueR   t	   TypeErrorRD   t   False(   R   R   (    (    R   t   test_set_nonstring_typesO  s&    .."""	 (   R   R?   R   R   Rh   Rl   Rn   Rw   (    (    (    R   Rc   2  s
   				t   RawConfigParserTestCasec           B   s,   t  Z e i Z d „  Z d „  Z d „  Z RS(   Nc         C   s–   |  i ƒ  } |  i } | | i d d ƒ d ƒ | | i d d ƒ d ƒ | | i d d ƒ d ƒ | | i d d ƒ d	 ƒ | | i d d
 ƒ d ƒ d  S(   NR1   R\   s   %(__name__)sR   s*   something %(with1)s interpolation (1 step)Rd   s3   something %(with9)s lots of interpolation (9 steps)Re   s5   something %(with10)s lots of interpolation (10 steps)Rf   s5   something %(with11)s lots of interpolation (11 steps)(   R   R]   R   R   R   R   (   R   R   R   (    (    R   Rh   h  s    	c         C   s    |  i d d d d d g ƒ d  S(   NR^   s	   <default>Rm   s   |%(default)s|R\   s   |%(__name__)s|R(   s
   |%(name)s|Ri   R   (   s   defaults	   <default>(   s
   getdefaults   |%(default)s|(   s   getnames   |%(__name__)s|(   s   keys
   |%(name)s|(   s   names   value(   R   Rb   (   R   (    (    R   Rn   u  s    c         C   sì   |  i ƒ  } | i d ƒ | i d d d ƒ | i d d d d d d d d d	 d
 g ƒ | i d d h  d d <ƒ |  i | i d d ƒ d ƒ |  i | i d d ƒ d d d d d d d	 d
 g ƒ |  i | i d d ƒ h  d d <ƒ d  S(   Ns
   non-stringRo   i   R_   i    i   i   i   i   i   Rp   Rq   f3.1415899999999999(   R   R   R   R+   R,   R   R   (   R   R   (    (    R   Rw   |  s    +(   R   R?   R   t   RawConfigParserR   Rh   Rn   Rw   (    (    (    R   Rx   e  s   			t   SafeConfigParserTestCasec           B   s#   t  Z e i Z d „  Z d „  Z RS(   Nc         C   sK   |  i d ƒ } |  i | i d d ƒ d ƒ |  i | i d d ƒ d ƒ d  S(   NsW   [section]
option1=xxx
option2=%(option1)s/xxx
ok=%(option1)s/%%s
not_ok=%(option2)s/%%sR)   t   oks   xxx/%st   not_oks
   xxx/xxx/%s(   R   R   R   R   R   (   R   R   (    (    R   t   test_safe_interpolation‹  s    c         C   sÁ   |  i d ƒ } |  i t | i d d d ƒ |  i t | i d d d ƒ |  i t | i d d t ƒ  ƒ |  i t | i d d d ƒ |  i t | i d d d ƒ |  i t | i d d t ƒ  ƒ d  S(   Ns   [sect]
option1=foo
RM   RN   i   f1.0RP   (   R   R   R   R   Ru   R,   t   object(   R   R   (    (    R   Rw   •  s    (   R   R?   R   t   SafeConfigParserR   R}   Rw   (    (    (    R   Rz   ˆ  s   		
c           C   s   t  i t t t ƒ d  S(   N(   RV   t   run_unittestRc   Rx   Rz   (    (    (    R   t	   test_main¢  s    	t   __main__(   R   R   t   unittestt   testRV   t   TestCaseR    Rc   Rx   Rz   R   R   (	   RV   R    R   Rƒ   Rz   Rx   Rc   R   R   (    (    R   t   ?   s   			ÿ +3#	