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