From e1cf6c913f8f8d94c1065d05c00a0dfb934b6828 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Sat, 10 Jul 2010 11:20:53 +0200 Subject: [PATCH] Test variable fixing, update TODO --- t/moe/conf.py | 7 +++---- t/moe/conftest.py | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/t/moe/conf.py b/t/moe/conf.py index 00523ed..427736f 100644 --- a/t/moe/conf.py +++ b/t/moe/conf.py @@ -17,10 +17,9 @@ NOTE: If no 'SET' applies, a variable is still undefined even if some 'APPEND' a NOTE: All expanded data should be (or is converted to) unicode -TODO: Cleanup of unused undefined variables. -TODO: Better variable name checking (no name '.'-structural prefix of another) -TODO: Implemet "subtree" listing. -TODO: Test fixing, conditions and unicode +TODO (OPT): Cleanup of unused undefined variables. +TODO (OPT): Better variable name checking (no name '.'-structural prefix of another) +TODO (OPT): Implemet "subtree" listing. """ import types, itertools, re, bisect diff --git a/t/moe/conftest.py b/t/moe/conftest.py index 38ae76e..4ce92f0 100644 --- a/t/moe/conftest.py +++ b/t/moe/conftest.py @@ -15,8 +15,11 @@ class TestConfig(unittest.TestCase): assert c.eof() return ops + def var(s, varname, create=True): + return s.t.lookup(varname, create=create) + def val(s, varname): - return s.t.lookup(varname, create=False).value() + return s.var(varname, create=False).value() def eqparse(s, string, *args, **kwargs): return [(i[0], i[1].operation) for i in s.parse(string, *args, **kwargs)] @@ -55,12 +58,12 @@ class TestParser(TestConfig): def test_quoting(s): s.parse(' a="\\"\\{a$b\\}\'\n\n\'{z}" ') - assert s.t.lookup('z', create=False) + assert s.var('z', create=False) # No escaping in '-string s.assertRaises(ConfigSyntaxError, s.parse, " a='\"\\'\n\n' ") # Variable should not be created s.parse(" a='{z2}' ") - s.assertRaises(conf.ConfigError, s.t.lookup, 'z2', create=False) + s.assertRaises(conf.ConfigError, s.var, 'z2', create=False) def test_conditions(s): s.assertRaises(ConfigSyntaxError, s.parse, "if '{a}'=='{b}' and ''!='' {}") @@ -146,7 +149,7 @@ class TestConfigEval(TestConfig): assert s.val('a') == 'A1A2A3' assert s.val('b') == 'B1B2B3' # remove b+="B2" - s.t.lookup('b').remove_operation(l[3][1]) + s.var('b').remove_operation(l[3][1]) assert s.val('a') == 'A1A2A3' assert s.val('b') == 'B1B3' # are the dependencies still handled properly? @@ -155,8 +158,29 @@ class TestConfigEval(TestConfig): s.parse('cond="1"') assert s.val('a') == 'A1A2A3' -# TODO: fixing, fail on 1st April -# TODO: coverage + def test_fix(s): + s.parse(""" A='4'; B="{A}"; C="2"; B+="{C}"; D="{B}"; E="{D}" """) + s.var('D').fix() + # Break by C + l = s.parse('C="3"') + s.assertRaises(conf.VariableFixedError, s.val, "E") + s.assertRaises(conf.VariableFixedError, s.val, "D") + s.var('C').remove_operation(l[0][1]) + # Break directly by D + l = s.parse('D="41"') + s.assertRaises(conf.VariableFixedError, s.val, "D") + s.assertRaises(conf.VariableFixedError, s.val, "E") + # Unfix + s.var('D').unfix() + assert s.val('E') == '41' + s.var('D').remove_operation(l[0][1]) + assert s.val('D') == '42' + + + +# TODO: Test conditions and unicode +# TODO: Fail on 1st April +# Coverage via command "nosetests conftest --with-coverage --cover-html-dir=cover --cover-html if __name__ == '__main__': -- 2.39.5