def test_allow_to_modify_only_added_parameters(self):
        cfg = AS.Cfg()
        cfg.add("aster-version", AS.Line("version", "10.0"))
        self.assertEqual(cfg["aster-version"].value, "10.0")

        self.assertRaises(KeyError, cfg.__getitem__, "proc-nb")
        cfg.add("proc-nb", AS.Line("ncpus"))
        cfg["proc-nb"].value = 5
        self.assertEqual(cfg["proc-nb"].value, 5)
    def test_remove_a_parameter_from_many(self):
        cfg = AS.Cfg()
        for key in ["a", "b", "c"]:
            cfg.add(key, AS.Line(key))
        lines = cfg.lines()

        cfg.remove("c")

        self.assertEqual(cfg.lines(), [lines[0], lines[1]])
    def test_copy_configuration_objects(self):
        copy = AS.Line("v", 128).copy()
        self.assertEqual(copy._key, "v")
        self.assertEqual(copy.value, 128)

        copy = AS.FileLine("comm", 20, "f").copy()
        self.assertEqual(copy._key, "comm")
        self.assertEqual(copy._idx, 20)
        self.assertEqual(copy.fname, "f")
    def test_remove_a_parameter(self):
        cfg = AS.Cfg()
        cfg.add("p", AS.Line("proc"))
        self.assert_(cfg["p"].value is None)

        cfg.remove("p")
        try:
            val = cfg["p"]
            self.fail()
        except KeyError, exc:
            self.assertEqual(exc.args[0], AS.Cfg._mess % "p")
 def test_allow_to_add_only_one_time(self):
     cfg = AS.Cfg()
     cfg.add("a", AS.Line("a"))
     self.assertRaises(KeyError, cfg.add, "a", AS.Line("a"))