skip fixEncoding for py3

This commit is contained in:
Tomas Kopecek 2019-02-27 17:13:40 +01:00 committed by Mike McLean
parent 613d1587a6
commit eeeeb3ab78
6 changed files with 76 additions and 84 deletions

View file

@ -18,52 +18,48 @@ class FixEncodingTestCase(unittest.TestCase):
simple_values = [
# [ value, fixed ]
['', 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')],
[u'céad míle fáilte', six.b('c\xc3\xa9ad m\xc3\xadle f\xc3\xa1ilte')],
[u'dobrý den', six.b('dobr\xc3\xbd den')],
[u'hylô', six.b('hyl\xc3\xb4')],
[u'jó napot', six.b('j\xc3\xb3 napot')],
[u'tervehdys', six.b('tervehdys')],
[u'olá', six.b('ol\xc3\xa1')],
[u'grüezi', six.b('gr\xc3\xbcezi')],
[u'dobre dan', six.b('dobre dan')],
[u'hello', six.b('hello')],
[u'bună ziua', six.b('bun\xc4\x83 ziua')],
[u'こんにちは', six.b('\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf')],
[u'你好', six.b('\xe4\xbd\xa0\xe5\xa5\xbd')],
[u'नमस्कार', six.b('\xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\x95\xe0\xa4\xbe\xe0\xa4\xb0')],
[u'안녕하세요', six.b('\xec\x95\x88\xeb\x85\x95\xed\x95\x98\xec\x84\xb8\xec\x9a\x94')],
['', ''],
[u'', ''],
[u'góðan daginn', 'g\xc3\xb3\xc3\xb0an daginn'],
[u'hej', 'hej'],
[u'zdravstvuite', 'zdravstvuite'],
[u'céad míle fáilte', 'c\xc3\xa9ad m\xc3\xadle f\xc3\xa1ilte'],
[u'dobrý den', 'dobr\xc3\xbd den'],
[u'hylô', 'hyl\xc3\xb4'],
[u'jó napot', 'j\xc3\xb3 napot'],
[u'tervehdys', 'tervehdys'],
[u'olá', 'ol\xc3\xa1'],
[u'grüezi', 'gr\xc3\xbcezi'],
[u'dobre dan', 'dobre dan'],
[u'hello', 'hello'],
[u'bună ziua', 'bun\xc4\x83 ziua'],
[u'こんにちは', '\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf'],
[u'你好', '\xe4\xbd\xa0\xe5\xa5\xbd'],
[u'नमस्कार', '\xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\x95\xe0\xa4\xbe\xe0\xa4\xb0'],
[u'안녕하세요', '\xec\x95\x88\xeb\x85\x95\xed\x95\x98\xec\x84\xb8\xec\x9a\x94'],
]
def test_fixEncoding(self):
"""Test the fixEncoding function"""
for a, b in self.simple_values:
self.assertEqual(koji.fixEncoding(a), b)
self.assertEqual(koji.fixEncoding(b), b)
c = a.encode('utf16')
self.assertEqual(koji.fixEncoding(c, fallback='utf16'), b)
d = a[:-3] + u'\x00\x01' + a[-3:]
self.assertEqual(koji.fixEncoding(d, remove_nonprintable=True), b)
if six.PY2:
self.assertEqual(koji.fixEncoding(a), b)
c = a.encode('utf16')
self.assertEqual(koji.fixEncoding(c, fallback='utf16'), b)
d = a[:-3] + u'\x00\x01' + a[-3:]
self.assertEqual(koji.fixEncoding(d, remove_nonprintable=True), b)
else:
self.assertEqual(koji.fixEncoding(a), a)
@mock.patch('sys.stdout', new_callable=six.StringIO)
def test_fix_print(self, stdout):
def test_fix_print(self):
"""Test the _fix_print function"""
expected = ''
actual, expected = [], []
for a, b in self.simple_values:
if six.PY3:
self.assertEqual(koji._fix_print(b), a)
else:
self.assertEqual(koji._fix_print(b), b)
print(koji._fix_print(b))
if six.PY3:
expected = expected + a + '\n'
else:
expected = expected + b + '\n'
actual = stdout.getvalue()
actual.append(koji._fix_print(b))
expected.append(b)
expected = '\n'.join(expected)
actual = '\n'.join(actual)
self.assertEqual(actual, expected)
complex_values = [
@ -73,21 +69,24 @@ class FixEncodingTestCase(unittest.TestCase):
[None, None],
[[], []],
[{u'a': 'a' , 'b' : {'c': u'c\x00'}},
{six.b('a'): six.b('a') , six.b('b') : {six.b('c'): six.b('c\x00')}}],
{'a': 'a' , 'b' : {'c': 'c\x00'}}],
# iso8859-15 fallback
['g\xf3\xf0an daginn', six.b('g\xc3\xb3\xc3\xb0an daginn')],
['g\xf3\xf0an daginn', 'g\xc3\xb3\xc3\xb0an daginn'],
]
nonprint = [
['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')}]],
['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'}]],
]
def test_fixEncodingRecurse(self):
"""Test the fixEncodingRecurse function"""
if six.PY3:
# don't test for py3
return
for a, b in self.simple_values:
self.assertEqual(koji.fixEncoding(a), b)
for a, b in self.complex_values: