1
1
import shlex
2
2
import subprocess
3
3
import time
4
+ import uuid
4
5
5
6
import pytest
6
7
@@ -54,13 +55,13 @@ def s3so(worker_id):
54
55
return {"client_kwargs" : {"endpoint_url" : url }}
55
56
56
57
57
- @pytest .fixture (scope = "session" )
58
+ @pytest .fixture (scope = "function" if is_ci_environment () else " session" )
58
59
def monkeysession ():
59
60
with pytest .MonkeyPatch .context () as mp :
60
61
yield mp
61
62
62
63
63
- @pytest .fixture (scope = "session" )
64
+ @pytest .fixture (scope = "function" if is_ci_environment () else " session" )
64
65
def s3_base (worker_id , monkeysession ):
65
66
"""
66
67
Fixture for mocking S3 interaction.
@@ -123,24 +124,67 @@ def s3_base(worker_id, monkeysession):
123
124
124
125
125
126
@pytest .fixture
126
- def s3_resource (s3_base , tips_file , jsonl_file , feather_file ):
127
- """
128
- Sets up S3 bucket with contents
127
+ def s3_resource (s3_base ):
128
+ import boto3
129
+
130
+ s3 = boto3 .resource ("s3" , endpoint_url = s3_base )
131
+ return s3
132
+
129
133
130
- The primary bucket name is "pandas-test". The following datasets
134
+ @pytest .fixture
135
+ def s3_public_bucket (s3_resource ):
136
+ bucket = s3_resource .Bucket (f"pandas-test-{ uuid .uuid4 ()} " )
137
+ bucket .create ()
138
+ yield bucket
139
+ bucket .objects .delete ()
140
+ bucket .delete ()
141
+
142
+
143
+ @pytest .fixture
144
+ def s3_public_bucket_with_data (s3_public_bucket , tips_file , jsonl_file , feather_file ):
145
+ """
146
+ The following datasets
131
147
are loaded.
132
148
133
149
- tips.csv
134
150
- tips.csv.gz
135
151
- tips.csv.bz2
136
152
- items.jsonl
153
+ """
154
+ test_s3_files = [
155
+ ("tips#1.csv" , tips_file ),
156
+ ("tips.csv" , tips_file ),
157
+ ("tips.csv.gz" , tips_file + ".gz" ),
158
+ ("tips.csv.bz2" , tips_file + ".bz2" ),
159
+ ("items.jsonl" , jsonl_file ),
160
+ ("simple_dataset.feather" , feather_file ),
161
+ ]
162
+ for s3_key , file_name in test_s3_files :
163
+ with open (file_name , "rb" ) as f :
164
+ s3_public_bucket .put_object (Key = s3_key , Body = f )
165
+ return s3_public_bucket
166
+
167
+
168
+ @pytest .fixture
169
+ def s3_private_bucket (s3_resource ):
170
+ bucket = s3_resource .Bucket (f"cant_get_it-{ uuid .uuid4 ()} " )
171
+ bucket .create (ACL = "private" )
172
+ yield bucket
173
+ bucket .objects .delete ()
174
+ bucket .delete ()
175
+
137
176
138
- A private bucket "cant_get_it" is also created. The boto3 s3 resource
139
- is yielded by the fixture.
177
+ @ pytest . fixture
178
+ def s3_private_bucket_with_data ( s3_private_bucket , tips_file , jsonl_file , feather_file ):
140
179
"""
141
- import boto3
142
- import s3fs
180
+ The following datasets
181
+ are loaded.
143
182
183
+ - tips.csv
184
+ - tips.csv.gz
185
+ - tips.csv.bz2
186
+ - items.jsonl
187
+ """
144
188
test_s3_files = [
145
189
("tips#1.csv" , tips_file ),
146
190
("tips.csv" , tips_file ),
@@ -149,50 +193,10 @@ def s3_resource(s3_base, tips_file, jsonl_file, feather_file):
149
193
("items.jsonl" , jsonl_file ),
150
194
("simple_dataset.feather" , feather_file ),
151
195
]
152
-
153
- def add_tips_files (bucket_name ):
154
- for s3_key , file_name in test_s3_files :
155
- with open (file_name , "rb" ) as f :
156
- cli .put_object (Bucket = bucket_name , Key = s3_key , Body = f )
157
-
158
- bucket = "pandas-test"
159
- conn = boto3 .resource ("s3" , endpoint_url = s3_base )
160
- cli = boto3 .client ("s3" , endpoint_url = s3_base )
161
-
162
- try :
163
- cli .create_bucket (Bucket = bucket )
164
- except Exception :
165
- # OK is bucket already exists
166
- pass
167
- try :
168
- cli .create_bucket (Bucket = "cant_get_it" , ACL = "private" )
169
- except Exception :
170
- # OK is bucket already exists
171
- pass
172
- timeout = 2
173
- while not cli .list_buckets ()["Buckets" ] and timeout > 0 :
174
- time .sleep (0.1 )
175
- timeout -= 0.1
176
-
177
- add_tips_files (bucket )
178
- add_tips_files ("cant_get_it" )
179
- s3fs .S3FileSystem .clear_instance_cache ()
180
- yield conn
181
-
182
- s3 = s3fs .S3FileSystem (client_kwargs = {"endpoint_url" : s3_base })
183
-
184
- try :
185
- s3 .rm (bucket , recursive = True )
186
- except Exception :
187
- pass
188
- try :
189
- s3 .rm ("cant_get_it" , recursive = True )
190
- except Exception :
191
- pass
192
- timeout = 2
193
- while cli .list_buckets ()["Buckets" ] and timeout > 0 :
194
- time .sleep (0.1 )
195
- timeout -= 0.1
196
+ for s3_key , file_name in test_s3_files :
197
+ with open (file_name , "rb" ) as f :
198
+ s3_private_bucket .put_object (Key = s3_key , Body = f )
199
+ return s3_private_bucket
196
200
197
201
198
202
_compression_formats_params = [
0 commit comments