98 lines
3.2 KiB
Diff
98 lines
3.2 KiB
Diff
From e73d4d29203dab20e001beb1090d07683de583d6 Mon Sep 17 00:00:00 2001
|
|
From: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
|
|
Date: Sat, 28 Jan 2023 08:37:26 -0500
|
|
Subject: [PATCH] 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 <47963215+lithomas1@users.noreply.github.com>
|
|
---
|
|
pandas/tests/io/test_fsspec.py | 2 --
|
|
pandas/tests/io/test_gcs.py | 24 +++++-------------------
|
|
2 files changed, 5 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/pandas/tests/io/test_fsspec.py b/pandas/tests/io/test_fsspec.py
|
|
index 4f033fd63f978..fd1b30eca449e 100644
|
|
--- a/pandas/tests/io/test_fsspec.py
|
|
+++ b/pandas/tests/io/test_fsspec.py
|
|
@@ -50,10 +50,8 @@ def test_read_csv(cleared_fs, df1):
|
|
|
|
|
|
def test_reasonable_error(monkeypatch, cleared_fs):
|
|
- from fsspec import registry
|
|
from fsspec.registry import known_implementations
|
|
|
|
- registry.target.clear()
|
|
with pytest.raises(ValueError, match="nosuchprotocol"):
|
|
read_csv("nosuchprotocol://test/test.csv")
|
|
err_msg = "test error message"
|
|
diff --git a/pandas/tests/io/test_gcs.py b/pandas/tests/io/test_gcs.py
|
|
index 6907d8978e603..538969b7e226c 100644
|
|
--- a/pandas/tests/io/test_gcs.py
|
|
+++ b/pandas/tests/io/test_gcs.py
|
|
@@ -22,17 +22,12 @@
|
|
@pytest.fixture
|
|
def gcs_buffer(monkeypatch):
|
|
"""Emulate GCS using a binary buffer."""
|
|
- from fsspec import (
|
|
- AbstractFileSystem,
|
|
- registry,
|
|
- )
|
|
-
|
|
- registry.target.clear() # remove state
|
|
+ import fsspec
|
|
|
|
gcs_buffer = BytesIO()
|
|
gcs_buffer.close = lambda: True
|
|
|
|
- class MockGCSFileSystem(AbstractFileSystem):
|
|
+ class MockGCSFileSystem(fsspec.AbstractFileSystem):
|
|
def open(*args, **kwargs):
|
|
gcs_buffer.seek(0)
|
|
return gcs_buffer
|
|
@@ -41,7 +36,8 @@ def ls(self, path, **kwargs):
|
|
# needed for pyarrow
|
|
return [{"name": path, "type": "file"}]
|
|
|
|
- monkeypatch.setattr("gcsfs.GCSFileSystem", MockGCSFileSystem)
|
|
+ # Overwrites the default implementation from gcsfs to our mock class
|
|
+ fsspec.register_implementation("gs", MockGCSFileSystem, clobber=True)
|
|
|
|
return gcs_buffer
|
|
|
|
@@ -54,9 +50,6 @@ def test_to_read_gcs(gcs_buffer, format):
|
|
|
|
GH 33987
|
|
"""
|
|
- from fsspec import registry
|
|
-
|
|
- registry.target.clear() # remove state
|
|
|
|
df1 = DataFrame(
|
|
{
|
|
@@ -131,9 +124,6 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
|
|
GH 35677 (to_csv, compression), GH 26124 (to_csv, encoding), and
|
|
GH 32392 (read_csv, encoding)
|
|
"""
|
|
- from fsspec import registry
|
|
-
|
|
- registry.target.clear() # remove state
|
|
df = tm.makeDataFrame()
|
|
|
|
# reference of compressed and encoded file
|
|
@@ -173,12 +163,8 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
|
|
@td.skip_if_no("gcsfs")
|
|
def test_to_parquet_gcs_new_file(monkeypatch, tmpdir):
|
|
"""Regression test for writing to a not-yet-existent GCS Parquet file."""
|
|
- from fsspec import (
|
|
- AbstractFileSystem,
|
|
- registry,
|
|
- )
|
|
+ from fsspec import AbstractFileSystem
|
|
|
|
- registry.target.clear() # remove state
|
|
df1 = DataFrame(
|
|
{
|
|
"int": [1, 3],
|