77from .schema_external import schema
88import datajoint as dj
99from .schema_external import stores_config
10+ from .schema_external import SimpleRemote
11+ current_location_s3 = dj .config ['stores' ]['share' ]['location' ]
12+ current_location_local = dj .config ['stores' ]['local' ]['location' ]
1013
1114
1215def setUp (self ):
1316 dj .config ['stores' ] = stores_config
1417
1518
19+ def tearDown (self ):
20+ dj .config ['stores' ]['share' ]['location' ] = current_location_s3
21+ dj .config ['stores' ]['local' ]['location' ] = current_location_local
22+
23+
1624def test_external_put ():
1725 """
1826 external storage put and get and remove
@@ -33,3 +41,65 @@ def test_external_put():
3341
3442 output_ = unpack (ext .get (hash1 ))
3543 assert_array_equal (input_ , output_ )
44+
45+
46+ def test_s3_leading_slash (index = 100 , store = 'share' ):
47+ """
48+ s3 external storage configured with leading slash
49+ """
50+ value = np .array ([1 , 2 , 3 ])
51+
52+ id = index
53+ dj .config ['stores' ][store ]['location' ] = 'leading/slash/test'
54+ SimpleRemote .insert ([{'simple' : id , 'item' : value }])
55+ assert_true (np .array_equal (
56+ value , (SimpleRemote & 'simple={}' .format (id )).fetch1 ('item' )))
57+
58+ id = index + 1
59+ dj .config ['stores' ][store ]['location' ] = '/leading/slash/test'
60+ SimpleRemote .insert ([{'simple' : id , 'item' : value }])
61+ assert_true (np .array_equal (
62+ value , (SimpleRemote & 'simple={}' .format (id )).fetch1 ('item' )))
63+
64+ id = index + 2
65+ dj .config ['stores' ][store ]['location' ] = 'leading\\ slash\\ test'
66+ SimpleRemote .insert ([{'simple' : id , 'item' : value }])
67+ assert_true (np .array_equal (
68+ value , (SimpleRemote & 'simple={}' .format (id )).fetch1 ('item' )))
69+
70+ id = index + 3
71+ dj .config ['stores' ][store ]['location' ] = 'f:\\ leading\\ slash\\ test'
72+ SimpleRemote .insert ([{'simple' : id , 'item' : value }])
73+ assert_true (np .array_equal (
74+ value , (SimpleRemote & 'simple={}' .format (id )).fetch1 ('item' )))
75+
76+ id = index + 4
77+ dj .config ['stores' ][store ]['location' ] = 'f:\\ leading/slash\\ test'
78+ SimpleRemote .insert ([{'simple' : id , 'item' : value }])
79+ assert_true (np .array_equal (
80+ 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