diff configuration/config.py @ 38:8909ae1cc4ea

fix serialization (stub) tests
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 27 Mar 2012 10:28:02 -0700
parents a1f8dec4d4f9
children 1bd4ddf2e81d
line wrap: on
line diff
--- a/configuration/config.py	Tue Mar 27 09:52:51 2012 -0700
+++ b/configuration/config.py	Tue Mar 27 10:28:02 2012 -0700
@@ -58,18 +58,18 @@
         raise NotImplementedError("Abstract base class")
 
 if json:
-    class JSON(object):
+    class JSON(ConfigurationProvider):
         indent = 2
         extensions = ['json']
         def read(self, filename):
             return json.loads(file(filename).read())
         def _write(self, fp, config):
-            fp.write(json.dumps(config), indent=self.indent, sort_keys=True)
+            fp.write(json.dumps(config, indent=self.indent, sort_keys=True))
             # TODO: could use templates to get order down, etc
     configuration_providers.append(JSON())
 
 if yaml:
-    class YAML(object):
+    class YAML(ConfigurationProvider):
         extensions = ['yml', 'yaml']
         def read(self, filename):
             f = file(filename)
@@ -296,7 +296,7 @@
 
     def filename2format(self, filename):
         extension = os.path.splitext(filename)[-1]
-        return extension.rstrip('.') or None
+        return extension.lstrip('.') or None
 
     def serialize(self, filename, format=None, full=False):
         """
@@ -314,6 +314,8 @@
                 # TODO: more specific exception type
 
         provider = self.configuration_provider(format)
+        if not provider:
+            raise Exception("Provider not found for format: %s" % format)
 
         config = copy.deepcopy(self.config)