Example #1
0
    def test_dumps(self):
        cfg = SimplerConfig()
        cfg.add_comment("Some comment")
        cfg.level1 = "new val"
        cfg.section1.add_comment("# Left most comment")
        cfg.add_comment("Should be after section 1")
        cfg.section1.item1 = "item 1"
        cfg.section1.add_comment("    # Indented comment")
        cfg.section1.subsection.item2 = "item 2"
        cfg.section2.subsection.item3 = 3
        _ = cfg.empty_section
        cfg.just_item = 5
        cfg.add_comment("Trailing comment")
        res = cfg.dumps()
        self.assertEqual(
            res, """\
# Some comment
level1 = new val
section1:
# Left most comment
    item1 = item 1
    # Indented comment
    subsection:
        item2 = item 2
# Should be after section 1
section2:
    subsection:
        item3 = 3
empty_section:
just_item = 5
# Trailing comment
""")
Example #2
0
    def test_preserve_comments(self):
        file_string = """\
# Some comment
empty_section:
level1 = new val
section1:
# this is a comment for section1.item1:
    item1 = item 1
          # this is another comment
    # Indented comment
    subsection:
        item2 = item 2
# Should be after section 1
section2:
    subsection:
        item3 = 3
very_last = 7
# Trailing comment
"""
        cfg = SimplerConfig()
        cfg.loads(file_string)
        res = cfg.dumps()
        self.assertEqual(file_string, res)