fixEncoding tests

This commit is contained in:
Tomas Kopecek 2017-05-19 11:56:08 +02:00
parent b2bfc28c86
commit 95f012b27d
2 changed files with 11 additions and 11 deletions

View file

@ -2912,7 +2912,7 @@ def _taskLabel(taskInfo):
return '%s (%s)' % (method, arch)
CONTROL_CHARS = [chr(i) for i in range(32)]
NONPRINTABLE_CHARS = ''.join([c for c in CONTROL_CHARS if c not in '\r\n\t'])
NONPRINTABLE_CHARS = six.b(''.join([c for c in CONTROL_CHARS if c not in '\r\n\t']))
def removeNonprintable(value):
# expects raw-encoded string, not unicode
return value.translate(None, NONPRINTABLE_CHARS)
@ -2924,7 +2924,7 @@ def fixEncoding(value, fallback='iso8859-15', remove_nonprintable=False):
encoded in the 'fallback' charset.
"""
if not value:
return ''
return six.b('')
if isinstance(value, six.text_type):
# value is already unicode, so just convert it

View file

@ -13,8 +13,8 @@ class FixEncodingTestCase(unittest.TestCase):
simple_values = [
# [ value, fixed ]
['', ''],
[u'', ''],
['', six.b('')],
[u'', six.b('')],
[u'góðan daginn', six.b('g\xc3\xb3\xc3\xb0an daginn')],
[u'hej', six.b('hej')],
[u'zdravstvuite', six.b('zdravstvuite')],
@ -51,17 +51,17 @@ class FixEncodingTestCase(unittest.TestCase):
[None, None],
[[], []],
[{u'a': 'a' , 'b' : {'c': u'c\x00'}},
{ 'a': 'a' , 'b' : {'c': 'c\x00'}}],
{six.b('a'): six.b('a') , six.b('b') : {six.b('c'): six.b('c\x00')}}],
# iso8859-15 fallback
['g\xf3\xf0an daginn', 'g\xc3\xb3\xc3\xb0an daginn'],
['g\xf3\xf0an daginn', six.b('g\xc3\xb3\xc3\xb0an daginn')],
]
nonprint = [
['hello\0world\0', 'helloworld'],
[u'hello\0world\0', 'helloworld'],
[[u'hello\0world\0'], ['helloworld']],
[{0: u'hello\0world\0'}, {0: 'helloworld'}],
[[{0: u'hello\0world\0'}], [{0: 'helloworld'}]],
['hello\0world\0', six.b('helloworld')],
[u'hello\0world\0', six.b('helloworld')],
[[u'hello\0world\0'], [six.b('helloworld')]],
[{0: u'hello\0world\0'}, {0: six.b('helloworld')}],
[[{0: u'hello\0world\0'}], [{0: six.b('helloworld')}]],
]
def test_fixEncodingRecurse(self):