Skip to content

Commit b5876c8

Browse files
Add file storage tests.
1 parent 8573ef3 commit b5876c8

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

datajoint/external.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ def _make_external_filepath(self, relative_filepath):
7878
if self.spec['protocol'] == 's3':
7979
posix_path = PurePosixPath(PureWindowsPath(self.spec['location']))
8080
location_path = Path(
81-
*posix_path.parts[1:]) if any(
82-
case in posix_path.parts[0] for case in (
83-
'\\', ':')) else Path(posix_path)
81+
*posix_path.parts[1:]) if len(
82+
self.spec['location']) > 0 and any(
83+
case in posix_path.parts[0] for case in (
84+
'\\', ':')) else Path(posix_path)
8485
return PurePosixPath(location_path, relative_filepath)
8586
# Preserve root
8687
elif self.spec['protocol'] == 'file':

tests/test_external.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
import datajoint as dj
99
from .schema_external import stores_config
1010
from .schema_external import SimpleRemote
11-
current_location = dj.config['stores']['share']['location']
11+
current_location_s3 = dj.config['stores']['share']['location']
12+
current_location_local = dj.config['stores']['local']['location']
1213

1314

1415
def setUp(self):
1516
dj.config['stores'] = stores_config
1617

1718

1819
def tearDown(self):
19-
dj.config['stores']['share']['location'] = current_location
20+
dj.config['stores']['share']['location'] = current_location_s3
21+
dj.config['stores']['local']['location'] = current_location_local
2022

2123

2224
def test_external_put():
@@ -41,38 +43,63 @@ def test_external_put():
4143
assert_array_equal(input_, output_)
4244

4345

44-
def test_leading_slash():
46+
def test_s3_leading_slash(index=100, store='share'):
4547
"""
46-
external storage configured with leading slash
48+
s3 external storage configured with leading slash
4749
"""
4850
value = np.array([1, 2, 3])
4951

50-
id = 100
51-
dj.config['stores']['share']['location'] = 'leading/slash/test'
52+
id = index
53+
dj.config['stores'][store]['location'] = 'leading/slash/test'
5254
SimpleRemote.insert([{'simple': id, 'item': value}])
5355
assert_true(np.array_equal(
5456
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
5557

56-
id = 101
57-
dj.config['stores']['share']['location'] = '/leading/slash/test'
58+
id = index + 1
59+
dj.config['stores'][store]['location'] = '/leading/slash/test'
5860
SimpleRemote.insert([{'simple': id, 'item': value}])
5961
assert_true(np.array_equal(
6062
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
6163

62-
id = 102
63-
dj.config['stores']['share']['location'] = 'leading\\slash\\test'
64+
id = index + 2
65+
dj.config['stores'][store]['location'] = 'leading\\slash\\test'
6466
SimpleRemote.insert([{'simple': id, 'item': value}])
6567
assert_true(np.array_equal(
6668
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
6769

68-
id = 103
69-
dj.config['stores']['share']['location'] = 'f:\\leading\\slash\\test'
70+
id = index + 3
71+
dj.config['stores'][store]['location'] = 'f:\\leading\\slash\\test'
7072
SimpleRemote.insert([{'simple': id, 'item': value}])
7173
assert_true(np.array_equal(
7274
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
7375

74-
id = 104
75-
dj.config['stores']['share']['location'] = 'f:\\leading/slash\\test'
76+
id = index + 4
77+
dj.config['stores'][store]['location'] = 'f:\\leading/slash\\test'
7678
SimpleRemote.insert([{'simple': id, 'item': value}])
7779
assert_true(np.array_equal(
7880
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
81+
82+
id = index + 5
83+
dj.config['stores'][store]['location'] = '/'
84+
SimpleRemote.insert([{'simple': id, 'item': value}])
85+
assert_true(np.array_equal(
86+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
87+
88+
id = index + 6
89+
dj.config['stores'][store]['location'] = 'C:\\'
90+
SimpleRemote.insert([{'simple': id, 'item': value}])
91+
assert_true(np.array_equal(
92+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
93+
94+
id = index + 7
95+
dj.config['stores'][store]['location'] = ''
96+
SimpleRemote.insert([{'simple': id, 'item': value}])
97+
assert_true(np.array_equal(
98+
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))
99+
100+
101+
def test_file_leading_slash():
102+
"""
103+
file external storage configured with leading slash
104+
"""
105+
test_s3_leading_slash(index=200, store='local')

0 commit comments

Comments
 (0)