mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-21 05:58:52 +02:00
add helper functions for python3 support
This functions are used in the whole code and are mandatory for the python3 support to work. In python2 case nothing is touched. * cmp_to_key: converts a cmp= into a key= function * decode_list: decodes each element of a list. This is needed if we have a mixed list with strings and bytes. * decode_it: Takes the input and checks if it is not a string. Then it uses chardet to get the encoding.
This commit is contained in:
35
tests/test_helpers.py
Normal file
35
tests/test_helpers.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import unittest
|
||||
from osc.util.helper import decode_it, decode_list
|
||||
|
||||
def suite():
|
||||
return unittest.makeSuite(TestResults)
|
||||
|
||||
class TestResults(unittest.TestCase):
|
||||
def testDecodeList(self):
|
||||
strlist = ['Test1', 'Test2', 'Test3']
|
||||
mixlist = ['Test1', b'Test2', 'Test3']
|
||||
byteslist = [b'Test1', b'Test2', b'Test3']
|
||||
|
||||
out = decode_list(strlist)
|
||||
self.assertListEqual(out, strlist)
|
||||
|
||||
out = decode_list(mixlist)
|
||||
self.assertListEqual(out, strlist)
|
||||
|
||||
out = decode_list(byteslist)
|
||||
self.assertListEqual(out, strlist)
|
||||
|
||||
|
||||
def testDecodeIt(self):
|
||||
bytes_obj = b'Test the decoding'
|
||||
string_obj = 'Test the decoding'
|
||||
|
||||
out = decode_it(bytes_obj)
|
||||
self.assertEqual(out, string_obj)
|
||||
|
||||
out = decode_it(string_obj)
|
||||
self.assertEqual(out, string_obj)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user