Revision: 3181
Author: jussi.ao.malinen
Date: Wed May 5 04:39:32 2010
Log: unit tests to unic nfc and nfd handling
http://code.google.com/p/robotframework/source/detail?r=3181
Modified:
/trunk/src/robot/utils/unic.py
/trunk/utest/utils/test_unic.py
=======================================
--- /trunk/src/robot/utils/unic.py Wed May 5 00:11:57 2010
+++ /trunk/src/robot/utils/unic.py Wed May 5 04:39:32 2010
@@ -19,12 +19,12 @@
def unic(item, *args):
# Based on a recipe from http://code.activestate.com/recipes/466341
try:
- return unicodedata.normalize("NFC",unicode(item, *args))
+ return unicodedata.normalize('NFC', unicode(item, *args))
except UnicodeError:
try:
ascii_text = str(item).encode('string_escape')
except UnicodeError:
- return "<unrepresentable object '%s'>" %
item.__class__.__name__
+ return u"<unrepresentable object '%s'>" %
item.__class__.__name__
else:
return unicode(ascii_text)
=======================================
--- /trunk/utest/utils/test_unic.py Fri Apr 16 04:55:04 2010
+++ /trunk/utest/utils/test_unic.py Wed May 5 04:39:32 2010
@@ -1,4 +1,5 @@
import unittest
+import unicodedata
from robot.utils import unic, is_jython
from robot.utils.asserts import assert_equals, assert_true
if is_jython:
@@ -8,7 +9,7 @@
if is_jython:
- class TestUnic(unittest.TestCase):
+ class TestJavaUnic(unittest.TestCase):
def test_with_java_object(self):
data = u'This is unicode \xe4\xf6'
@@ -29,6 +30,13 @@
class TestUnic(unittest.TestCase):
+ def test_unicode_nfc_and_nfd_decomposition_equality(self):
+ text = u'Hyv\xe4'
+ assert_equals(unic(unicodedata.normalize('NFC', text)), text)
+ # In Mac filesystem umlaut characters are presented in NFD-format.
+ # This is to check that unic normalizes all strings to NFC
+ assert_equals(unic(unicodedata.normalize('NFD', text)), text)
+
def test_object_containing_unicode_repr(self):
assert_equals(unic(UnicodeRepr()), u'Hyv\xe4')