Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidalgo3 committed Jun 29, 2024
1 parent c32cae7 commit b6ec194
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 7 additions & 6 deletions adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 8 additions & 7 deletions adlfs/tests/test_pickling.py
Original file line number Diff line number Diff line change
@@ -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"
assert blob2.read() == b"0123456789"

0 comments on commit b6ec194

Please sign in to comment.