Exemplo n.º 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
""")
Exemplo n.º 2
0
 def test_set_get_dict(self):
     cfg = SimplerConfig()
     cfg.level1 = {'a': 1, 'b': 2}
     self.assertEqual(cfg.level1.a, 1)
     self.assertEqual(cfg.level1.b, 2)
     self.assertDictEqual({'level1': cfg.level1}, {**cfg})
Exemplo n.º 3
0
 def test_set_attr(self):
     cfg = SimplerConfig()
     cfg.level1 = "new val"
     self.assertEqual(cfg.level1, "new val")