@@ -44,7 +44,7 @@ class CfgParserTestCaseClass:
4444 default_section = configparser .DEFAULTSECT
4545 interpolation = configparser ._UNSET
4646
47- def newconfig (self , defaults = None ):
47+ def newconfig (self , defaults = None , ** kwargs ):
4848 arguments = dict (
4949 defaults = defaults ,
5050 allow_no_value = self .allow_no_value ,
@@ -57,6 +57,7 @@ def newconfig(self, defaults=None):
5757 default_section = self .default_section ,
5858 interpolation = self .interpolation ,
5959 )
60+ arguments .update (kwargs )
6061 instance = self .config_class (** arguments )
6162 return instance
6263
@@ -359,6 +360,32 @@ def test_basic(self):
359360 the larch {0[1]} 1
360361 """ .format (self .delimiters )))
361362
363+ @support .subTests ('data' , [
364+ 'foo bar=baz' ,
365+ 'foo bar=baz' ,
366+ 'foo=bar=baz' ,
367+ 'foo = bar=baz' ,
368+ 'foo\t \t =\t \t bar=baz' ,
369+ ])
370+ def test_space_delimiter (self , data ):
371+ # gh-156353: Space should be accepted as a delimiter
372+ cf = self .newconfig (delimiters = (' ' , '=' ))
373+ cf .read_string (f"[all]\n { data } " )
374+ self .assertEqual (cf .options ('all' ), ['foo' ])
375+ self .assertEqual (cf .get ('all' , 'foo' ), 'bar=baz' )
376+
377+ @support .subTests ('delimiter' , ' =:;#x\t \0 \N{RS} \N{CEDILLA} \N{CAT} ' )
378+ @support .subTests ('space_before' , ['' , ' ' , '\t ' , ' \t ' ])
379+ @support .subTests ('space_after' , ['' , ' ' , '\t ' , ' \t ' ])
380+ def test_any_delimiter (self , delimiter , space_before , space_after ):
381+ cf = self .newconfig (
382+ delimiters = (delimiter ,),
383+ inline_comment_prefixes = None ,
384+ )
385+ cf .read_string (f"[all]\n foo{ space_before } { delimiter } { space_after } bar=baz" )
386+ self .assertEqual (cf .options ('all' ), ['foo' ])
387+ self .assertEqual (cf .get ('all' , 'foo' ), 'bar=baz' )
388+
362389 def test_basic_from_dict (self ):
363390 config = {
364391 "Foo Bar" : {
@@ -1956,8 +1983,8 @@ class ConvertersTestCase(BasicTestCase, unittest.TestCase):
19561983
19571984 config_class = configparser .ConfigParser
19581985
1959- def newconfig (self , defaults = None ):
1960- instance = super ().newconfig (defaults = defaults )
1986+ def newconfig (self , defaults = None , ** kwargs ):
1987+ instance = super ().newconfig (defaults = defaults , ** kwargs )
19611988 instance .converters ['list' ] = lambda v : [e .strip () for e in v .split ()
19621989 if e .strip ()]
19631990 return instance
0 commit comments