Пример #1
0
 def test_save_no_config(self):
     """Test saving uninitialized config
     """
     conf["a"] = 12
     with tempfile.NamedTemporaryFile() as temp:
         conf.save(temp.name)
         conf.reset_instance()
         self.assertNotIn("a", conf)
         conf.load(temp.name)
         self.assertIn("a", conf)
         self.assertEqual(int(conf["a"]), 12)
Пример #2
0
 def test_save_no_config(self):
     """Test saving uninitialized config
     """
     conf['a'] = 12
     with tempfile.NamedTemporaryFile() as temp:
         conf.save(temp.name)
         conf.reset_instance()
         self.assertNotIn('a', conf)
         conf.load(temp.name)
         self.assertIn('a', conf)
         self.assertEqual(int(conf['a']), 12)
Пример #3
0
    def test_save_load_config(self):
        """Test saving and reloading conf
        """
        conf.load(self.filename)

        filename = tempfile.mkstemp()[1]
        conf.save(filename)

        # Destroy configuration
        conf.reset_instance()
        self.assertRaises(KeyError, lambda: conf["section_1.a"])

        conf.load(filename)
        a_conf = conf["section_1.a"]
        self.assertEqual(a_conf, "12")
        b_conf = conf["section_1.b"]
        self.assertEqual(b_conf, "13")
        c_conf = conf["section_2.c"]
        self.assertEqual(c_conf, "True")

        self.assertTrue(os.path.isfile(filename))
        # Clean up
        os.remove(filename)
Пример #4
0
    def test_save_load_config(self):
        """Test saving and reloading conf
        """
        conf.load(self.filename)

        filename = tempfile.mkstemp()[1]
        conf.save(filename)

        # Destroy configuration
        conf.reset_instance()
        self.assertRaises(KeyError, lambda: conf['section_1.a'])

        conf.load(filename)
        a_conf = conf['section_1.a']
        self.assertEqual(a_conf, '12')
        b_conf = conf['section_1.b']
        self.assertEqual(b_conf, '13')
        c_conf = conf['section_2.c']
        self.assertEqual(c_conf, 'True')

        self.assertTrue(os.path.isfile(filename))
        # Clean up
        os.remove(filename)
Пример #5
0
def save_config(filename):
    """Save a configuration file to a filename
    """
    conf.save(filename)
    print("Wrote configuration to '%s'" % filename)
Пример #6
0
def save_config(filename):
    """Save a configuration file to a filename
    """
    conf.save(filename)
    print("Wrote configuration to '%s'" % filename)