Skip to content

Commit e4022e1

Browse files
fix 3.4 compatibility issues
1 parent c27332b commit e4022e1

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

datajoint/connection.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
client_errors = (client.err.InterfaceError, client.err.DatabaseError)
1717

1818

19-
def translate_query_error(client_error, query, args):
19+
def translate_query_error(client_error, query):
2020
"""
2121
Take client error and original query and return the corresponding DataJoint exception.
2222
:param client_error: the exception raised by the client interface
2323
:param query: sql query with placeholders
24-
:param args: values for query placeholders
2524
:return: an instance of the corresponding subclass of datajoint.errors.DataJointError
2625
"""
2726
# Loss of connection errors
@@ -34,20 +33,20 @@ def translate_query_error(client_error, query, args):
3433
return errors.LostConnectionError(disconnect_codes[client_error.args[0]], *client_error.args[1:])
3534
# Access errors
3635
if isinstance(client_error, client.err.OperationalError) and client_error.args[0] in (1044, 1142):
37-
return errors.AccessError('Insufficient privileges.', *client_error.args[1:], query)
36+
return errors.AccessError('Insufficient privileges.', client_error.args[1], query)
3837
# Integrity errors
3938
if isinstance(client_error, client.err.IntegrityError) and client_error.args[0] == 1062:
4039
return errors.DuplicateError(*client_error.args[1:])
4140
if isinstance(client_error, client.err.IntegrityError) and client_error.args[0] == 1452:
4241
return errors.IntegrityError(*client_error.args[1:])
4342
# Syntax Errors
4443
if isinstance(client_error, client.err.ProgrammingError) and client_error.args[0] == 1064:
45-
return errors.QuerySyntaxError(*client_error.args[1:], query)
44+
return errors.QuerySyntaxError(client_error.args[1], query)
4645
# Existence Errors
4746
if isinstance(client_error, client.err.ProgrammingError) and client_error.args[0] == 1146:
48-
return errors.MissingTableError(*args[1:], query)
47+
return errors.MissingTableError(client_error.args[1], query)
4948
if isinstance(client_error, client.err.InternalError) and client_error.args[0] == 1364:
50-
return errors.MissingAttributeError(*args[1:])
49+
return errors.MissingAttributeError(*client_error.args[1:])
5150
raise client_error
5251

5352

@@ -188,7 +187,7 @@ def __execute_query(cursor, query, args, cursor_class, suppress_warnings):
188187
warnings.simplefilter("ignore")
189188
cursor.execute(query, args)
190189
except client_errors as err:
191-
raise translate_query_error(err, query, args)
190+
raise translate_query_error(err, query)
192191

193192
def query(self, query, args=(), *, as_dict=False, suppress_warnings=True, reconnect=None):
194193
"""

tests/__init__.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from distutils.version import LooseVersion
1212
import os
1313
from pathlib import Path
14-
from minio import Minio
14+
import minio
1515
import urllib3
1616
import certifi
1717
import shutil
@@ -96,11 +96,12 @@
9696
)
9797

9898
# Initialize minioClient with an endpoint and access/secret keys.
99-
minioClient = Minio(S3_CONN_INFO['endpoint'],
100-
access_key=S3_CONN_INFO['access_key'],
101-
secret_key=S3_CONN_INFO['secret_key'],
102-
secure=False,
103-
http_client=httpClient)
99+
minioClient = minio.Minio(
100+
S3_CONN_INFO['endpoint'],
101+
access_key=S3_CONN_INFO['access_key'],
102+
secret_key=S3_CONN_INFO['secret_key'],
103+
secure=False,
104+
http_client=httpClient)
104105

105106

106107
def setup_package():
@@ -128,7 +129,10 @@ def setup_package():
128129
"/external-legacy-data/s3"
129130
bucket = "migrate-test"
130131
region = "us-east-1"
131-
minioClient.make_bucket(bucket, location=region)
132+
try:
133+
minioClient.make_bucket(bucket, location=region)
134+
except minio.error.BucketAlreadyOwnedByYou:
135+
pass
132136

133137
pathlist = Path(source).glob('**/*')
134138
for path in pathlist:
@@ -138,15 +142,20 @@ def setup_package():
138142
str(path),
139143
'{}/{}'.format(source, bucket)
140144
), str(path))
141-
142145
# Add S3
143-
minioClient.make_bucket("datajoint-test", location=region)
146+
try:
147+
minioClient.make_bucket("datajoint-test", location=region)
148+
except minio.error.BucketAlreadyOwnedByYou:
149+
pass
144150

145151
# Add old File Content
146-
shutil.copytree(
147-
os.path.dirname(os.path.realpath(__file__)) +
148-
"/external-legacy-data/file/temp",
149-
os.path.expanduser('~/temp'))
152+
try:
153+
shutil.copytree(
154+
os.path.dirname(os.path.realpath(__file__)) +
155+
"/external-legacy-data/file/temp",
156+
os.path.expanduser('~/temp'))
157+
except FileExistsError:
158+
pass
150159

151160

152161
def teardown_package():

tests/test_relation.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55
from nose.tools import assert_equal, assert_not_equal, assert_true, assert_list_equal, raises
66
import datajoint as dj
7-
from datajoint import utils, DataJointError
87
from datajoint.table import Table
98
from unittest.mock import patch
109

@@ -189,7 +188,7 @@ def test_skip_duplicate(self):
189188
dtype=self.subject.heading.as_dtype)
190189
self.subject.insert(tmp, skip_duplicates=True)
191190

192-
@raises(DataJointError)
191+
@raises(dj.errors.DuplicateError)
193192
def test_not_skip_duplicate(self):
194193
"""Tests if duplicates are not skipped."""
195194
tmp = np.array([
@@ -199,7 +198,7 @@ def test_not_skip_duplicate(self):
199198
dtype=self.subject.heading.as_dtype)
200199
self.subject.insert(tmp, skip_duplicates=False)
201200

202-
@raises(dj.DataJointError)
201+
@raises(dj.errors.MissingAttributeError)
203202
def test_no_error_suppression(self):
204203
"""skip_duplicates=True should not suppress other errors"""
205204
self.test.insert([dict(key=100)], skip_duplicates=True)
@@ -211,12 +210,12 @@ def test_blob_insert(self):
211210
Y = self.img.fetch()[0]['img']
212211
assert_true(np.all(X == Y), 'Inserted and retrieved image are not identical')
213212

214-
@raises(DataJointError)
213+
@raises(dj.DataJointError)
215214
def test_drop(self):
216215
"""Tests dropping tables"""
217216
dj.config['safemode'] = True
218217
try:
219-
with patch.object(utils, "input", create=True, return_value='yes'):
218+
with patch.object(dj.utils, "input", create=True, return_value='yes'):
220219
self.trash.drop()
221220
except:
222221
pass

0 commit comments

Comments
 (0)