<s> import ConfigParser <EOL> import StringIO <EOL> import os <EOL> import unittest <EOL> import UserDict <EOL> from test import test_support <EOL> class SortedDict ( UserDict . UserDict ) : <EOL> def items ( self ) : <EOL> result = self . data . items ( ) <EOL> result . sort ( ) <EOL> return result <EOL> def keys ( self ) : <EOL> result = self . data . keys ( ) <EOL> result . sort ( ) <EOL> return result <EOL> def values ( self ) : <EOL> result = self . items ( ) <EOL> return [ i [ <NUM_LIT:1> ] for i in result ] <EOL> def iteritems ( self ) : return iter ( self . items ( ) ) <EOL> def iterkeys ( self ) : return iter ( self . keys ( ) ) <EOL> __iter__ = iterkeys <EOL> def itervalues ( self ) : return iter ( self . values ( ) ) <EOL> class TestCaseBase ( unittest . TestCase ) : <EOL> allow_no_value = False <EOL> def newconfig ( self , defaults = None ) : <EOL> if defaults is None : <EOL> self . cf = self . config_class ( allow_no_value = self . allow_no_value ) <EOL> else : <EOL> self . cf = self . config_class ( defaults , <EOL> allow_no_value = self . allow_no_value ) <EOL> return self . cf <EOL> def fromstring ( self , string , defaults = None ) : <EOL> cf = self . newconfig ( defaults ) <EOL> sio = StringIO . StringIO ( string ) <EOL> cf . readfp ( sio ) <EOL> return cf <EOL> def test_basic ( self ) : <EOL> config_string = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> if self . allow_no_value : <EOL> config_string += ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> cf = self . fromstring ( config_string ) <EOL> L = cf . sections ( ) <EOL> L . sort ( ) <EOL> E = [ r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> r'<STR_LIT>' '<STR_LIT:\t>' , <EOL> r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> ] <EOL> if self . allow_no_value : <EOL> E . append ( r'<STR_LIT>' ) <EOL> E . sort ( ) <EOL> eq = self . assertEqual <EOL> eq ( L , E ) <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT:foo>' ) , '<STR_LIT:bar>' ) <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT:foo>' ) , '<STR_LIT:bar>' ) <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT:foo>' ) , '<STR_LIT:bar>' ) <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:value>' ) <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> if self . allow_no_value : <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT>' ) , None ) <EOL> self . assertNotIn ( '<STR_LIT>' , cf . options ( "<STR_LIT>" ) , <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( cf . remove_option ( '<STR_LIT>' , '<STR_LIT:foo>' ) , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( cf . has_option ( '<STR_LIT>' , '<STR_LIT:foo>' ) , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( cf . remove_option ( '<STR_LIT>' , '<STR_LIT:foo>' ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertRaises ( ConfigParser . NoSectionError , <EOL> cf . remove_option , '<STR_LIT>' , '<STR_LIT:foo>' ) <EOL> eq ( cf . get ( '<STR_LIT>' , '<STR_LIT:foo>' ) , <EOL> '<STR_LIT>' ) <EOL> def test_case_sensitivity ( self ) : <EOL> cf = self . newconfig ( ) <EOL> cf . add_section ( "<STR_LIT:A>" ) <EOL> cf . add_section ( "<STR_LIT:a>" ) <EOL> L = cf . sections ( ) <EOL> L . sort ( ) <EOL> eq = self . assertEqual <EOL> eq ( L , [ "<STR_LIT:A>" , "<STR_LIT:a>" ] ) <EOL> cf . set ( "<STR_LIT:a>" , "<STR_LIT:B>" , "<STR_LIT:value>" ) <EOL> eq ( cf . options ( "<STR_LIT:a>" ) , [ "<STR_LIT:b>" ] ) <EOL> eq ( cf . get ( "<STR_LIT:a>" , "<STR_LIT:b>" ) , "<STR_LIT:value>" , <EOL> "<STR_LIT>" ) <EOL> self . assertTrue ( cf . has_option ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) <EOL> cf . set ( "<STR_LIT:A>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> for opt in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . assertTrue ( <EOL> cf . has_option ( "<STR_LIT:A>" , opt ) , <EOL> "<STR_LIT>" ) <EOL> eq ( cf . options ( "<STR_LIT:A>" ) , [ "<STR_LIT>" ] ) <EOL> eq ( cf . options ( "<STR_LIT:a>" ) , [ "<STR_LIT:b>" ] ) <EOL> cf . remove_option ( "<STR_LIT:a>" , "<STR_LIT:B>" ) <EOL> eq ( cf . options ( "<STR_LIT:a>" ) , [ ] ) <EOL> cf = self . fromstring ( <EOL> "<STR_LIT>" ) <EOL> eq ( cf . options ( "<STR_LIT>" ) , [ "<STR_LIT>" ] ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> cf = self . fromstring ( "<STR_LIT>" , <EOL> defaults = { "<STR_LIT:key>" : "<STR_LIT:value>" } ) <EOL> self . assertTrue ( cf . has_option ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> def test_default_case_sensitivity ( self ) : <EOL> cf = self . newconfig ( { "<STR_LIT:foo>" : "<STR_LIT>" } ) <EOL> self . assertEqual ( <EOL> cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> cf = self . newconfig ( { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertEqual ( <EOL> cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> def test_parse_errors ( self ) : <EOL> self . newconfig ( ) <EOL> self . parse_error ( ConfigParser . ParsingError , <EOL> "<STR_LIT>" ) <EOL> self . parse_error ( ConfigParser . ParsingError , <EOL> "<STR_LIT>" ) <EOL> self . parse_error ( ConfigParser . ParsingError , <EOL> "<STR_LIT>" ) <EOL> self . parse_error ( ConfigParser . ParsingError , <EOL> "<STR_LIT>" ) <EOL> self . parse_error ( ConfigParser . MissingSectionHeaderError , <EOL> "<STR_LIT>" ) <EOL> def parse_error ( self , exc , src ) : <EOL> sio = StringIO . StringIO ( src ) <EOL> self . assertRaises ( exc , self . cf . readfp , sio ) <EOL> def test_query_errors ( self ) : <EOL> cf = self . newconfig ( ) <EOL> self . assertEqual ( cf . sections ( ) , [ ] , <EOL> "<STR_LIT>" ) <EOL> self . assertFalse ( cf . has_section ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertRaises ( ConfigParser . NoSectionError , <EOL> cf . options , "<STR_LIT>" ) <EOL> self . assertRaises ( ConfigParser . NoSectionError , <EOL> cf . set , "<STR_LIT:foo>" , "<STR_LIT:bar>" , "<STR_LIT:value>" ) <EOL> self . get_error ( ConfigParser . NoSectionError , "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> cf . add_section ( "<STR_LIT:foo>" ) <EOL> self . get_error ( ConfigParser . NoOptionError , "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> def get_error ( self , exc , section , option ) : <EOL> try : <EOL> self . cf . get ( section , option ) <EOL> except exc , e : <EOL> return e <EOL> else : <EOL> self . fail ( "<STR_LIT>" <EOL> % ( exc . __module__ , exc . __name__ ) ) <EOL> def test_boolean ( self ) : <EOL> cf = self . fromstring ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> for x in range ( <NUM_LIT:1> , <NUM_LIT:5> ) : <EOL> self . assertTrue ( cf . getboolean ( '<STR_LIT>' , '<STR_LIT>' % x ) ) <EOL> self . assertFalse ( cf . getboolean ( '<STR_LIT>' , '<STR_LIT>' % x ) ) <EOL> self . assertRaises ( ValueError , <EOL> cf . getboolean , '<STR_LIT>' , '<STR_LIT>' % x ) <EOL> def test_weird_errors ( self ) : <EOL> cf = self . newconfig ( ) <EOL> cf . add_section ( "<STR_LIT>" ) <EOL> self . assertRaises ( ConfigParser . DuplicateSectionError , <EOL> cf . add_section , "<STR_LIT>" ) <EOL> def test_write ( self ) : <EOL> config_string = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> if self . allow_no_value : <EOL> config_string += ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> cf = self . fromstring ( config_string ) <EOL> output = StringIO . StringIO ( ) <EOL> cf . write ( output ) <EOL> expect_string = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" <EOL> ) <EOL> if self . allow_no_value : <EOL> expect_string += ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" <EOL> ) <EOL> self . assertEqual ( output . getvalue ( ) , expect_string ) <EOL> def test_set_string_types ( self ) : <EOL> cf = self . fromstring ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class mystr ( str ) : <EOL> pass <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , mystr ( "<STR_LIT>" ) ) <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , mystr ( "<STR_LIT>" ) ) <EOL> try : <EOL> unicode <EOL> except NameError : <EOL> pass <EOL> else : <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , unicode ( "<STR_LIT>" ) ) <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , unicode ( "<STR_LIT>" ) ) <EOL> def test_read_returns_file_list ( self ) : <EOL> file1 = test_support . findfile ( "<STR_LIT>" ) <EOL> cf = self . newconfig ( ) <EOL> parsed_files = cf . read ( [ file1 , "<STR_LIT>" ] ) <EOL> self . assertEqual ( parsed_files , [ file1 ] ) <EOL> self . assertEqual ( cf . get ( "<STR_LIT>" , "<STR_LIT:foo>" ) , "<STR_LIT>" ) <EOL> cf = self . newconfig ( ) <EOL> parsed_files = cf . read ( file1 ) <EOL> self . assertEqual ( parsed_files , [ file1 ] ) <EOL> self . assertEqual ( cf . get ( "<STR_LIT>" , "<STR_LIT:foo>" ) , "<STR_LIT>" ) <EOL> cf = self . newconfig ( ) <EOL> parsed_files = cf . read ( [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( parsed_files , [ ] ) <EOL> cf = self . newconfig ( ) <EOL> parsed_files = cf . read ( [ ] ) <EOL> self . assertEqual ( parsed_files , [ ] ) <EOL> def get_interpolation_config ( self ) : <EOL> return self . fromstring ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:\n>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> defaults = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> def check_items_config ( self , expected ) : <EOL> cf = self . fromstring ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> defaults = { "<STR_LIT:default>" : "<STR_LIT>" } ) <EOL> L = list ( cf . items ( "<STR_LIT>" ) ) <EOL> L . sort ( ) <EOL> self . assertEqual ( L , expected ) <EOL> class ConfigParserTestCase ( TestCaseBase ) : <EOL> config_class = ConfigParser . ConfigParser <EOL> allow_no_value = True <EOL> def test_interpolation ( self ) : <EOL> rawval = { <EOL> ConfigParser . ConfigParser : ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ConfigParser . SafeConfigParser : "<STR_LIT>" , <EOL> } <EOL> cf = self . get_interpolation_config ( ) <EOL> eq = self . assertEqual <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT:bar>" ) , "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> self . get_error ( ConfigParser . InterpolationDepthError , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_interpolation_missing_value ( self ) : <EOL> self . get_interpolation_config ( ) <EOL> e = self . get_error ( ConfigParser . InterpolationError , <EOL> "<STR_LIT>" , "<STR_LIT:name>" ) <EOL> self . assertEqual ( e . reference , "<STR_LIT>" ) <EOL> self . assertEqual ( e . section , "<STR_LIT>" ) <EOL> self . assertEqual ( e . option , "<STR_LIT:name>" ) <EOL> def test_items ( self ) : <EOL> self . check_items_config ( [ ( '<STR_LIT:default>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:key>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT:value>' ) ] ) <EOL> def test_set_nonstring_types ( self ) : <EOL> cf = self . newconfig ( ) <EOL> cf . add_section ( '<STR_LIT>' ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT:int>' , <NUM_LIT:1> ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT:list>' , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT> , '<STR_LIT>' ] ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT:int>' , raw = True ) , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , cf . get , '<STR_LIT>' , '<STR_LIT:int>' ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT:list>' , raw = True ) , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT> , '<STR_LIT>' ] ) <EOL> self . assertRaises ( TypeError , cf . get , '<STR_LIT>' , '<STR_LIT:list>' ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT>' , raw = True ) , <EOL> { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRaises ( TypeError , cf . get , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT>' , <EOL> raw = True ) , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , cf . get , '<STR_LIT>' , <EOL> '<STR_LIT>' , raw = False ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT>' ) , None ) <EOL> class MultilineValuesTestCase ( TestCaseBase ) : <EOL> config_class = ConfigParser . ConfigParser <EOL> wonderful_spam = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> cf = self . newconfig ( ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> s = '<STR_LIT>' . format ( i ) <EOL> cf . add_section ( s ) <EOL> for j in range ( <NUM_LIT:10> ) : <EOL> cf . set ( s , '<STR_LIT>' . format ( j ) , self . wonderful_spam ) <EOL> with open ( test_support . TESTFN , '<STR_LIT:w>' ) as f : <EOL> cf . write ( f ) <EOL> def tearDown ( self ) : <EOL> os . unlink ( test_support . TESTFN ) <EOL> def test_dominating_multiline_values ( self ) : <EOL> cf_from_file = self . newconfig ( ) <EOL> with open ( test_support . TESTFN ) as f : <EOL> cf_from_file . readfp ( f ) <EOL> self . assertEqual ( cf_from_file . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> self . wonderful_spam . replace ( '<STR_LIT>' , '<STR_LIT:\n>' ) ) <EOL> class RawConfigParserTestCase ( TestCaseBase ) : <EOL> config_class = ConfigParser . RawConfigParser <EOL> def test_interpolation ( self ) : <EOL> cf = self . get_interpolation_config ( ) <EOL> eq = self . assertEqual <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT:bar>" ) , <EOL> "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> eq ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> def test_items ( self ) : <EOL> self . check_items_config ( [ ( '<STR_LIT:default>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:key>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT:value>' ) ] ) <EOL> def test_set_nonstring_types ( self ) : <EOL> cf = self . newconfig ( ) <EOL> cf . add_section ( '<STR_LIT>' ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT:int>' , <NUM_LIT:1> ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT:list>' , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT> ] ) <EOL> cf . set ( '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT:int>' ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT:list>' ) , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT> ] ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , '<STR_LIT>' ) , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> class SafeConfigParserTestCase ( ConfigParserTestCase ) : <EOL> config_class = ConfigParser . SafeConfigParser <EOL> def test_safe_interpolation ( self ) : <EOL> cf = self . fromstring ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> self . assertEqual ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def test_set_malformatted_interpolation ( self ) : <EOL> cf = self . fromstring ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , "<STR_LIT>" ) , "<STR_LIT:foo>" ) <EOL> self . assertRaises ( ValueError , cf . set , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , cf . set , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , cf . set , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEqual ( cf . get ( '<STR_LIT>' , "<STR_LIT>" ) , "<STR_LIT:foo>" ) <EOL> cf . set ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . assertEqual ( cf . get ( "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def test_set_nonstring_types ( self ) : <EOL> cf = self . fromstring ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , cf . set , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , cf . set , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1.0> ) <EOL> self . assertRaises ( TypeError , cf . set , "<STR_LIT>" , "<STR_LIT>" , object ( ) ) <EOL> self . assertRaises ( TypeError , cf . set , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , cf . set , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1.0> ) <EOL> self . assertRaises ( TypeError , cf . set , "<STR_LIT>" , "<STR_LIT>" , object ( ) ) <EOL> def test_add_section_default_1 ( self ) : <EOL> cf = self . newconfig ( ) <EOL> self . assertRaises ( ValueError , cf . add_section , "<STR_LIT:default>" ) <EOL> def test_add_section_default_2 ( self ) : <EOL> cf = self . newconfig ( ) <EOL> self . assertRaises ( ValueError , cf . add_section , "<STR_LIT>" ) <EOL> class SafeConfigParserTestCaseNoValue ( SafeConfigParserTestCase ) : <EOL> allow_no_value = True <EOL> class TestChainMap ( unittest . TestCase ) : <EOL> def test_issue_12717 ( self ) : <EOL> d1 = dict ( red = <NUM_LIT:1> , green = <NUM_LIT:2> ) <EOL> d2 = dict ( green = <NUM_LIT:3> , blue = <NUM_LIT:4> ) <EOL> dcomb = d2 . copy ( ) <EOL> dcomb . update ( d1 ) <EOL> cm = ConfigParser . _Chainmap ( d1 , d2 ) <EOL> self . assertIsInstance ( cm . keys ( ) , list ) <EOL> self . assertEqual ( set ( cm . keys ( ) ) , set ( dcomb . keys ( ) ) ) <EOL> self . assertEqual ( set ( cm . values ( ) ) , set ( dcomb . values ( ) ) ) <EOL> self . assertEqual ( set ( cm . items ( ) ) , set ( dcomb . items ( ) ) ) <EOL> self . assertEqual ( set ( cm ) , set ( dcomb ) ) <EOL> self . assertEqual ( cm , dcomb ) <EOL> self . assertEqual ( [ cm [ k ] for k in dcomb ] , dcomb . values ( ) ) <EOL> klist = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( [ cm . get ( k , <NUM_LIT:10> ) for k in klist ] , <EOL> [ dcomb . get ( k , <NUM_LIT:10> ) for k in klist ] ) <EOL> self . assertEqual ( [ k in cm for k in klist ] , <EOL> [ k in dcomb for k in klist ] ) <EOL> with test_support . check_py3k_warnings ( ) : <EOL> self . assertEqual ( [ cm . has_key ( k ) for k in klist ] , <EOL> [ dcomb . has_key ( k ) for k in klist ] ) <EOL> class Issue7005TestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> expected_output = "<STR_LIT>" <EOL> def prepare ( self , config_class ) : <EOL> cp = config_class ( allow_no_value = False ) <EOL> cp . add_section ( "<STR_LIT>" ) <EOL> cp . set ( "<STR_LIT>" , "<STR_LIT>" , None ) <EOL> sio = StringIO . StringIO ( ) <EOL> cp . write ( sio ) <EOL> return sio . getvalue ( ) <EOL> def test_none_as_value_stringified ( self ) : <EOL> output = self . prepare ( ConfigParser . ConfigParser ) <EOL> self . assertEqual ( output , self . expected_output ) <EOL> def test_none_as_value_stringified_raw ( self ) : <EOL> output = self . prepare ( ConfigParser . RawConfigParser ) <EOL> self . assertEqual ( output , self . expected_output ) <EOL> class SortedTestCase ( RawConfigParserTestCase ) : <EOL> def newconfig ( self , defaults = None ) : <EOL> self . cf = self . config_class ( defaults = defaults , dict_type = SortedDict ) <EOL> return self . cf <EOL> def test_sorted ( self ) : <EOL> self . fromstring ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> output = StringIO . StringIO ( ) <EOL> self . cf . write ( output ) <EOL> self . assertEqual ( output . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class ExceptionPicklingTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_error ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . Error ( '<STR_LIT:value>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_nosectionerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . NoSectionError ( '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_nooptionerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . NoOptionError ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( e1 . option , e2 . option ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_duplicatesectionerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . DuplicateSectionError ( '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_interpolationerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . InterpolationError ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( e1 . option , e2 . option ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_interpolationmissingoptionerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . InterpolationMissingOptionError ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( e1 . option , e2 . option ) <EOL> self . assertEqual ( e1 . reference , e2 . reference ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_interpolationsyntaxerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . InterpolationSyntaxError ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( e1 . option , e2 . option ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_interpolationdeptherror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . InterpolationDepthError ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . section , e2 . section ) <EOL> self . assertEqual ( e1 . option , e2 . option ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_parsingerror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . ParsingError ( '<STR_LIT:source>' ) <EOL> e1 . append ( <NUM_LIT:1> , '<STR_LIT>' ) <EOL> e1 . append ( <NUM_LIT:2> , '<STR_LIT>' ) <EOL> e1 . append ( <NUM_LIT:3> , '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . filename , e2 . filename ) <EOL> self . assertEqual ( e1 . errors , e2 . errors ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_missingsectionheadererror ( self ) : <EOL> import pickle <EOL> e1 = ConfigParser . MissingSectionHeaderError ( '<STR_LIT:filename>' , <NUM_LIT> , '<STR_LIT>' ) <EOL> pickled = pickle . dumps ( e1 ) <EOL> e2 = pickle . loads ( pickled ) <EOL> self . assertEqual ( e1 . message , e2 . message ) <EOL> self . assertEqual ( e1 . args , e2 . args ) <EOL> self . assertEqual ( e1 . line , e2 . line ) <EOL> self . assertEqual ( e1 . filename , e2 . filename ) <EOL> self . assertEqual ( e1 . lineno , e2 . lineno ) <EOL> self . assertEqual ( repr ( e1 ) , repr ( e2 ) ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( <EOL> ConfigParserTestCase , <EOL> MultilineValuesTestCase , <EOL> RawConfigParserTestCase , <EOL> SafeConfigParserTestCase , <EOL> SafeConfigParserTestCaseNoValue , <EOL> SortedTestCase , <EOL> Issue7005TestCase , <EOL> TestChainMap , <EOL> ExceptionPicklingTestCase , <EOL> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
