Exemple #1
0
 def test_set_config_new_section(self):
     """
     ``_Config.set_config`` can be called with the name of a section that does
     not already exist to create that section and set an item in it.
     """
     basedir = self.mktemp()
     new_config = config_from_string(basedir, "", "",
                                     ValidConfiguration.everything())
     new_config.set_config("foo", "bar", "value1")
     self.assertEqual(new_config.get_config("foo", "bar"), "value1")
Exemple #2
0
 def test_set_config_replace(self):
     """
     ``_Config.set_config`` can be called with a section and item that already
     exists to change an existing value to a new one.
     """
     basedir = self.mktemp()
     new_config = config_from_string(basedir, "", "",
                                     ValidConfiguration.everything())
     new_config.set_config("foo", "bar", "value1")
     new_config.set_config("foo", "bar", "value2")
     self.assertEqual(new_config.get_config("foo", "bar"), "value2")
Exemple #3
0
 def test_set_config_rejects_invalid_config(self):
     """
     ``_Config.set_config`` raises ``UnknownConfigError`` if the section or
     item is not recognized by the validation object and does not set the
     value.
     """
     # Make everything invalid.
     valid_config = ValidConfiguration.nothing()
     new_config = config_from_string(self.mktemp(), "", "", valid_config)
     with self.assertRaises(UnknownConfigError):
         new_config.set_config("foo", "bar", "baz")
     with self.assertRaises(MissingConfigEntry):
         new_config.get_config("foo", "bar")
Exemple #4
0
 def test_set_config_write(self):
     """
     ``_Config.set_config`` persists the configuration change so it can be
     re-loaded later.
     """
     # Let our nonsense config through
     valid_config = ValidConfiguration.everything()
     basedir = FilePath(self.mktemp())
     basedir.makedirs()
     cfg = basedir.child(b"tahoe.cfg")
     cfg.setContent(b"")
     new_config = read_config(basedir.path, "", [], valid_config)
     new_config.set_config("foo", "bar", "value1")
     loaded_config = read_config(basedir.path, "", [], valid_config)
     self.assertEqual(
         loaded_config.get_config("foo", "bar"),
         "value1",
     )