@@ -45,7 +45,7 @@ class CfgParserTestCaseClass:
4545 default_section = configparser .DEFAULTSECT
4646 interpolation = configparser ._UNSET
4747
48- def newconfig (self , defaults = None ):
48+ def newconfig (self , defaults = None , ** kwargs ):
4949 arguments = dict (
5050 defaults = defaults ,
5151 allow_no_value = self .allow_no_value ,
@@ -58,6 +58,7 @@ def newconfig(self, defaults=None):
5858 default_section = self .default_section ,
5959 interpolation = self .interpolation ,
6060 )
61+ arguments .update (kwargs )
6162 instance = self .config_class (** arguments )
6263 return instance
6364
@@ -360,6 +361,32 @@ def test_basic(self):
360361 the larch {0[1]} 1
361362 """ .format (self .delimiters )))
362363
364+ @support .subTests ('data' , [
365+ 'foo bar=baz' ,
366+ 'foo bar=baz' ,
367+ 'foo=bar=baz' ,
368+ 'foo = bar=baz' ,
369+ 'foo\t \t =\t \t bar=baz' ,
370+ ])
371+ def test_space_delimiter (self , data ):
372+ # gh-156353: Space should be accepted as a delimiter
373+ cf = self .newconfig (delimiters = (' ' , '=' ))
374+ cf .read_string (f"[all]\n { data } " )
375+ self .assertEqual (cf .options ('all' ), ['foo' ])
376+ self .assertEqual (cf .get ('all' , 'foo' ), 'bar=baz' )
377+
378+ @support .subTests ('delimiter' , ' =:;#x\t \0 \N{RS} \N{CEDILLA} \N{CAT} ' )
379+ @support .subTests ('space_before' , ['' , ' ' , '\t ' , ' \t ' ])
380+ @support .subTests ('space_after' , ['' , ' ' , '\t ' , ' \t ' ])
381+ def test_any_delimiter (self , delimiter , space_before , space_after ):
382+ cf = self .newconfig (
383+ delimiters = (delimiter ,),
384+ inline_comment_prefixes = None ,
385+ )
386+ cf .read_string (f"[all]\n foo{ space_before } { delimiter } { space_after } bar=baz" )
387+ self .assertEqual (cf .options ('all' ), ['foo' ])
388+ self .assertEqual (cf .get ('all' , 'foo' ), 'bar=baz' )
389+
363390 def test_basic_from_dict (self ):
364391 config = {
365392 "Foo Bar" : {
@@ -1989,8 +2016,8 @@ class ConvertersTestCase(BasicTestCase, unittest.TestCase):
19892016
19902017 config_class = configparser .ConfigParser
19912018
1992- def newconfig (self , defaults = None ):
1993- instance = super ().newconfig (defaults = defaults )
2019+ def newconfig (self , defaults = None , ** kwargs ):
2020+ instance = super ().newconfig (defaults = defaults , ** kwargs )
19942021 instance .converters ['list' ] = lambda v : [e .strip () for e in v .split ()
19952022 if e .strip ()]
19962023 return instance
0 commit comments