From 6831f0b92032686ed53b910da6fb9fa89bbe4889 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Sat, 29 May 2010 13:34:06 -0400 Subject: [PATCH] Several new tests, updated, all passed Also covers all important code --- t/moe/{conf.test.py => conftest.py} | 66 +++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) rename t/moe/{conf.test.py => conftest.py} (58%) diff --git a/t/moe/conf.test.py b/t/moe/conftest.py similarity index 58% rename from t/moe/conf.test.py rename to t/moe/conftest.py index d26b4fe..beac064 100644 --- a/t/moe/conf.test.py +++ b/t/moe/conftest.py @@ -1,5 +1,5 @@ -import conf -from confparser import * +import moe.conf +from moe.confparser import * import logging as log import unittest @@ -72,13 +72,71 @@ class TestConfigEval(TestConfig): def test_escape_chars(s): s.parse(r"""a='{a}\\\\#\n'; b="{a}'\"\{\}"; c='\'; c+="\{{b}\}";""") assert s.val('c') == r"""\{{a}\\\\#\n'"{}}""" + ts = 'a="A:"; if "{c1}"=="1" {a+="C1"; b="B"; if ("{c2a}"=="1" or not "{c2b}"=="1") { a+="C2"; '\ + 'if ("{c3a}"=="1" and "{c3b}"=="1") { a+="C3" }}}' + def test_cond_chain(s): + s.parse(s.ts) + s.parse('c1="1"; c2="0"') + # b should have determined value, a should not (since c3a is undefined) + s.assertRaises(conf.UndefinedError, s.val, 'a') + assert s.val('b') == 'B' + s.parse('c1="0"') + # now b should be undefined + s.assertRaises(conf.UndefinedError, s.val, 'b') + # Normal evaluation + s.parse('c1="1"; c2a="1"; c2b="0"; c3a="0"') + assert s.val('a') == 'A:C1C2' + s.parse('c3a="1"; c3b="1"; c2b="1"') + assert s.val('a') == 'A:C1C2C3' + # tests condition invalidating + s.parse('c2a+="0"') + assert s.val('a') == 'A:C1' + def test_cond_eager(s): + s.parse(s.ts) + # undefined c2b and c3a should not be evaluated + s.parse('c1="1"; c2a="1"; c3a="0"') + assert s.val('a') == 'A:C1C2' + # but now c3b should be evaluated + s.parse('c1="1"; c2a="1"; c3a="1"') + s.assertRaises(conf.UndefinedError, s.val, 'a') + s.parse('c1="1"; c2a="1"; c3b="1"') + assert s.val('a') == 'A:C1C2C3' + def test_undef(s): + s.assertRaises(conf.UndefinedError, s.val, 'a') + s.parse('a="{b}"') + s.assertRaises(conf.UndefinedError, s.val, 'a') + s.parse('b+="1"') + s.assertRaises(conf.UndefinedError, s.val, 'b') + def test_loopy_def(s): + s.parse('a="A"; a+="{a}"') + s.assertRaises(conf.CyclicConfigError, s.val, 'a') + s.parse('b="{c}"; c="{b}"') + s.assertRaises(conf.CyclicConfigError, s.val, 'b') + def test_varname(s): + s.assertRaises(conf.VariableNameError, s.val, 'b/c') + s.assertRaises(conf.VariableNameError, s.val, '.b.c') + s.assertRaises(conf.VariableNameError, s.val, 'b.c.') + s.assertRaises(conf.VariableNameError, s.val, 'b..c') + def test_remove(s): + l = s.parse('a="A1"; b="B1"; if "{cond}"=="1" {a+="A2"; b+="B2"}; a+="A3"; b+="B3"; cond="1"') + assert s.val('a') == 'A1A2A3' + assert s.val('b') == 'B1B2B3' + # remove b+="B2" + s.t.lookup('b').remove_operation(l[3][1]) + assert s.val('a') == 'A1A2A3' + assert s.val('b') == 'B1B3' + # are the dependencies still handled properly? + s.parse('cond+="-invalidated"') + assert s.val('a') == 'A1A3' + s.parse('cond="1"') + assert s.val('a') == 'A1A2A3' -# TODO: conditions, chaining conditions, undefined (incl +=), loops, removal, fixing, fail on 1st April +# TODO: fixing, fail on 1st April # TODO: coverage if __name__ == '__main__': log.getLogger().setLevel(log.WARN) -# log.getLogger().setLevel(log.DEBUG) + #log.getLogger().setLevel(log.DEBUG) unittest.main() # TODO: log.info('maxdepth: %d', conf.debug_maxdepth) -- 2.39.2