Author: andar

Revision: 5614

Log:
        Add a test for saving the config

Diff:
Modified: trunk/deluge/config.py
===================================================================
--- trunk/deluge/config.py      2009-08-03 16:56:01 UTC (rev 5613)
+++ trunk/deluge/config.py      2009-08-03 17:39:12 UTC (rev 5614)
@@ -396,12 +396,12 @@
 
             if self.__config == loaded_data and self.__version == version:
                 # The config has not changed so lets just return
-                self._save_timer = None
+                self._save_timer.cancel()
                 return
         except Exception, e:
             log.warning("Unable to open config file: %s", filename)
 
-        self._save_timer = None
+        self._save_timer.cancel()
 
         # Save the new config and make sure it's written to disk
         try:

Modified: trunk/tests/test_config.py
===================================================================
--- trunk/tests/test_config.py  2009-08-03 16:56:01 UTC (rev 5613)
+++ trunk/tests/test_config.py  2009-08-03 17:39:12 UTC (rev 5614)
@@ -2,21 +2,25 @@
 from twisted.python.failure import Failure
 
 import common
+import os
 
 from deluge.config import Config
 
+DEFAULTS = {"string": "foobar", "int": 1, "float": 0.435, "bool": True, 
"tuple": (1, 2)}
+
 class ConfigTestCase(unittest.TestCase):
+    def setUp(self):
+        self.config_dir = common.set_tmp_config_dir()
+
     def test_init(self):
-        defaults = {"string": "foobar", "int": 1, "float": 0.435, "bool": 
True, "tuple": (1, 2)}
+        config = Config("test.conf", defaults=DEFAULTS, 
config_dir=self.config_dir)
+        self.assertEquals(DEFAULTS, config.config)
         
-        config = Config("test.conf", defaults=defaults, config_dir=".")
-        self.assertEquals(defaults, config.config)
-        
-        config = Config("test.conf", config_dir=".")
+        config = Config("test.conf", config_dir=self.config_dir)
         self.assertEquals({}, config.config)
     
     def test_set_get_item(self):
-        config = Config("test.conf", config_dir=".")
+        config = Config("test.conf", config_dir=self.config_dir)
         config["foo"] = 1
         self.assertEquals(config["foo"], 1)
         self.assertRaises(ValueError, config.set_item, "foo", "bar")
@@ -26,41 +30,52 @@
         config._save_timer.cancel()
 
     def test_load(self):
-        d = {"string": "foobar", "int": 1, "float": 0.435, "bool": True, 
"tuple": (1, 2)}
-
         def check_config():
-            config = Config("test.conf", config_dir=".")
+            config = Config("test.conf", config_dir=self.config_dir)
             
             self.assertEquals(config["string"], "foobar")
             self.assertEquals(config["float"], 0.435)
                 
         # Test loading an old config from 1.1.x
         import pickle
-        pickle.dump(d, open("test.conf", "wb"))
+        pickle.dump(DEFAULTS, open(os.path.join(self.config_dir, "test.conf"), 
"wb"))
         
         check_config()
                 
         # Test opening a previous 1.2 config file of just a json object
         import json
-        json.dump(d, open("test.conf", "wb"), indent=2)
+        json.dump(DEFAULTS, open(os.path.join(self.config_dir, "test.conf"), 
"wb"), indent=2)
 
         check_config()
         
         # Test opening a previous 1.2 config file of having the format versions
         # as ints
-        f = open("test.conf", "wb")
+        f = open(os.path.join(self.config_dir, "test.conf"), "wb")
         f.write(str(1) + "\n")
         f.write(str(1) + "\n")
-        json.dump(d, f, indent=2)
+        json.dump(DEFAULTS, f, indent=2)
         f.close()
         
         check_config()
         
         # Test the 1.2 config format
         v = {"format": 1, "file": 1}
-        f = open("test.conf", "wb")
+        f = open(os.path.join(self.config_dir, "test.conf"), "wb")
         json.dump(v, f, indent=2)
-        json.dump(d, f, indent=2)
+        json.dump(DEFAULTS, f, indent=2)
         f.close()
         
         check_config()
+
+    def test_save(self):
+        config = Config("test.conf", defaults=DEFAULTS, 
config_dir=self.config_dir)
+        config["string"] = "baz"
+        config["int"] = 2
+        ret = config.save()
+        self.assertTrue(ret)
+        del config
+        
+        config = Config("test.conf", defaults=DEFAULTS, 
config_dir=self.config_dir)
+        self.assertEquals(config["string"], "baz")
+        self.assertEquals(config["int"], 2)
+



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to