22
22
@pytest .fixture
23
23
def gcs_buffer (monkeypatch ):
24
24
"""Emulate GCS using a binary buffer."""
25
- from fsspec import (
26
- AbstractFileSystem ,
27
- registry ,
28
- )
29
-
30
- registry .target .clear () # remove state
25
+ import fsspec
31
26
32
27
gcs_buffer = BytesIO ()
33
28
gcs_buffer .close = lambda : True
34
29
35
- class MockGCSFileSystem (AbstractFileSystem ):
30
+ class MockGCSFileSystem (fsspec . AbstractFileSystem ):
36
31
def open (* args , ** kwargs ):
37
32
gcs_buffer .seek (0 )
38
33
return gcs_buffer
@@ -41,7 +36,8 @@ def ls(self, path, **kwargs):
41
36
# needed for pyarrow
42
37
return [{"name" : path , "type" : "file" }]
43
38
44
- monkeypatch .setattr ("gcsfs.GCSFileSystem" , MockGCSFileSystem )
39
+ # Overwrites the default implementation from gcsfs to our mock class
40
+ fsspec .register_implementation ("gs" , MockGCSFileSystem , clobber = True )
45
41
46
42
return gcs_buffer
47
43
@@ -54,9 +50,6 @@ def test_to_read_gcs(gcs_buffer, format):
54
50
55
51
GH 33987
56
52
"""
57
- from fsspec import registry
58
-
59
- registry .target .clear () # remove state
60
53
61
54
df1 = DataFrame (
62
55
{
@@ -131,9 +124,6 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
131
124
GH 35677 (to_csv, compression), GH 26124 (to_csv, encoding), and
132
125
GH 32392 (read_csv, encoding)
133
126
"""
134
- from fsspec import registry
135
-
136
- registry .target .clear () # remove state
137
127
df = tm .makeDataFrame ()
138
128
139
129
# reference of compressed and encoded file
@@ -173,12 +163,8 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
173
163
@td .skip_if_no ("gcsfs" )
174
164
def test_to_parquet_gcs_new_file (monkeypatch , tmpdir ):
175
165
"""Regression test for writing to a not-yet-existent GCS Parquet file."""
176
- from fsspec import (
177
- AbstractFileSystem ,
178
- registry ,
179
- )
166
+ from fsspec import AbstractFileSystem
180
167
181
- registry .target .clear () # remove state
182
168
df1 = DataFrame (
183
169
{
184
170
"int" : [1 , 3 ],
0 commit comments