From: Tomas Gavenciak Date: Sat, 10 Jul 2010 10:38:50 +0000 (+0200) Subject: Add unicode and file parsing test X-Git-Tag: python-dummy-working~41 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=c1ab43f6560c6ad61e51face3bfeda5dd8c703ce;p=moe.git Add unicode and file parsing test --- diff --git a/t/moe/confparser.py b/t/moe/confparser.py index ebc453d..3178340 100644 --- a/t/moe/confparser.py +++ b/t/moe/confparser.py @@ -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) diff --git a/t/moe/conftest.py b/t/moe/conftest.py index 4ce92f0..b065d04 100644 --- a/t/moe/conftest.py +++ b/t/moe/conftest.py @@ -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"