# HG changeset patch # User Jeff Hammel # Date 1332869282 25200 # Node ID 8909ae1cc4eafc7d353b8d4fcb1e1984a4cb9b4a # Parent a1f8dec4d4f910c7546a1ad159c5be63acd667b3 fix serialization (stub) tests diff -r a1f8dec4d4f9 -r 8909ae1cc4ea configuration/config.py --- 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) diff -r a1f8dec4d4f9 -r 8909ae1cc4ea tests/unit.py --- a/tests/unit.py Tue Mar 27 09:52:51 2012 -0700 +++ b/tests/unit.py Tue Mar 27 10:28:02 2012 -0700 @@ -53,6 +53,7 @@ # serialize to a temporary file filename = tempfile.mktemp(suffix='.json') + self.assertEqual(example.filename2format(filename), 'json') self.assertFalse(os.path.exists(filename)) config = {'browser_path': '/home/jhammel/bin/firefox', 'activeTests': ['ts']}