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
This commit is contained in:
parent
e8b04c1542
commit
704435f721
|
@ -146,7 +146,7 @@ class Config(object):
|
||||||
self._save_timer = None
|
self._save_timer = None
|
||||||
|
|
||||||
if defaults:
|
if defaults:
|
||||||
self.__config = defaults
|
self.__config = dict(defaults)
|
||||||
|
|
||||||
# Load the config from file in the config_dir
|
# Load the config from file in the config_dir
|
||||||
if config_dir:
|
if config_dir:
|
||||||
|
@ -401,7 +401,7 @@ what is currently in the config and it could not convert the value
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to open config file: %s", filename)
|
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
|
# Save the new config and make sure it's written to disk
|
||||||
try:
|
try:
|
||||||
|
@ -433,6 +433,9 @@ what is currently in the config and it could not convert the value
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
finally:
|
||||||
|
if self._save_timer.active():
|
||||||
|
self._save_timer.cancel()
|
||||||
|
|
||||||
def run_converter(self, input_range, output_version, func):
|
def run_converter(self, input_range, output_version, func):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -79,3 +79,21 @@ class ConfigTestCase(unittest.TestCase):
|
||||||
self.assertEquals(config["string"], "baz")
|
self.assertEquals(config["string"], "baz")
|
||||||
self.assertEquals(config["int"], 2)
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue