Skip to content

Commit e73d4d2

Browse files
phofllithomas1
andauthored
Backport PR #50925 on branch 1.5.x (TST: Remove fsspec internals from tests) (#51038)
TST: Remove fsspec internals from tests (#50925) Co-authored-by: Thomas Li <[email protected]>
1 parent 3ae2de9 commit e73d4d2

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

pandas/tests/io/test_fsspec.py

-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ def test_read_csv(cleared_fs, df1):
5050

5151

5252
def test_reasonable_error(monkeypatch, cleared_fs):
53-
from fsspec import registry
5453
from fsspec.registry import known_implementations
5554

56-
registry.target.clear()
5755
with pytest.raises(ValueError, match="nosuchprotocol"):
5856
read_csv("nosuchprotocol://test/test.csv")
5957
err_msg = "test error message"

pandas/tests/io/test_gcs.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@
2222
@pytest.fixture
2323
def gcs_buffer(monkeypatch):
2424
"""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
3126

3227
gcs_buffer = BytesIO()
3328
gcs_buffer.close = lambda: True
3429

35-
class MockGCSFileSystem(AbstractFileSystem):
30+
class MockGCSFileSystem(fsspec.AbstractFileSystem):
3631
def open(*args, **kwargs):
3732
gcs_buffer.seek(0)
3833
return gcs_buffer
@@ -41,7 +36,8 @@ def ls(self, path, **kwargs):
4136
# needed for pyarrow
4237
return [{"name": path, "type": "file"}]
4338

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)
4541

4642
return gcs_buffer
4743

@@ -54,9 +50,6 @@ def test_to_read_gcs(gcs_buffer, format):
5450
5551
GH 33987
5652
"""
57-
from fsspec import registry
58-
59-
registry.target.clear() # remove state
6053

6154
df1 = DataFrame(
6255
{
@@ -131,9 +124,6 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
131124
GH 35677 (to_csv, compression), GH 26124 (to_csv, encoding), and
132125
GH 32392 (read_csv, encoding)
133126
"""
134-
from fsspec import registry
135-
136-
registry.target.clear() # remove state
137127
df = tm.makeDataFrame()
138128

139129
# reference of compressed and encoded file
@@ -173,12 +163,8 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
173163
@td.skip_if_no("gcsfs")
174164
def test_to_parquet_gcs_new_file(monkeypatch, tmpdir):
175165
"""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
180167

181-
registry.target.clear() # remove state
182168
df1 = DataFrame(
183169
{
184170
"int": [1, 3],

0 commit comments

Comments
 (0)