Ejemplo n.º 1
0
 def test_load(self):
     c = Config()
     c.load_writable_config_file(pathWritable, pathRef)
     
     self.assertEqual(c.get("christmas"), "merry Christmas\nand happy new year")
     self.assertEqual(c.get("newyear"), "champagne")
     
     self.assertEqual(c.get("firstint"), 5)
     self.assertEqual(c.get("sndint"), 8)
     
     self.assertEqual(c.get("liststr"), ["one", "two"])
     self.assertEqual(c.get("listint"), [1, 2, 3])
     self.assertEqual(c.get("lls"), [["a", "1"], ["b", "2"], ["c", "2", "ccc"]])
Ejemplo n.º 2
0
    def test_error(self):
        c = Config()
        self.failUnlessRaises(KeyError, lambda:c.set("MAJ", 3))
        self.failUnlessRaises(KeyError, lambda:c.get("MAJ"))

        c.load_writable_config_file(pathWritable, pathRef)
        self.failUnlessRaises(KeyError, lambda:c.get("easter"))
Ejemplo n.º 3
0
 def test_save(self):
     shutil.copy(pathWritable, pathTemp)
     c = Config()
     c.load_writable_config_file(pathTemp, pathRef)
     c.set("firstint", 666)
     c.set("liststr", ["1", "2", "3"])
     c.set("listint", [666, 666])
     c.set("lls", [["A"], ["B", "BETA"], ["C", "CETA", "3"]])
     c.save()
     c = Config()
     c.load_writable_config_file(pathTemp, pathRef)
     self.assertEqual(c.get("firstint"), 666)
     self.assertEqual(c.get("liststr"), ["1", "2", "3"])
     self.assertEqual(c.get("listint"), [666, 666])
     self.assertEqual(c.get("lls"), [["A"], ["B", "BETA"], ["C", "CETA", "3"]])
     os.remove(pathTemp)
     
     c = Config()
     c.load_writable_config_file(pathTemp2, pathRef)
     c.set("firstint", 666)
     c.save()
     c.load_writable_config_file(pathTemp2, pathRef)
     self.assertEqual(c.get("firstint"), 666)
     shutil.rmtree("./a")