Author: andar
Revision: 5615
Log:
Config copies the defaults dict now since it is mutable
Fix saving with the save_timer after setting an item
Add test for testing the save timer
Diff:
Modified: trunk/deluge/config.py
===================================================================
--- trunk/deluge/config.py 2009-08-03 17:39:12 UTC (rev 5614)
+++ trunk/deluge/config.py 2009-08-03 18:43:05 UTC (rev 5615)
@@ -146,7 +146,7 @@
self._save_timer = None
if defaults:
- self.__config = defaults
+ self.__config = dict(defaults)
# Load the config from file in the config_dir
if config_dir:
@@ -401,7 +401,7 @@
except Exception, e:
log.warning("Unable to open config file: %s", filename)
- self._save_timer.cancel()
+
# Save the new config and make sure it's written to disk
try:
@@ -433,6 +433,9 @@
return False
else:
return True
+ finally:
+ if self._save_timer.active():
+ self._save_timer.cancel()
def run_converter(self, input_range, output_version, func):
"""
Modified: trunk/tests/test_config.py
===================================================================
--- trunk/tests/test_config.py 2009-08-03 17:39:12 UTC (rev 5614)
+++ trunk/tests/test_config.py 2009-08-03 18:43:05 UTC (rev 5615)
@@ -79,3 +79,21 @@
self.assertEquals(config["string"], "baz")
self.assertEquals(config["int"], 2)
+ def test_save_timer(self):
+ config = Config("test.conf", defaults=DEFAULTS,
config_dir=self.config_dir)
+ config["string"] = "baz"
+ config["int"] = 2
+ self.assertTrue(config._save_timer.active())
+
+ def check_config(config):
+ self.assertTrue(not config._save_timer.active())
+ del config
+ config = Config("test.conf", defaults=DEFAULTS,
config_dir=self.config_dir)
+ self.assertEquals(config["string"], "baz")
+ self.assertEquals(config["int"], 2)
+
+ from twisted.internet.task import deferLater
+ from twisted.internet import reactor
+ d = deferLater(reactor, 7, check_config, config)
+ return d
+
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---