Skip to content

Commit 4f686b9

Browse files
d-w-mooretrel
authored andcommitted
[#3] fix failing tests
- Correct DEST_RESC (vs. RESC) oversights in irods/irods#5848 related tests. - Correct tests failing for QUASI_XML under Python2. - instances of fix Python 2 / unicode mismatch causing tests to fail.
1 parent 64270b3 commit 4f686b9

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

irods/test/data_obj_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def write_and_check_replica_on_parallel_connections( self, data_object_path, roo
123123
Then we assert the file contents and dispose of the data object."""
124124

125125
try:
126-
self.sess.data_objects.create(data_object_path, **{kw.RESC_NAME_KW: root_resc} )
126+
self.sess.data_objects.create(data_object_path, resource = root_resc)
127127
for _ in range( seconds_to_wait_for_replicas ):
128128
if required_num_replicas <= len( self.sess.data_objects.get(data_object_path).replicas ): break
129129
time.sleep(1)
@@ -137,7 +137,7 @@ def write_and_check_replica_on_parallel_connections( self, data_object_path, roo
137137
fd1.write(b'book')
138138
fd2.close()
139139
fd1.close()
140-
with self.sess.data_objects.open(data_object_path, 'r', **{kw.RESC_NAME_KW: root_resc} ) as f:
140+
with self.sess.data_objects.open(data_object_path, 'r', **{kw.DEST_RESC_NAME_KW: root_resc} ) as f:
141141
self.assertEqual(f.read(), b'books\n')
142142
except Exception as e:
143143
logging.debug('Exception %r in [%s], called from [%s]', e, my_function_name(), caller_func)

irods/test/meta_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from irods.models import (DataObject, Collection, Resource)
1010
import irods.test.helpers as helpers
1111
from six.moves import range
12+
from six import PY3
1213

1314

1415
class TestMeta(unittest.TestCase):
@@ -165,7 +166,8 @@ def getKey(AVU):
165166
assert meta[1].units == self.unit1
166167

167168
assert meta[2].name == attribute
168-
assert meta[2].value == value
169+
testValue = (value if PY3 else value.encode('utf8'))
170+
assert meta[2].value == testValue
169171

170172

171173
def test_add_obj_meta_empty(self):

irods/test/query_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ def test_query_for_data_object_with_utf8_name_python2(self):
369369
results = self.sess.query(DataObject, Collection.name).filter(DataObject.path == test_file).first()
370370
result_logical_path = os.path.join(results[Collection.name], results[DataObject.name])
371371
result_physical_path = results[DataObject.path]
372-
self.assertEqual(result_logical_path, obj_path.decode('utf8'))
373-
self.assertEqual(result_physical_path, test_file.decode('utf8'))
372+
self.assertEqual(result_logical_path, obj_path)
373+
self.assertEqual(result_physical_path, test_file)
374374
finally:
375375
if results: self.sess.data_objects.unregister(obj_path)
376376
os.remove(test_file)

irods/test/unicode_test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from irods.message import (ET as ET_set, XML_Parser_Type, current_XML_parser, default_XML_parser)
1010
import logging
1111
import irods.test.helpers as helpers
12+
from six import PY3
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -90,16 +91,24 @@ def test_files(self):
9091
query = self.sess.query(DataObject.name, Collection.name).filter(
9192
Collection.name == self.coll_path)
9293

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+
93101
for result in query:
94102
# 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] )
96104

97105
# 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+
)
100109

101110
# remove from set
102-
self.names.remove(result[DataObject.name])
111+
self.names.remove(decode_unless_PY3(result[DataObject.name]))
103112

104113
# make sure we got all of them
105114
self.assertEqual(0, len(self.names))

0 commit comments

Comments
 (0)