# HG changeset patch # User Jeff Hammel # Date 1396232861 25200 # Node ID dff886188b551cfa88fb1070f395023be549ae85 # Parent 6b798d23f99f79f7313ed658f28d9132811d54cd minor fixes diff -r 6b798d23f99f -r dff886188b55 README.txt --- a/README.txt Sun Mar 30 19:12:00 2014 -0700 +++ b/README.txt Sun Mar 30 19:27:41 2014 -0700 @@ -4,8 +4,8 @@ multi-level unified configuration for python consumption - you have a (python) program that wants to read configuration from - configuration files (I currently support JSON and YAML) and also - from the command line [TODO: environment variables] + configuration files (I currently support JSON and YAML) and also + from the command line [TODO: environment variables] - you want to be able to serialize and deserialize configuration diff -r 6b798d23f99f -r dff886188b55 configuration/configuration.py --- a/configuration/configuration.py Sun Mar 30 19:12:00 2014 -0700 +++ b/configuration/configuration.py Sun Mar 30 19:27:41 2014 -0700 @@ -31,6 +31,7 @@ 'TypeCastException', 'ConfigurationOption'] + ### exceptions class UnknownOptionException(Exception): @@ -65,15 +66,11 @@ else: f = filename newfile = False - exception = None try: self._write(f, config) - except Exception, exception: - pass - if newfile: - f.close() - if exception: - raise exception + finally: + if newfile: + f.close() def _write(self, fp, config): raise NotImplementedError("Abstract base class") @@ -85,7 +82,6 @@ return json.loads(file(filename).read()) 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()) if yaml: @@ -132,6 +128,7 @@ parser.parsed = dict() parser.parsed[dest] = value + ### plugins for option types class BaseCLI(object): @@ -157,6 +154,7 @@ def take_action(self, value): return value + class BoolCLI(BaseCLI): def __call__(self, name, value): diff -r 6b798d23f99f -r dff886188b55 tests/unit.py --- a/tests/unit.py Sun Mar 30 19:12:00 2014 -0700 +++ b/tests/unit.py Sun Mar 30 19:27:41 2014 -0700 @@ -1,21 +1,17 @@ #!/usr/bin/env python """ -unit tests +unit tests for configuration package """ import configuration import datetime +import json import os import sys import tempfile import unittest -try: - import json -except ImportError: - import simplejson as json - from example import ExampleConfiguration # example configuration to test # globals @@ -227,5 +223,6 @@ instance({'foo': 'foo'}, {'foo': 'FOO', 'bar': 'bar'}) self.assertEqual(instance.added, set(['foo', 'bar'])) + if __name__ == '__main__': unittest.main()