Skip to content

Commit ff3ccdb

Browse files
author
Julio Martin-Hidalgo
committed
Changed test to use zip instead of simplecache
1 parent f0a1bec commit ff3ccdb

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

fsspec/tests/test_core.py

+23-25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
)
1818

1919

20+
@contextmanager
21+
def tempzip(data={}):
22+
f = tempfile.mkstemp(suffix="zip")[1]
23+
with zipfile.ZipFile(f, mode="w") as z:
24+
for k, v in data.items():
25+
z.writestr(k, v)
26+
try:
27+
yield f
28+
finally:
29+
try:
30+
os.remove(f)
31+
except (IOError, OSError):
32+
pass
33+
34+
2035
@pytest.mark.parametrize(
2136
"path, name_function, num, out",
2237
[
@@ -196,42 +211,25 @@ def test_url_to_fs(ftp_writable):
196211

197212
def test_target_protocol_options(ftp_writable):
198213
host, port, username, password = ftp_writable
199-
data = b"hello_protocol"
214+
data = {"afile": b"hello"}
200215
options = {"host": host, "port": port, "username": username, "password": password}
201-
with fsspec.open(f"ftp://{username}:{password}@{host}:{port}/afile", "wb") as f:
202-
f.write(data)
203-
with fsspec.open(f"ftp://{username}:{password}@{host}:{port}/afile", "rb") as f:
204-
assert f.read() == data
205-
with fsspec.open("ftp:///afile", "rb", **options) as f:
206-
assert f.read() == data
216+
with tempzip(data) as lfile, fsspec.open(
217+
"ftp:///archive.zip", "wb", **options
218+
) as f:
219+
f.write(open(lfile, "rb").read())
207220
with fsspec.open(
208-
"simplecache://afile",
221+
"zip://afile",
209222
"rb",
210223
target_protocol="ftp",
211224
target_options=options,
225+
fo="archive.zip",
212226
) as f:
213-
assert f.read() == data
227+
assert f.read() == data["afile"]
214228

215229

216230
def test_chained_url(ftp_writable):
217231
host, port, username, password = ftp_writable
218-
219-
@contextmanager
220-
def tempzip(data={}):
221-
f = tempfile.mkstemp(suffix="zip")[1]
222-
with zipfile.ZipFile(f, mode="w") as z:
223-
for k, v in data.items():
224-
z.writestr(k, v)
225-
try:
226-
yield f
227-
finally:
228-
try:
229-
os.remove(f)
230-
except (IOError, OSError):
231-
pass
232-
233232
data = {"afile": b"hello"}
234-
235233
cls = fsspec.get_filesystem_class("ftp")
236234
fs = cls(host=host, port=port, username=username, password=password)
237235
with tempzip(data) as lfile:

0 commit comments

Comments
 (0)