1+ import collections
12import configparser
23import io
4+ import os
35import unittest
4- import collections
56
67from test import support
78
@@ -162,7 +163,7 @@ def test_default_case_sensitivity(self):
162163 def test_parse_errors (self ):
163164 self .newconfig ()
164165 e = self .parse_error (configparser .ParsingError ,
165- "[Foo]\n extra-spaces: splat\n " )
166+ "[Foo]\n extra-spaces: splat\n " )
166167 self .assertEqual (e .args , ('<???>' ,))
167168 self .parse_error (configparser .ParsingError ,
168169 "[Foo]\n extra-spaces= splat\n " )
@@ -171,7 +172,7 @@ def test_parse_errors(self):
171172 self .parse_error (configparser .ParsingError ,
172173 "[Foo]\n =value-without-option-name\n " )
173174 e = self .parse_error (configparser .MissingSectionHeaderError ,
174- "No Section!\n " )
175+ "No Section!\n " )
175176 self .assertEqual (e .args , ('<???>' , 1 , "No Section!\n " ))
176177
177178 def parse_error (self , exc , src ):
@@ -185,7 +186,8 @@ def test_query_errors(self):
185186 self .assertEqual (cf .sections (), [],
186187 "new ConfigParser should have no defined sections" )
187188 self .assertFalse (cf .has_section ("Foo" ),
188- "new ConfigParser should have no acknowledged sections" )
189+ "new ConfigParser should have no acknowledged "
190+ "sections" )
189191 with self .assertRaises (configparser .NoSectionError ) as cm :
190192 cf .options ("Foo" )
191193 with self .assertRaises (configparser .NoSectionError ) as cm :
@@ -355,8 +357,8 @@ class ConfigParserTestCase(TestCaseBase):
355357
356358 def test_interpolation (self ):
357359 rawval = {
358- configparser .ConfigParser : "something %(with11)s " \
359- "lots of interpolation (11 steps)" ,
360+ configparser .ConfigParser : ( "something %(with11)s "
361+ "lots of interpolation (11 steps)" ) ,
360362 configparser .SafeConfigParser : "%(with1)s" ,
361363 }
362364 cf = self .get_interpolation_config ()
@@ -412,6 +414,33 @@ def test_set_nonstring_types(self):
412414 self .assertRaises (ValueError , cf .get , 'non-string' ,
413415 'string_with_interpolation' , raw = False )
414416
417+ class MultilineValuesTestCase (TestCaseBase ):
418+ config_class = configparser .ConfigParser
419+ wonderful_spam = ("I'm having spam spam spam spam "
420+ "spam spam spam beaked beans spam "
421+ "spam spam and spam!" ).replace (' ' , '\t \n ' )
422+
423+ def setUp (self ):
424+ cf = self .newconfig ()
425+ for i in range (100 ):
426+ s = 'section{}' .format (i )
427+ cf .add_section (s )
428+ for j in range (10 ):
429+ cf .set (s , 'lovely_spam{}' .format (j ), self .wonderful_spam )
430+ with open (support .TESTFN , 'w' ) as f :
431+ cf .write (f )
432+
433+ def tearDown (self ):
434+ os .unlink (support .TESTFN )
435+
436+ def test_dominating_multiline_values (self ):
437+ # We're reading from file because this is where the code changed
438+ # during performance updates in Python 3.2
439+ cf_from_file = self .newconfig ()
440+ with open (support .TESTFN ) as f :
441+ cf_from_file .readfp (f )
442+ self .assertEqual (cf_from_file .get ('section8' , 'lovely_spam4' ),
443+ self .wonderful_spam .replace ('\t \n ' , '\n ' ))
415444
416445class RawConfigParserTestCase (TestCaseBase ):
417446 config_class = configparser .RawConfigParser
@@ -530,10 +559,11 @@ def test_sorted(self):
530559def test_main ():
531560 support .run_unittest (
532561 ConfigParserTestCase ,
562+ MultilineValuesTestCase ,
533563 RawConfigParserTestCase ,
534564 SafeConfigParserTestCase ,
535- SortedTestCase ,
536565 SafeConfigParserTestCaseNoValue ,
566+ SortedTestCase ,
537567 )
538568
539569
0 commit comments