Mercurial > hg > configuration
changeset 131:dff886188b55
minor fixes
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 30 Mar 2014 19:27:41 -0700 |
parents | 6b798d23f99f |
children | af5e83a4763b |
files | README.txt configuration/configuration.py tests/unit.py |
diffstat | 3 files changed, 11 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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):
--- 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()