X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=t%2Fmoe%2Fconfig.py;h=d17d1c8af7e7ccf75d236f3f120ac169230ffd3f;hb=204f84eafd2659dd82b06feb7d182d4a15a44237;hp=bcef93be2cb841e394bc496abeb687078275b1aa;hpb=750990d7dbbaf2740f290a26dab527ce4444cbfb;p=moe.git diff --git a/t/moe/config.py b/t/moe/config.py index bcef93b..d17d1c8 100644 --- a/t/moe/config.py +++ b/t/moe/config.py @@ -94,6 +94,10 @@ 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 parse(self, s, source=None, level=0): """Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details.""" import moe.confparser @@ -103,10 +107,10 @@ class ConfigTree(object): def parse_file(self, filename, desc=None, level=0): """Parse an utf-8 file into the tree, see `moe.confparser.ConfigParser` for details. Names the source "`filename` <`desc`>". """ - f = open(filename, 'rt') - if desc: - filename += " <" + desc + ">" - self.parse(f, source=filename, level=level) + with open(filename, 'rt') as f: + if desc: + filename += " <" + desc + ">" + self.parse(f, source=filename, level=level) class ConfigElem(object): @@ -274,7 +278,7 @@ class ConfigVar(ConfigElem): self.fixed = True def unfix(self): - "Set the variable to be modifiable again." + "Make the variable modifiable again." self.fixed = False def value(self, depth=0):