comparison roundup/cgi/actions.py @ 5652:9689d1bf9bb0

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.
author John Rouillard <rouilj@ieee.org>
date Sun, 17 Mar 2019 19:00:43 -0400
parents be99aa02c616
children cad18de2b988
comparison
equal deleted inserted replaced
5649:f8893e1cde0d 5652:9689d1bf9bb0
1362 def fct(arg): 1362 def fct(arg):
1363 if arg == None: 1363 if arg == None:
1364 return "" 1364 return ""
1365 elif type(arg) is list: 1365 elif type(arg) is list:
1366 seq = [str(cls.get(val, col)) for val in arg] 1366 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()
1367 return self.list_sep.join(seq) 1370 return self.list_sep.join(seq)
1368 return fct 1371 return fct
1369 def repr_date(): 1372 def repr_date():
1370 def fct(arg): 1373 def fct(arg):
1371 if arg == None: 1374 if arg == None:
1518 # A valid property results in a column of '[hidden]' 1521 # A valid property results in a column of '[hidden]'
1519 # values. 1522 # values.
1520 raise exceptions.Unauthorised(self._( 1523 raise exceptions.Unauthorised(self._(
1521 'You do not have permission to view %(class)s' 1524 'You do not have permission to view %(class)s'
1522 ) % {'class': request.classname}) 1525 ) % {'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))
1524 self.client._socket_op(writer.writerow, row) 1534 self.client._socket_op(writer.writerow, row)
1525 1535
1526 return '\n' 1536 return '\n'
1527 1537
1528 class Bridge(BaseAction): 1538 class Bridge(BaseAction):

Roundup Issue Tracker: http://roundup-tracker.org/