From 145dc4325718a119b07ff52f460b9d1e6c8ec790 Mon Sep 17 00:00:00 2001 From: Dario Mapelli Date: Thu, 27 May 2021 19:04:59 +0200 Subject: [PATCH] [py2py3] fix unittests from #9818 - test --- test/python/WMCore_t/Cache_t/GenericDataCache_t.py | 3 ++- test/python/WMCore_t/Database_t/CMSCouch_t.py | 4 +++- test/python/WMCore_t/Lexicon_t.py | 4 ++++ test/python/WMCore_t/Services_t/Requests_t.py | 3 +-- test/python/WMCore_t/WMException_py2py3_t.py | 13 +++++++++++-- test/python/WMCore_t/test_empty.log | 0 6 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 test/python/WMCore_t/test_empty.log diff --git a/test/python/WMCore_t/Cache_t/GenericDataCache_t.py b/test/python/WMCore_t/Cache_t/GenericDataCache_t.py index f79192db1b..5841c96f0b 100644 --- a/test/python/WMCore_t/Cache_t/GenericDataCache_t.py +++ b/test/python/WMCore_t/Cache_t/GenericDataCache_t.py @@ -10,6 +10,7 @@ from WMCore.Cache.GenericDataCache import GenericDataCache, CacheExistException, \ CacheWithWrongStructException, MemoryCacheStruct +from Utils.PythonVersion import PY3 class Foo(object): pass @@ -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 diff --git a/test/python/WMCore_t/Database_t/CMSCouch_t.py b/test/python/WMCore_t/Database_t/CMSCouch_t.py index c65e3db0ee..6d705ebf88 100644 --- a/test/python/WMCore_t/Database_t/CMSCouch_t.py +++ b/test/python/WMCore_t/Database_t/CMSCouch_t.py @@ -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 @@ -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!" diff --git a/test/python/WMCore_t/Lexicon_t.py b/test/python/WMCore_t/Lexicon_t.py index b0dd7a5fc8..28bb94f581 100644 --- a/test/python/WMCore_t/Lexicon_t.py +++ b/test/python/WMCore_t/Lexicon_t.py @@ -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") diff --git a/test/python/WMCore_t/Services_t/Requests_t.py b/test/python/WMCore_t/Services_t/Requests_t.py index b07c734d8b..e91041e778 100644 --- a/test/python/WMCore_t/Services_t/Requests_t.py +++ b/test/python/WMCore_t/Services_t/Requests_t.py @@ -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 @@ -352,6 +352,5 @@ def testNoCache(self): self.assertEqual(out[3], False) self.assertTrue('html' in out[0]) - if __name__ == "__main__": unittest.main() diff --git a/test/python/WMCore_t/WMException_py2py3_t.py b/test/python/WMCore_t/WMException_py2py3_t.py index fe8fdfa6c8..64724ee80a 100644 --- a/test/python/WMCore_t/WMException_py2py3_t.py +++ b/test/python/WMCore_t/WMException_py2py3_t.py @@ -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): @@ -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: self.logger.debug("str(exception): %s", type(str(exception))) # - self.logger.debug("bytes(exception): %s", type(bytes(exception))) # + + # The following line breaks python3 with + # in __getitem__; return self.data[key]; KeyError: 0 + # self.logger.debug("bytes(exception): %s", type(bytes(exception))) # if __name__ == "__main__": diff --git a/test/python/WMCore_t/test_empty.log b/test/python/WMCore_t/test_empty.log new file mode 100644 index 0000000000..e69de29bb2