changeset 30:b27a7cb2dd5b

stub test for configuration providers
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Mar 2012 17:05:02 -0700
parents fadcc6ab51d4
children 5571d1608cba
files configuration/config.py tests/unit.py
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/config.py	Mon Mar 26 17:00:12 2012 -0700
+++ b/configuration/config.py	Mon Mar 26 17:05:02 2012 -0700
@@ -59,11 +59,11 @@
         def _write(self, fp, config):
             fp.write(json.dumps(config), indent=self.indent, sort_keys=True)
             # TODO: could use templates to get order down, etc
-    configuration_providers.append(JSON)
+    configuration_providers.append(JSON())
 
 if yaml:
     class YAML(object):
-        extensions = ['yml']
+        extensions = ['yml', 'yaml']
         def read(self, filename):
             f = file(filename)
             config = yaml.load(f)
@@ -73,7 +73,9 @@
             fp.write(yaml.dump(config))
             # TODO: could use templates to get order down, etc
 
-    configuration_providers.append(YAML)
+    configuration_providers.append(YAML())
+
+__all__.extend([i.__class__.__name__ for i in configuration_providers])
 
 ### plugins for option types
 ### TODO: this could use a bit of thought
@@ -275,4 +277,3 @@
 
         if not format:
             extension = os.path.splitext(filename)[-1]
-
--- a/tests/unit.py	Mon Mar 26 17:00:12 2012 -0700
+++ b/tests/unit.py	Mon Mar 26 17:05:02 2012 -0700
@@ -4,6 +4,7 @@
 unit tests
 """
 
+import configuration
 import os
 import sys
 import unittest
@@ -36,6 +37,13 @@
 
     def test_configuration_providers(self):
         """test file-based configuration providers"""
+        # require json/simplejson and pyyaml to be installed
+
+        example = ExampleConfiguration()
+
+        # see what providers you got
+        json_provider = example.configuration_provider('json')
+        self.assertTrue(isinstance(json_provider, configuration.JSON))
 
 if __name__ == '__main__':
     unittest.main()