|
9 | 9 | from irods.message import (ET as ET_set, XML_Parser_Type, current_XML_parser, default_XML_parser) |
10 | 10 | import logging |
11 | 11 | import irods.test.helpers as helpers |
| 12 | +from six import PY3 |
12 | 13 |
|
13 | 14 | logger = logging.getLogger(__name__) |
14 | 15 |
|
@@ -90,16 +91,24 @@ def test_files(self): |
90 | 91 | query = self.sess.query(DataObject.name, Collection.name).filter( |
91 | 92 | Collection.name == self.coll_path) |
92 | 93 |
|
| 94 | + # Python2 compatibility note: In keeping with the principle of least surprise, we now ensure |
| 95 | + # queries return values of 'str' type in Python2. When and if these quantities have a possibility |
| 96 | + # of representing unicode quantities, they can then go through a decode stage. |
| 97 | + |
| 98 | + encode_unless_PY3 = (lambda x:x) if PY3 else (lambda x:x.encode('utf8')) |
| 99 | + decode_unless_PY3 = (lambda x:x) if PY3 else (lambda x:x.decode('utf8')) |
| 100 | + |
93 | 101 | for result in query: |
94 | 102 | # check that we got back one of our original names |
95 | | - assert result[DataObject.name] in self.names |
| 103 | + assert result[DataObject.name] in ( [encode_unless_PY3(n) for n in self.names] ) |
96 | 104 |
|
97 | 105 | # fyi |
98 | | - logger.info( |
99 | | - u"{0}/{1}".format(result[Collection.name], result[DataObject.name])) |
| 106 | + logger.info( u"{0}/{1}".format( decode_unless_PY3(result[Collection.name]), |
| 107 | + decode_unless_PY3(result[DataObject.name]) ) |
| 108 | + ) |
100 | 109 |
|
101 | 110 | # remove from set |
102 | | - self.names.remove(result[DataObject.name]) |
| 111 | + self.names.remove(decode_unless_PY3(result[DataObject.name])) |
103 | 112 |
|
104 | 113 | # make sure we got all of them |
105 | 114 | self.assertEqual(0, len(self.names)) |
|
0 commit comments