diff --git a/adlfs/spec.py b/adlfs/spec.py index db17e81c..513882de 100644 --- a/adlfs/spec.py +++ b/adlfs/spec.py @@ -1841,9 +1841,10 @@ def _open( cache_type=cache_type, metadata=metadata, version_id=version_id, - **kwargs, + **kwargs, ) + class AzureBlobFile(AbstractBufferedFile): """File-like operations on Azure Blobs""" @@ -1915,7 +1916,7 @@ def __init__( else None ) - self.loop = self._get_loop() + self.loop = self._get_loop() self.container_client = self._get_container_client() self.blocksize = ( self.DEFAULT_BLOCK_SIZE if block_size in ["default", None] else block_size @@ -2187,13 +2188,13 @@ def __del__(self): self.close() except TypeError: pass - + def __getstate__(self): state = self.__dict__.copy() - del state['container_client'] - del state['loop'] + del state["container_client"] + del state["loop"] return state - + def __setstate__(self, state): self.__dict__.update(state) self.loop = self._get_loop() diff --git a/adlfs/tests/test_pickling.py b/adlfs/tests/test_pickling.py index 5bcb41da..4e46d14f 100644 --- a/adlfs/tests/test_pickling.py +++ b/adlfs/tests/test_pickling.py @@ -1,31 +1,32 @@ import pickle -import pytest -from adlfs import AzureBlobFileSystem, AzureBlobFile -import asyncio + +from adlfs import AzureBlobFileSystem URL = "http://127.0.0.1:10000" ACCOUNT_NAME = "devstoreaccount1" KEY = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" # NOQA CONN_STR = f"DefaultEndpointsProtocol=http;AccountName={ACCOUNT_NAME};AccountKey={KEY};BlobEndpoint={URL}/{ACCOUNT_NAME};" # NOQA + def test_fs_pickling(storage): fs = AzureBlobFileSystem( account_name=storage.account_name, connection_string=CONN_STR, - kwarg1= "some_value", + kwarg1="some_value", ) - fs2 : AzureBlobFileSystem = pickle.loads(pickle.dumps(fs)) + fs2: AzureBlobFileSystem = pickle.loads(pickle.dumps(fs)) assert "data" in fs.ls("") assert "data" in fs2.ls("") assert fs2.kwargs["kwarg1"] == "some_value" + def test_blob_pickling(storage): fs = AzureBlobFileSystem( account_name=storage.account_name, connection_string=CONN_STR ) - fs2 : AzureBlobFileSystem = pickle.loads(pickle.dumps(fs)) + fs2: AzureBlobFileSystem = pickle.loads(pickle.dumps(fs)) blob = fs2.open("data/root/a/file.txt") assert blob.read() == b"0123456789" blob2 = pickle.loads(pickle.dumps(blob)) blob2.seek(0) - assert blob2.read() == b"0123456789" \ No newline at end of file + assert blob2.read() == b"0123456789"