From 8c1055587e623ccd4a9ea069e30cbfc697a0ad30 Mon Sep 17 00:00:00 2001 From: schlatterbeck Date: Fri, 9 Oct 2009 14:32:21 +0000 Subject: [PATCH] corrections for python2.3 compatibility: - rename testdata in test/test_anypy_hashlib.py, python2.3 testsuite will try to execute anything that starts with "test". - fix generator expressions in roundup/admin.py - fix sort calls with key attribute, use a standard (slower) compare function instead - Add 'sqlite' to ImportError exceptions when searching for backends git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4373 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/admin.py | 4 ++-- roundup/backends/__init__.py | 2 +- roundup/cgi/form_parser.py | 4 ++-- test/test_anypy_hashlib.py | 22 +++++++++++----------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/roundup/admin.py b/roundup/admin.py index 83728c7..077a2f5 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -1126,10 +1126,10 @@ Erase it? Y/N: """)) sys.stdout.flush() node = cl.getnode(nodeid) exp = cl.export_list(propnames, nodeid) - lensum = sum (len (repr(node[p])) for p in propnames) + lensum = sum ([len (repr(node[p])) for p in propnames]) # for a safe upper bound of field length we add # difference between CSV len and sum of all field lengths - d = sum (len(x) for x in exp) - lensum + d = sum ([len(x) for x in exp]) - lensum assert (d > 0) for p in propnames: ll = len(repr(node[p])) + d diff --git a/roundup/backends/__init__.py b/roundup/backends/__init__.py index a89223a..8735151 100644 --- a/roundup/backends/__init__.py +++ b/roundup/backends/__init__.py @@ -31,7 +31,7 @@ _modules = { 'mysql': ('MySQLdb',), 'postgresql': ('psycopg',), 'tsearch2': ('psycopg',), - 'sqlite': ('pysqlite', 'pysqlite2', 'sqlite3', '_sqlite3'), + 'sqlite': ('pysqlite', 'pysqlite2', 'sqlite3', '_sqlite3', 'sqlite'), } def get_backend(name): diff --git a/roundup/cgi/form_parser.py b/roundup/cgi/form_parser.py index cf6bb25..ce6b630 100755 --- a/roundup/cgi/form_parser.py +++ b/roundup/cgi/form_parser.py @@ -427,7 +427,7 @@ class FormParser: value = existing # Sort the value in the same order used by # Multilink.from_raw. - value.sort(key = lambda x: int(x)) + value.sort(lambda x, y: cmp(int(x),int(y))) elif value == '': # other types should be None'd if there's no value @@ -491,7 +491,7 @@ class FormParser: # The canonical order (given in Multilink.from_raw) is # by the numeric value of the IDs. if isinstance(proptype, hyperdb.Multilink): - existing.sort(key = lambda x: int(x)) + existing.sort(lambda x, y: cmp(int(x),int(y))) # "missing" existing values may not be None if not existing: diff --git a/test/test_anypy_hashlib.py b/test/test_anypy_hashlib.py index cdfb4f1..c3c7ec4 100644 --- a/test/test_anypy_hashlib.py +++ b/test/test_anypy_hashlib.py @@ -39,7 +39,7 @@ if not ((sha or md5) and hashlib): class TestCase_anypy_hashlib(unittest.TestCase): """test the hashlib compatibility layer""" - testdata = ( + data_for_test = ( ('', 'da39a3ee5e6b4b0d3255bfef95601890afd80709', 'd41d8cd98f00b204e9800998ecf8427e'), @@ -58,12 +58,12 @@ class TestCase_anypy_hashlib(unittest.TestCase): # the following two are always excecuted: def test_sha1_expected_anypy(self): """...anypy.hashlib_.sha1().hexdigest() yields expected results""" - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(roundup.anypy.hashlib_.sha1(src).hexdigest(), SHA) def test_md5_expected_anypy(self): """...anypy.hashlib_.md5().hexdigest() yields expected results""" - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(roundup.anypy.hashlib_.md5(src).hexdigest(), MD5) # execution depending on availability of modules: @@ -73,14 +73,14 @@ class TestCase_anypy_hashlib(unittest.TestCase): if md5.md5 is hashlib.md5: return else: - for s, i1, i2 in self.testdata: + for s, i1, i2 in self.data_for_test: self.assertEqual(md5.md5(s).digest(), hashlib.md5().digest()) if md5: def test_md5_expected(self): """md5.md5().hexdigest() yields expected results""" - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(md5.md5(src).hexdigest(), MD5) def test_md5_new_expected(self): @@ -88,7 +88,7 @@ class TestCase_anypy_hashlib(unittest.TestCase): if md5.new is md5.md5: return else: - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(md5.new(src).hexdigest(), MD5) if sha and hashlib: @@ -97,14 +97,14 @@ class TestCase_anypy_hashlib(unittest.TestCase): if sha.sha is hashlib.sha1: return else: - for s in self.testdata: + for s in self.data_for_test: self.assertEqual(sha.sha(s).digest(), hashlib.sha1().digest()) if sha: def test_sha_expected(self): """sha.sha().hexdigest() yields expected results""" - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(sha.sha(src).hexdigest(), SHA) # fails for me with Python 2.3; unittest module bug? @@ -113,18 +113,18 @@ class TestCase_anypy_hashlib(unittest.TestCase): if sha.new is sha.sha: return else: - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(sha.new(src).hexdigest(), SHA) if hashlib: def test_sha1_expected_hashlib(self): """hashlib.sha1().hexdigest() yields expected results""" - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(hashlib.sha1(src).hexdigest(), SHA) def test_md5_expected_hashlib(self): """hashlib.md5().hexdigest() yields expected results""" - for src, SHA, MD5 in self.testdata: + for src, SHA, MD5 in self.data_for_test: self.assertEqual(hashlib.md5(src).hexdigest(), MD5) def test_suite(): -- 2.30.2