1
1
import numpy as np
2
2
from numpy .testing import assert_array_equal
3
- from nose .tools import assert_true , assert_equal
4
3
from datajoint .external import ExternalTable
5
4
from datajoint .blob import pack , unpack
6
5
import datajoint as dj
7
- from .schema_external import stores_config , SimpleRemote , Simple , schema
6
+ from .schema_external import SimpleRemote , Simple
8
7
import os
9
8
10
- current_location_s3 = dj .config ["stores" ]["share" ]["location" ]
11
- current_location_local = dj .config ["stores" ]["local" ]["location" ]
12
9
13
-
14
- def setUp (self ):
15
- dj .config ["stores" ] = stores_config
16
-
17
-
18
- def tearDown (self ):
19
- dj .config ["stores" ]["share" ]["location" ] = current_location_s3
20
- dj .config ["stores" ]["local" ]["location" ] = current_location_local
21
-
22
-
23
- def test_external_put ():
10
+ def test_external_put (schema_ext , mock_stores , mock_cache ):
24
11
"""
25
12
external storage put and get and remove
26
13
"""
27
- ext = ExternalTable (schema .connection , store = "raw" , database = schema .database )
14
+ ext = ExternalTable (schema_ext .connection , store = "raw" , database = schema_ext .database )
28
15
initial_length = len (ext )
29
16
input_ = np .random .randn (3 , 7 , 8 )
30
17
count = 7
@@ -42,78 +29,84 @@ def test_external_put():
42
29
assert_array_equal (input_ , output_ )
43
30
44
31
45
- def test_s3_leading_slash (index = 100 , store = "share" ):
46
- """
47
- s3 external storage configured with leading slash
48
- """
32
+ class TestLeadingSlash :
33
+
34
+ def test_s3_leading_slash (self , schema_ext , mock_stores , mock_cache , minio_client ):
35
+ """
36
+ s3 external storage configured with leading slash
37
+ """
38
+ self ._leading_slash (schema_ext , index = 100 , store = "share" )
49
39
50
- oldConfig = dj .config ["stores" ][store ]["location" ]
40
+ def test_file_leading_slash (self , schema_ext , mock_stores , mock_cache , minio_client ):
41
+ """
42
+ File external storage configured with leading slash
43
+ """
44
+ self ._leading_slash (schema_ext , index = 200 , store = "local" )
51
45
52
- value = np .array ([1 , 2 , 3 ])
46
+ def _leading_slash (self , schema_ext , index , store ):
47
+ oldConfig = dj .config ["stores" ][store ]["location" ]
48
+ value = np .array ([1 , 2 , 3 ])
53
49
54
- id = index
55
- dj .config ["stores" ][store ]["location" ] = "leading/slash/test"
56
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
57
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
50
+ id = index
51
+ dj .config ["stores" ][store ]["location" ] = "leading/slash/test"
52
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
53
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
58
54
59
- id = index + 1
60
- dj .config ["stores" ][store ]["location" ] = "/leading/slash/test"
61
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
62
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
55
+ id = index + 1
56
+ dj .config ["stores" ][store ]["location" ] = "/leading/slash/test"
57
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
58
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
63
59
64
- id = index + 2
65
- dj .config ["stores" ][store ]["location" ] = "leading\\ slash\\ test"
66
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
67
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
60
+ id = index + 2
61
+ dj .config ["stores" ][store ]["location" ] = "leading\\ slash\\ test"
62
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
63
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
68
64
69
- id = index + 3
70
- dj .config ["stores" ][store ]["location" ] = "f:\\ leading\\ slash\\ test"
71
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
72
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
65
+ id = index + 3
66
+ dj .config ["stores" ][store ]["location" ] = "f:\\ leading\\ slash\\ test"
67
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
68
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
73
69
74
- id = index + 4
75
- dj .config ["stores" ][store ]["location" ] = "f:\\ leading/slash\\ test"
76
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
77
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
70
+ id = index + 4
71
+ dj .config ["stores" ][store ]["location" ] = "f:\\ leading/slash\\ test"
72
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
73
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
78
74
79
- id = index + 5
80
- dj .config ["stores" ][store ]["location" ] = "/"
81
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
82
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
75
+ id = index + 5
76
+ dj .config ["stores" ][store ]["location" ] = "/"
77
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
78
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
83
79
84
- id = index + 6
85
- dj .config ["stores" ][store ]["location" ] = "C:\\ "
86
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
87
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
80
+ id = index + 6
81
+ dj .config ["stores" ][store ]["location" ] = "C:\\ "
82
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
83
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
88
84
89
- id = index + 7
90
- dj .config ["stores" ][store ]["location" ] = ""
91
- SimpleRemote .insert ([{"simple" : id , "item" : value }])
92
- assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
85
+ id = index + 7
86
+ dj .config ["stores" ][store ]["location" ] = ""
87
+ SimpleRemote .insert ([{"simple" : id , "item" : value }])
88
+ assert np .array_equal (value , (SimpleRemote & "simple={}" .format (id )).fetch1 ("item" ))
93
89
94
- dj .config ["stores" ][store ]["location" ] = oldConfig
90
+ dj .config ["stores" ][store ]["location" ] = oldConfig
95
91
96
92
97
- def test_file_leading_slash ( ):
93
+ def test_remove_fail ( schema_ext , mock_stores , mock_cache , minio_client ):
98
94
"""
99
- file external storage configured with leading slash
95
+ https://github.com/datajoint/datajoint-python/issues/953
100
96
"""
101
- test_s3_leading_slash ( index = 200 , store = " local")
97
+ assert dj . config [ "stores" ][ " local"][ "location" ]
102
98
103
-
104
- def test_remove_fail ():
105
- # https://github.com/datajoint/datajoint-python/issues/953
106
99
data = dict (simple = 2 , item = [1 , 2 , 3 ])
107
100
Simple .insert1 (data )
108
101
path1 = dj .config ["stores" ]["local" ]["location" ] + "/djtest_extern/4/c/"
109
102
currentMode = int (oct (os .stat (path1 ).st_mode ), 8 )
110
103
os .chmod (path1 , 0o40555 )
111
104
(Simple & "simple=2" ).delete ()
112
- listOfErrors = schema .external ["local" ].delete (delete_external_files = True )
113
- assert len ( listOfErrors ) == 1 , "unexpected number of errors"
105
+ listOfErrors = schema_ext .external ["local" ].delete (delete_external_files = True )
106
+
114
107
assert (
115
- len (schema .external ["local" ] & dict (hash = listOfErrors [0 ][0 ])) == 1
108
+ len (schema_ext .external ["local" ] & dict (hash = listOfErrors [0 ][0 ])) == 1
116
109
), "unexpected number of rows in external table"
117
110
# ---------------------CLEAN UP--------------------
118
111
os .chmod (path1 , currentMode )
119
- listOfErrors = schema .external ["local" ].delete (delete_external_files = True )
112
+ listOfErrors = schema_ext .external ["local" ].delete (delete_external_files = True )
0 commit comments