]> mj.ucw.cz Git - moe.git/commitdiff
Test variable fixing, update TODO
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 10 Jul 2010 09:20:53 +0000 (11:20 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 10 Jul 2010 09:20:53 +0000 (11:20 +0200)
t/moe/conf.py
t/moe/conftest.py

index 00523ed80f028cef197e4e4c34dd5bcacb0eddb6..427736faf81fb9501898da450fe43e4d399125fe 100644 (file)
@@ -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
index 38ae76ee20b081378a0592b26b225d40900bee8b..4ce92f05dda679dcbe94792ab7faaabf5350892f 100644 (file)
@@ -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__':