Skip to content

Commit 67f82b5

Browse files
committed
python2/python3 normalization. When exporting CSV, sort lists as they
are ordered differently in python3 vs python2. Also python 3 list element order seems to not be stable/repeatable between runs. Sometimes the tests would pass sometimes they wouldn't.
1 parent e6eba23 commit 67f82b5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

roundup/cgi/actions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,9 @@ def fct(arg):
13641364
return ""
13651365
elif type(arg) is list:
13661366
seq = [str(cls.get(val, col)) for val in arg]
1367+
# python2/python 3 have different order in lists
1368+
# sort to not break tests
1369+
seq.sort()
13671370
return self.list_sep.join(seq)
13681371
return fct
13691372
def repr_date():
@@ -1520,7 +1523,14 @@ def handle(self):
15201523
raise exceptions.Unauthorised(self._(
15211524
'You do not have permission to view %(class)s'
15221525
) % {'class': request.classname})
1523-
row.append(str(klass.get(itemid, name)))
1526+
value = klass.get(itemid, name)
1527+
try:
1528+
# python2/python 3 have different order in lists
1529+
# sort to not break tests
1530+
value.sort()
1531+
except AttributeError:
1532+
pass # value is not sortable, probably str
1533+
row.append(str(value))
15241534
self.client._socket_op(writer.writerow, row)
15251535

15261536
return '\n'

test/test_cgi.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,20 +1525,21 @@ def testCSVExport(self):
15251525
# call export version that outputs names
15261526
actions.ExportCSVAction(cl).handle()
15271527
#print(output.getvalue())
1528-
self.assertEquals('id,title,status,keyword,assignedto,nosy\r\n'
1529-
'1,foo1,deferred,,"Contrary, Mary","Bork, Chef;demo;Contrary, Mary"\r\n'
1530-
'2,bar2,unread,keyword1;keyword2,"Bork, Chef","Bork, Chef"\r\n'
1531-
'3,baz32,need-eg,,,\r\n',
1532-
1533-
output.getvalue())
1528+
should_be=('id,title,status,keyword,assignedto,nosy\r\n'
1529+
'1,foo1,deferred,,"Contrary, Mary","Bork, Chef;Contrary, Mary;demo"\r\n'
1530+
'2,bar2,unread,keyword1;keyword2,"Bork, Chef","Bork, Chef"\r\n'
1531+
'3,baz32,need-eg,,,\r\n')
1532+
#print(should_be)
1533+
#print(output.getvalue())
1534+
self.assertEqual(output.getvalue(), should_be)
15341535
output = StringIO()
15351536
cl.request = MockNull()
15361537
cl.request.wfile = output
15371538
# call export version that outputs id numbers
15381539
actions.ExportCSVWithIdAction(cl).handle()
1539-
#print(output.getvalue())
1540+
print(output.getvalue())
15401541
self.assertEquals('id,title,status,keyword,assignedto,nosy\r\n'
1541-
"1,foo1,2,[],4,\"['3', '5', '4']\"\r\n"
1542+
"1,foo1,2,[],4,\"['3', '4', '5']\"\r\n"
15421543
"2,bar2,1,\"['1', '2']\",3,['3']\r\n"
15431544
'3,baz32,4,[],None,[]\r\n',
15441545
output.getvalue())

0 commit comments

Comments
 (0)