11import numpy as np
22from numpy .testing import assert_array_equal
3- from nose .tools import assert_true , assert_equal
43from datajoint .external import ExternalTable
54from datajoint .blob import pack , unpack
65import datajoint as dj
7- from .schema_external import stores_config , SimpleRemote , Simple , schema
6+ from .schema_external import SimpleRemote , Simple
87import os
98
10- current_location_s3 = dj .config ["stores" ]["share" ]["location" ]
11- current_location_local = dj .config ["stores" ]["local" ]["location" ]
129
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 ):
2411 """
2512 external storage put and get and remove
2613 """
27- ext = ExternalTable (schema .connection , store = "raw" , database = schema .database )
14+ ext = ExternalTable (schema_ext .connection , store = "raw" , database = schema_ext .database )
2815 initial_length = len (ext )
2916 input_ = np .random .randn (3 , 7 , 8 )
3017 count = 7
@@ -42,78 +29,84 @@ def test_external_put():
4229 assert_array_equal (input_ , output_ )
4330
4431
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" )
4939
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" )
5145
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 ])
5349
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" ))
5854
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" ))
6359
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" ))
6864
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" ))
7369
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" ))
7874
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" ))
8379
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" ))
8884
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" ))
9389
94- dj .config ["stores" ][store ]["location" ] = oldConfig
90+ dj .config ["stores" ][store ]["location" ] = oldConfig
9591
9692
97- def test_file_leading_slash ( ):
93+ def test_remove_fail ( schema_ext , mock_stores , mock_cache , minio_client ):
9894 """
99- file external storage configured with leading slash
95+ https://github.com/datajoint/datajoint-python/issues/953
10096 """
101- test_s3_leading_slash ( index = 200 , store = " local")
97+ assert dj . config [ "stores" ][ " local"][ "location" ]
10298
103-
104- def test_remove_fail ():
105- # https://github.com/datajoint/datajoint-python/issues/953
10699 data = dict (simple = 2 , item = [1 , 2 , 3 ])
107100 Simple .insert1 (data )
108101 path1 = dj .config ["stores" ]["local" ]["location" ] + "/djtest_extern/4/c/"
109102 currentMode = int (oct (os .stat (path1 ).st_mode ), 8 )
110103 os .chmod (path1 , 0o40555 )
111104 (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+
114107 assert (
115- len (schema .external ["local" ] & dict (hash = listOfErrors [0 ][0 ])) == 1
108+ len (schema_ext .external ["local" ] & dict (hash = listOfErrors [0 ][0 ])) == 1
116109 ), "unexpected number of rows in external table"
117110 # ---------------------CLEAN UP--------------------
118111 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