From: Tomas Gavenciak Date: Sat, 11 Sep 2010 16:35:09 +0000 (+0200) Subject: Made ConfigTree.fix take list os well, added test X-Git-Tag: python-dummy-working~21 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=8020078dd0c80b9b6680244c586c8a34c1912682;p=eval.git Made ConfigTree.fix take list os well, added test --- diff --git a/t/moe/config.py b/t/moe/config.py index d17d1c8..1de6799 100644 --- a/t/moe/config.py +++ b/t/moe/config.py @@ -94,9 +94,12 @@ class ConfigTree(object): self.variables[k].dump(prefix) for k in sorted(self.variables.keys()) ]) - def fix(self, key): - "Fix variable value. Fixing undefined variable raises `UndefinedError`." - self.lookup(key, create=True).fix() + def fix(self, keys): + "Fix value of variable or list of variables. Fixing undefined variable raises `UndefinedError`." + if isinstance(keys, types.StringTypes): + keys = [keys] + for key in keys: + self.lookup(key, create=True).fix() def parse(self, s, source=None, level=0): """Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details.""" diff --git a/t/moe/config_test.py b/t/moe/config_test.py index 573934f..b0ba612 100644 --- a/t/moe/config_test.py +++ b/t/moe/config_test.py @@ -188,6 +188,13 @@ class TestConfigEval(TestConfig): assert s.val('E') == '41' s.var('D').remove_operation(l[0][1]) assert s.val('D') == '42' + # Fixing via ConfigTree.fix + s.t.fix('D') + s.t.fix(['E','A']) + s.parse('D=""; E=""; A=""; ') + s.assertRaises(cf.VariableFixedError, s.val, "D") + s.assertRaises(cf.VariableFixedError, s.val, "E") + s.assertRaises(cf.VariableFixedError, s.val, "A") def test_unicode(s): # Ascii (1b) and unicode (2b)