]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Correctly handle explicit None values
authorZack Cerza <zack.cerza@inktank.com>
Tue, 9 Dec 2014 01:18:00 +0000 (18:18 -0700)
committerZack Cerza <zack.cerza@inktank.com>
Tue, 9 Dec 2014 01:18:00 +0000 (18:18 -0700)
With test.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/config.py
teuthology/test/test_config.py

index df1b5c7ca688ebb675eed9b116020217529a42b9..bc725827b01352b85f6fca6aa390bf4a74e877d9 100644 (file)
@@ -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():
index 3393b81a8396ad0dbbcdac162a141343c0018085..7ceb5cadd57da8e6ec7309725fc2d06803509916 100644 (file)
@@ -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'