X Tutup
Skip to content

Commit feefd40

Browse files
committed
unit tests to unic nfc and nfd handling
1 parent 8dfbf5b commit feefd40

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/robot/utils/unic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
def unic(item, *args):
2020
# Based on a recipe from http://code.activestate.com/recipes/466341
2121
try:
22-
return unicodedata.normalize("NFC",unicode(item, *args))
22+
return unicodedata.normalize('NFC', unicode(item, *args))
2323
except UnicodeError:
2424
try:
2525
ascii_text = str(item).encode('string_escape')
2626
except UnicodeError:
27-
return "<unrepresentable object '%s'>" % item.__class__.__name__
27+
return u"<unrepresentable object '%s'>" % item.__class__.__name__
2828
else:
2929
return unicode(ascii_text)
3030

utest/utils/test_unic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
import unicodedata
23
from robot.utils import unic, is_jython
34
from robot.utils.asserts import assert_equals, assert_true
45
if is_jython:
@@ -8,7 +9,7 @@
89

910

1011
if is_jython:
11-
class TestUnic(unittest.TestCase):
12+
class TestJavaUnic(unittest.TestCase):
1213

1314
def test_with_java_object(self):
1415
data = u'This is unicode \xe4\xf6'
@@ -29,6 +30,13 @@ def test_with_iterator(self):
2930

3031
class TestUnic(unittest.TestCase):
3132

33+
def test_unicode_nfc_and_nfd_decomposition_equality(self):
34+
text = u'Hyv\xe4'
35+
assert_equals(unic(unicodedata.normalize('NFC', text)), text)
36+
# In Mac filesystem umlaut characters are presented in NFD-format.
37+
# This is to check that unic normalizes all strings to NFC
38+
assert_equals(unic(unicodedata.normalize('NFD', text)), text)
39+
3240
def test_object_containing_unicode_repr(self):
3341
assert_equals(unic(UnicodeRepr()), u'Hyv\xe4')
3442

0 commit comments

Comments
 (0)
X Tutup