Add unit test for latin-1 fallback, multi-encoding

This commit is contained in:
Erik Johnson 2018-08-03 18:37:40 -05:00
parent 906644a80f
commit f14f4dae22
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -18,6 +18,9 @@ STR = BYTES = UNICODE.encode('utf-8')
# code points. Do not modify it.
EGGS = '\u044f\u0438\u0306\u0446\u0430'
LATIN1_UNICODE = 'räksmörgås'
LATIN1_BYTES = LATIN1_UNICODE.encode('latin-1')
class StringutilsTestCase(TestCase):
def test_contains_whitespace(self):
@ -134,6 +137,8 @@ class StringutilsTestCase(TestCase):
'яйца'
)
self.assertEqual(salt.utils.stringutils.to_unicode(LATIN1_BYTES), LATIN1_UNICODE)
if six.PY3:
self.assertEqual(salt.utils.stringutils.to_unicode('plugh'), 'plugh')
self.assertEqual(salt.utils.stringutils.to_unicode('áéíóúý'), 'áéíóúý')
@ -150,6 +155,10 @@ class StringutilsTestCase(TestCase):
with patch.object(builtins, '__salt_system_encoding__', 'CP1252'):
self.assertEqual(salt.utils.stringutils.to_unicode('Ψ'.encode('utf-8')), 'Ψ')
def test_to_unicode_multi_encoding(self):
result = salt.utils.stringutils.to_unicode(LATIN1_BYTES, encoding=('utf-8', 'latin1'))
assert result == LATIN1_UNICODE
def test_build_whitespace_split_regex(self):
expected_regex = '(?m)^(?:[\\s]+)?Lorem(?:[\\s]+)?ipsum(?:[\\s]+)?dolor(?:[\\s]+)?sit(?:[\\s]+)?amet\\,' \
'(?:[\\s]+)?$'