Skip to content

Commit

Permalink
[#221] fix tests which were failing in Py3.4 and 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
d-w-moore authored and trel committed Oct 19, 2020
1 parent bfd10d6 commit 14ef665
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion irods/test/login_auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
from irods.password_obfuscation import (encode as pw_encode)
from irods.connection import PlainTextPAMPasswordError
import contextlib
from re import (compile as regex,_pattern_type as regex_type)
from re import compile as regex
try:
from re import _pattern_type as regex_type
except ImportError:
from re import Pattern as regex_type # Python 3.7+


def json_file_update(fname,keys_to_delete=(),**kw):
Expand Down
23 changes: 18 additions & 5 deletions irods/test/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
import unittest
import time
import uuid
from datetime import datetime
from irods.models import (User, UserMeta,
Resource, ResourceMeta,
Expand Down Expand Up @@ -313,6 +314,7 @@ def test_multiple_criteria_on_one_column_name(self):
@unittest.skipIf(six.PY3, 'Test is for python2 only')
def test_query_for_data_object_with_utf8_name_python2(self):
filename_prefix = '_prefix_ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸ'
self.assertEqual(self.FILENAME_PREFIX.encode('utf-8'), filename_prefix)
_,test_file = tempfile.mkstemp(prefix=filename_prefix)
obj_path = os.path.join(self.coll.path, os.path.basename(test_file))
try:
Expand All @@ -326,25 +328,36 @@ def test_query_for_data_object_with_utf8_name_python2(self):
self.sess.data_objects.unregister(obj_path)
os.remove(test_file)

# view/change this line in text editors under own risk:
FILENAME_PREFIX = u'_prefix_ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸ'

@unittest.skipIf(six.PY2, 'Test is for python3 only')
def test_query_for_data_object_with_utf8_name_python3(self):
filename_prefix = u'_prefix_ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰDZDzdzǴǵǶǷǸ'
_,encoded_test_file = tempfile.mkstemp(prefix=filename_prefix.encode('utf-8'))
def python34_unicode_mkstemp( prefix, dir = None, open_mode = 0o777 ):
file_path = os.path.join ((dir or os.environ.get('TMPDIR') or '/tmp'), prefix+'-'+str(uuid.uuid1()))
encoded_file_path = file_path.encode('utf-8')
return os.open(encoded_file_path,os.O_CREAT|os.O_RDWR,mode=open_mode), encoded_file_path
fd = None
filename_prefix = u'_prefix_'\
u'\u01e0\u01e1\u01e2\u01e3\u01e4\u01e5\u01e6\u01e7\u01e8\u01e9\u01ea\u01eb\u01ec\u01ed\u01ee\u01ef'\
u'\u01f0\u01f1\u01f2\u01f3\u01f4\u01f5\u01f6\u01f7\u01f8' # make more visible/changeable in VIM
self.assertEqual(self.FILENAME_PREFIX, filename_prefix)
(fd,encoded_test_file) = tempfile.mkstemp(prefix=filename_prefix.encode('utf-8')) \
if sys.version_info >= (3,5) \
else python34_unicode_mkstemp(prefix = filename_prefix)
self.assertTrue(os.path.exists(encoded_test_file))

test_file = encoded_test_file.decode('utf-8')
obj_path = os.path.join(self.coll.path, os.path.basename(test_file))

try:
self.sess.data_objects.register(test_file, obj_path)

results = self.sess.query(DataObject, Collection.name).filter(DataObject.path == test_file).first()
result_logical_path = os.path.join(results[Collection.name], results[DataObject.name])
result_physical_path = results[DataObject.path]
self.assertEqual(result_logical_path, obj_path)
self.assertEqual(result_physical_path, test_file)
finally:
self.sess.data_objects.unregister(obj_path)
if fd is not None: os.close(fd)
os.remove(encoded_test_file)

class Issue_166_context:
Expand Down

0 comments on commit 14ef665

Please sign in to comment.