`fname` is an optional name of the file, for debugging and syntax errors.
`level` indicates the precedence the operations should have in the ConfigTree
"""
- self.s = s # Unicode, string or an open file
+ self.s = s # Unicode, ascii string or an open file
self.buf = u"" # Read-buffer for s file, whole unicode string for s string/unicode
if isinstance(self.s, types.StringTypes):
self.buf = unicode(self.s)
+# -*- coding: utf-8 -*-
+
import moe.conf as conf
from moe.confparser import *
import logging as log
import unittest
+import tempfile
class TestConfig(unittest.TestCase):
s.var('D').remove_operation(l[0][1])
assert s.val('D') == '42'
+ def test_unicode(s):
+ # Ascii (1b) and unicode (2b)
+ s.parse(u'A="Ú"; C="ě"')
+ # String
+ s.parse('B=\'chyln\'')
+ # By escapes
+ s.parse(u'D=\'\u0159e\u017eav\xe1\'')
+ s.parse(u'E="ŽluŤ"')
+ # Via utf8 file
+ f = tempfile.TemporaryFile(mode='w+t')
+ f.write(u'S1="\xdachyln\u011b \u0159e\u017eav\xe1 \u017dlu\u0164" ; S2="{A}{B}{C} {D} {E}"'.encode('utf8'))
+ f.seek(0)
+ s.parse(f)
+ # Test
+ s.parse(u'if "{S1}"=="{S2}" { ANS="jó!" } ')
+ assert s.val('ANS') == u"jó!"
+ assert s.val('S1') == s.val('S2') == u'\xdachyln\u011b \u0159e\u017eav\xe1 \u017dlu\u0164'
-# 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__':
- log.getLogger().setLevel(log.WARN)
- #log.getLogger().setLevel(log.DEBUG)
- unittest.main()
+# TODO: Test conditions
+# TODO: Fail on 1st April
+# TODO: Somehow add log.debug('Maximum encountered depth: %d', conf.debug_maxdepth)
-# TODO: log.info('maxdepth: %d', conf.debug_maxdepth)
+# Coverage via command "nosetests conftest --with-coverage --cover-html-dir=cover --cover-html"