]> mj.ucw.cz Git - eval.git/commitdiff
Add unicode and file parsing test
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 10 Jul 2010 10:38:50 +0000 (12:38 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 10 Jul 2010 10:38:50 +0000 (12:38 +0200)
t/moe/confparser.py
t/moe/conftest.py

index ebc453d52a16e6e430fd8c98ba182334edab20a8..31783403a3a78c640a5b413a62b321e25b5cd287 100644 (file)
@@ -85,7 +85,7 @@ class ConfigParser(object):
     `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)
index 4ce92f05dda679dcbe94792ab7faaabf5350892f..b065d04b6c19ce3c8ce5d98a752f5c8ccb964a00 100644 (file)
@@ -1,7 +1,10 @@
+# -*- coding: utf-8 -*-
+
 import moe.conf as conf
 from moe.confparser import *
 import logging as log
 import unittest
+import tempfile
 
 class TestConfig(unittest.TestCase):
 
@@ -176,17 +179,30 @@ class TestConfigEval(TestConfig):
     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"