mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-123049: configparser: Allow to create the unnamed section from scratch. (#123077)
--------- Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
c15bfa9a71
commit
be257c5815
4 changed files with 52 additions and 13 deletions
|
@ -2161,6 +2161,19 @@ class SectionlessTestCase(unittest.TestCase):
|
|||
self.assertEqual('1', cfg2[configparser.UNNAMED_SECTION]['a'])
|
||||
self.assertEqual('2', cfg2[configparser.UNNAMED_SECTION]['b'])
|
||||
|
||||
def test_add_section(self):
|
||||
cfg = configparser.ConfigParser(allow_unnamed_section=True)
|
||||
cfg.add_section(configparser.UNNAMED_SECTION)
|
||||
cfg.set(configparser.UNNAMED_SECTION, 'a', '1')
|
||||
self.assertEqual('1', cfg[configparser.UNNAMED_SECTION]['a'])
|
||||
|
||||
def test_disabled_error(self):
|
||||
with self.assertRaises(configparser.MissingSectionHeaderError):
|
||||
configparser.ConfigParser().read_string("a = 1")
|
||||
|
||||
with self.assertRaises(configparser.UnnamedSectionDisabledError):
|
||||
configparser.ConfigParser().add_section(configparser.UNNAMED_SECTION)
|
||||
|
||||
|
||||
class MiscTestCase(unittest.TestCase):
|
||||
def test__all__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue