Skip to content

Commit da4c272

Browse files
author
Ralf Schlatterbeck
committed
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
1 parent efdd949 commit da4c272

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

roundup/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,10 +1126,10 @@ class colon_separated(csv.excel):
11261126
sys.stdout.flush()
11271127
node = cl.getnode(nodeid)
11281128
exp = cl.export_list(propnames, nodeid)
1129-
lensum = sum (len (repr(node[p])) for p in propnames)
1129+
lensum = sum ([len (repr(node[p])) for p in propnames])
11301130
# for a safe upper bound of field length we add
11311131
# difference between CSV len and sum of all field lengths
1132-
d = sum (len(x) for x in exp) - lensum
1132+
d = sum ([len(x) for x in exp]) - lensum
11331133
assert (d > 0)
11341134
for p in propnames:
11351135
ll = len(repr(node[p])) + d

roundup/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'mysql': ('MySQLdb',),
3232
'postgresql': ('psycopg',),
3333
'tsearch2': ('psycopg',),
34-
'sqlite': ('pysqlite', 'pysqlite2', 'sqlite3', '_sqlite3'),
34+
'sqlite': ('pysqlite', 'pysqlite2', 'sqlite3', '_sqlite3', 'sqlite'),
3535
}
3636

3737
def get_backend(name):

roundup/cgi/form_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def parse(self, create=0, num_re=re.compile('^\d+$')):
427427
value = existing
428428
# Sort the value in the same order used by
429429
# Multilink.from_raw.
430-
value.sort(key = lambda x: int(x))
430+
value.sort(lambda x, y: cmp(int(x),int(y)))
431431

432432
elif value == '':
433433
# other types should be None'd if there's no value
@@ -491,7 +491,7 @@ def parse(self, create=0, num_re=re.compile('^\d+$')):
491491
# The canonical order (given in Multilink.from_raw) is
492492
# by the numeric value of the IDs.
493493
if isinstance(proptype, hyperdb.Multilink):
494-
existing.sort(key = lambda x: int(x))
494+
existing.sort(lambda x, y: cmp(int(x),int(y)))
495495

496496
# "missing" existing values may not be None
497497
if not existing:

test/test_anypy_hashlib.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class UntestableWarning(Warning):
3939
class TestCase_anypy_hashlib(unittest.TestCase):
4040
"""test the hashlib compatibility layer"""
4141

42-
testdata = (
42+
data_for_test = (
4343
('',
4444
'da39a3ee5e6b4b0d3255bfef95601890afd80709',
4545
'd41d8cd98f00b204e9800998ecf8427e'),
@@ -58,12 +58,12 @@ class TestCase_anypy_hashlib(unittest.TestCase):
5858
# the following two are always excecuted:
5959
def test_sha1_expected_anypy(self):
6060
"""...anypy.hashlib_.sha1().hexdigest() yields expected results"""
61-
for src, SHA, MD5 in self.testdata:
61+
for src, SHA, MD5 in self.data_for_test:
6262
self.assertEqual(roundup.anypy.hashlib_.sha1(src).hexdigest(), SHA)
6363

6464
def test_md5_expected_anypy(self):
6565
"""...anypy.hashlib_.md5().hexdigest() yields expected results"""
66-
for src, SHA, MD5 in self.testdata:
66+
for src, SHA, MD5 in self.data_for_test:
6767
self.assertEqual(roundup.anypy.hashlib_.md5(src).hexdigest(), MD5)
6868

6969
# execution depending on availability of modules:
@@ -73,22 +73,22 @@ def test_md5_continuity(self):
7373
if md5.md5 is hashlib.md5:
7474
return
7575
else:
76-
for s, i1, i2 in self.testdata:
76+
for s, i1, i2 in self.data_for_test:
7777
self.assertEqual(md5.md5(s).digest(),
7878
hashlib.md5().digest())
7979

8080
if md5:
8181
def test_md5_expected(self):
8282
"""md5.md5().hexdigest() yields expected results"""
83-
for src, SHA, MD5 in self.testdata:
83+
for src, SHA, MD5 in self.data_for_test:
8484
self.assertEqual(md5.md5(src).hexdigest(), MD5)
8585

8686
def test_md5_new_expected(self):
8787
"""md5.new is md5.md5, or at least yields expected results"""
8888
if md5.new is md5.md5:
8989
return
9090
else:
91-
for src, SHA, MD5 in self.testdata:
91+
for src, SHA, MD5 in self.data_for_test:
9292
self.assertEqual(md5.new(src).hexdigest(), MD5)
9393

9494
if sha and hashlib:
@@ -97,14 +97,14 @@ def test_sha1_continuity(self):
9797
if sha.sha is hashlib.sha1:
9898
return
9999
else:
100-
for s in self.testdata:
100+
for s in self.data_for_test:
101101
self.assertEqual(sha.sha(s).digest(),
102102
hashlib.sha1().digest())
103103

104104
if sha:
105105
def test_sha_expected(self):
106106
"""sha.sha().hexdigest() yields expected results"""
107-
for src, SHA, MD5 in self.testdata:
107+
for src, SHA, MD5 in self.data_for_test:
108108
self.assertEqual(sha.sha(src).hexdigest(), SHA)
109109

110110
# fails for me with Python 2.3; unittest module bug?
@@ -113,18 +113,18 @@ def test_sha_new_expected(self):
113113
if sha.new is sha.sha:
114114
return
115115
else:
116-
for src, SHA, MD5 in self.testdata:
116+
for src, SHA, MD5 in self.data_for_test:
117117
self.assertEqual(sha.new(src).hexdigest(), SHA)
118118

119119
if hashlib:
120120
def test_sha1_expected_hashlib(self):
121121
"""hashlib.sha1().hexdigest() yields expected results"""
122-
for src, SHA, MD5 in self.testdata:
122+
for src, SHA, MD5 in self.data_for_test:
123123
self.assertEqual(hashlib.sha1(src).hexdigest(), SHA)
124124

125125
def test_md5_expected_hashlib(self):
126126
"""hashlib.md5().hexdigest() yields expected results"""
127-
for src, SHA, MD5 in self.testdata:
127+
for src, SHA, MD5 in self.data_for_test:
128128
self.assertEqual(hashlib.md5(src).hexdigest(), MD5)
129129

130130
def test_suite():

0 commit comments

Comments
 (0)