From: Zack Cerza Date: Tue, 9 Dec 2014 01:18:00 +0000 (-0700) Subject: Correctly handle explicit None values X-Git-Tag: 1.1.0~1067^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=12c6aa038f3471b6bf32a269c2b36c8ea8c019ef;p=teuthology.git Correctly handle explicit None values With test. Signed-off-by: Zack Cerza --- diff --git a/teuthology/config.py b/teuthology/config.py index df1b5c7ca..bc725827b 100644 --- a/teuthology/config.py +++ b/teuthology/config.py @@ -168,8 +168,9 @@ class FakeNamespace(YamlConfig): def _clean_config(self, config_dict): """ - Makes sure that the keys of config_dict are able to be used. For example - the "--" prefix of a docopt dict isn't valid and won't populate correctly. + Makes sure that the keys of config_dict are able to be used. For + example the "--" prefix of a docopt dict isn't valid and won't populate + correctly. """ result = dict() for key, value in config_dict.iteritems(): @@ -191,10 +192,11 @@ class FakeNamespace(YamlConfig): We need to modify this for FakeNamespace so that getattr() will work correctly on a FakeNamespace instance. """ - result = self._conf.get(name, self._defaults.get(name)) - if result is None: - raise AttributeError - return self._conf.get(name, self._defaults.get(name)) + if name in self._conf: + return self._conf[name] + elif name in self._defaults: + return self._defaults[name] + raise AttributeError(name) def _get_config_path(): diff --git a/teuthology/test/test_config.py b/teuthology/test/test_config.py index 3393b81a8..7ceb5cadd 100644 --- a/teuthology/test/test_config.py +++ b/teuthology/test/test_config.py @@ -138,6 +138,10 @@ class TestFakeNamespace(TestYamlConfig): result = getattr(conf_obj, "foo") assert result == "bar" + def test_none(self): + conf_obj = self.test_class.from_dict(dict(null=None)) + assert conf_obj.null is None + def test_delattr(self): conf_obj = self.test_class() conf_obj.foo = 'bar'