"""
elements_added = set()
for section, keys in dictionary.items():
- section = str(section)
+ if section is not UNNAMED_SECTION:
+ section = str(section)
try:
self.add_section(section)
except (DuplicateSectionError, ValueError):
cfg.add_section(configparser.UNNAMED_SECTION)
cfg.set(configparser.UNNAMED_SECTION, 'a', '1')
self.assertEqual('1', cfg[configparser.UNNAMED_SECTION]['a'])
+ output = io.StringIO()
+ cfg.write(output)
+ self.assertEqual(output.getvalue(), 'a = 1\n\n')
+
+ cfg = configparser.ConfigParser(allow_unnamed_section=True)
+ cfg[configparser.UNNAMED_SECTION] = {'a': '1'}
+ self.assertEqual('1', cfg[configparser.UNNAMED_SECTION]['a'])
+ output = io.StringIO()
+ cfg.write(output)
+ self.assertEqual(output.getvalue(), 'a = 1\n\n')
def test_disabled_error(self):
with self.assertRaises(configparser.MissingSectionHeaderError):
with self.assertRaises(configparser.UnnamedSectionDisabledError):
configparser.ConfigParser().add_section(configparser.UNNAMED_SECTION)
+ with self.assertRaises(configparser.UnnamedSectionDisabledError):
+ configparser.ConfigParser()[configparser.UNNAMED_SECTION] = {'a': '1'}
+
def test_multiple_configs(self):
cfg = configparser.ConfigParser(allow_unnamed_section=True)
cfg.read_string('a = 1')