if self._defaults:
self._write_section(fp, self.default_section,
self._defaults.items(), d)
- if UNNAMED_SECTION in self._sections:
+ if UNNAMED_SECTION in self._sections and self._sections[UNNAMED_SECTION]:
self._write_section(fp, UNNAMED_SECTION, self._sections[UNNAMED_SECTION].items(), d, unnamed=True)
for section in self._sections:
self.assertEqual('1', cfg2[configparser.UNNAMED_SECTION]['a'])
self.assertEqual('2', cfg2[configparser.UNNAMED_SECTION]['b'])
+ def test_empty_unnamed_section(self):
+ cfg = configparser.ConfigParser(allow_unnamed_section=True)
+ cfg.add_section(configparser.UNNAMED_SECTION)
+ cfg.add_section('section')
+ output = io.StringIO()
+ cfg.write(output)
+ self.assertEqual(output.getvalue(), '[section]\n\n')
+
def test_add_section(self):
cfg = configparser.ConfigParser(allow_unnamed_section=True)
cfg.add_section(configparser.UNNAMED_SECTION)