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
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)]
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 ''!='' {}")
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?
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__':