[PATCH 4/4] Add test for handling unicode strings and files
Vratislav Podzimek
vpodzime at redhat.com
Fri Nov 9 19:23:25 UTC 2012
There were many bugs concerning these issues.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
tests/handle_unicode.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 tests/handle_unicode.py
diff --git a/tests/handle_unicode.py b/tests/handle_unicode.py
new file mode 100644
index 0000000..6ae67d7
--- /dev/null
+++ b/tests/handle_unicode.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+import tempfile
+
+from tests.baseclass import BaseTestCase
+from meh import Config
+
+UNICODE_STR = u"řěšččšě"
+UNICODE_LINE = u"řčšřščřčš\n"
+ASCII_STR = "fsdkljfdsldfs"
+ASCII_LINE = "fdsfsdakjfdsa\n"
+
+class UnicodeExample(object):
+ def __init__(self):
+ self.ascii_str = ASCII_STR
+ self.unicode_str = UNICODE_STR
+ self.encoded_str = self.unicode_str.encode("utf-8")
+
+class HandleUnicode_TestCase(BaseTestCase):
+ def setUp(self):
+ # write UTF-8 and ASCII files for testing
+ (fobj, self.uni_file_path) = self.openFile()
+ fobj.write(UNICODE_LINE.encode("utf-8"))
+ fobj.close()
+
+ (fobj, self.ascii_file_path) = self.openFile()
+ fobj.write(ASCII_LINE)
+ fobj.close()
+
+ def runTest(self):
+ unicode_example = UnicodeExample()
+
+ conf = Config(programName="UnicodeTest",
+ programVersion="1.0",
+ fileList=[self.uni_file_path, self.ascii_file_path])
+
+ # should not raise exception
+ dump = self.dump(conf, unicode_example)
+
+ self.assertIn("unicode_str: " + UNICODE_STR.encode("utf-8"), dump)
+ self.assertIn("encoded_str: " + UNICODE_STR.encode("utf-8"), dump)
+ self.assertIn(UNICODE_LINE.encode("utf-8"), dump)
+
+ self.assertIn("ascii_str: " + ASCII_STR, dump)
+ self.assertIn(ASCII_LINE, dump)
+
--
1.7.11.7
More information about the anaconda-patches
mailing list