Skip to content

Commit

Permalink
[py2py3] fix unittests from dmwm#9818 - test
Browse files Browse the repository at this point in the history
  • Loading branch information
mapellidario committed Jun 1, 2021
1 parent f887ab1 commit 145dc43
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion test/python/WMCore_t/Cache_t/GenericDataCache_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from WMCore.Cache.GenericDataCache import GenericDataCache, CacheExistException, \
CacheWithWrongStructException, MemoryCacheStruct

from Utils.PythonVersion import PY3

class Foo(object):
pass
Expand Down Expand Up @@ -58,7 +59,7 @@ def testBasicInit(self):
mc2 = MemoryCacheStruct(0, lambda x: x, {}, kwargs={'x': {'one':1, 'two':2}})
self.assertEqual(mc2.data, {})
after = mc2.getData()
self.assertItemsEqual(after.keys(), ['one', 'two'])
self.assertCountEqual(after.keys(), ['one', 'two']) if PY3 else self.assertItemsEqual(after.keys(), ['one', 'two'])

return

Expand Down
4 changes: 3 additions & 1 deletion test/python/WMCore_t/Database_t/CMSCouch_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from WMCore.Database.CMSCouch import (CouchServer, Document, Database,
CouchInternalServerError, CouchNotFoundError)

from Utils.Utilities import encodeUnicodeToBytes

class CMSCouchTest(unittest.TestCase):

test_counter = 0
Expand Down Expand Up @@ -176,7 +178,7 @@ def testAttachments(self):
attachment4 = "Lovely weather we're having"
attachment5 = "Goodbye"
keyhash = hashlib.md5()
keyhash.update(attachment5)
keyhash.update(encodeUnicodeToBytes(attachment5))
attachment5_md5 = keyhash.digest()
attachment5_md5 = base64.b64encode(attachment5_md5)
attachment6 = "Good day to you, sir!"
Expand Down
4 changes: 4 additions & 0 deletions test/python/WMCore_t/Lexicon_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,10 @@ def testGetStringsBetween(self):
self.assertEqual(result, 'T2_US_Florida')

def testGetIterMatchObjectOnRegex(self):
logPath = os.path.join(getTestBase(), "WMCore_t/test_empty.log")
for mo in getIterMatchObjectOnRegexp(logPath, WMEXCEPTION_REGEXP):
pass

count = 0
ecount = 0
logPath = os.path.join(getTestBase(), "WMCore_t/test_condor.log")
Expand Down
3 changes: 1 addition & 2 deletions test/python/WMCore_t/Services_t/Requests_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def roundTrip(self, data):
def roundTripLax(self, data):
encoded = self.request.encode(data)
decoded = self.request.decode(encoded)
datakeys = data.keys()
datakeys = list(data.keys())

for k in decoded.keys():
assert k in datakeys
Expand Down Expand Up @@ -352,6 +352,5 @@ def testNoCache(self):
self.assertEqual(out[3], False)
self.assertTrue('html' in out[0])


if __name__ == "__main__":
unittest.main()
13 changes: 11 additions & 2 deletions test/python/WMCore_t/WMException_py2py3_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ def setUp(self):
'key-ascii-d': bytes('√@ʟυℯ-1', 'utf-8'), # unicode (ascii): bytes (of non-ascii)
'ḱℯƴ-unicode-a': 'ṽ@łυ℮-2', # unicode (non-ascii): unicode (non-ascii)
u'ḱℯƴ-unicode-b': 'ṽ@łυ℮-2', # unicode (non-ascii): unicode (non-ascii)
bytes('ḱℯƴ-unicode-c', 'utf-8'): 'ṽ@łυ℮-2', # bytes (of non-ascii): unicode (non-ascii)
'ḱℯƴ-unicode-d': 'value-\x95', # unicode (of non-ascii): unicode (invalid byte)
'key-\x95': 'ṽ@łυ℮-2', # unicode (invalid byte): unicode (non-ascii)
'key3': 3.14159,

# The following line breaks py3 with
# TypeError: addInfo() keywords must be strings
# when using exception.addInfo(**data)
# 'ḱℯƴ-unicode-c'.encode('utf-8'): 'ṽ@łυ℮-2', # bytes (of non-ascii): unicode (non-ascii)

# This would break WMException, but should not happen
# 'key4': {
# b'ḱℯƴ-unicode-c': 'ṽ@łυ℮-2', # bytes (of unicode): unicode
# }

}

def tearDown(self):
Expand Down Expand Up @@ -94,7 +100,10 @@ def testExceptionUnicode1(self):
self.logger.debug("String version of exception: %s", str(exception))
self.logger.debug("exception.__str__(): %s", type(exception.__str__())) # from py2 interpreter: <class 'future.types.newbytes.newbytes'>
self.logger.debug("str(exception): %s", type(str(exception))) # <class 'future.types.newstr.newstr'>
self.logger.debug("bytes(exception): %s", type(bytes(exception))) # <class 'future.types.newbytes.newbytes'>

# The following line breaks python3 with
# in __getitem__; return self.data[key]; KeyError: 0
# self.logger.debug("bytes(exception): %s", type(bytes(exception))) # <class 'future.types.newbytes.newbytes'>


if __name__ == "__main__":
Expand Down
Empty file.

0 comments on commit 145dc43

Please sign in to comment.