Skip to content

Commit 92f6435

Browse files
committed
fix: return back nested syntax
This error was introduced when I tried to make all the linters happy, uh.
1 parent cdc8f4d commit 92f6435

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/apify/scrapy/cache.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ def store_response(self, _: Spider, request: Request, response: Response) -> Non
155155

156156
def to_gzip(data: dict, mtime: int | None = None) -> bytes:
157157
"""Dump a dictionary to a gzip-compressed byte stream."""
158-
with io.BytesIO() as byte_stream, gzip.GzipFile(fileobj=byte_stream, mode='wb', mtime=mtime) as gzip_file:
159-
pickle.dump(data, gzip_file, protocol=4)
160-
return byte_stream.getvalue()
158+
with io.BytesIO() as byte_stream:
159+
with gzip.GzipFile(fileobj=byte_stream, mode='wb', mtime=mtime) as gzip_file:
160+
pickle.dump(data, gzip_file, protocol=4)
161+
return byte_stream.getvalue()
161162

162163

163164
def from_gzip(gzip_bytes: bytes) -> dict:

tests/unit/scrapy/test_cache.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22

33
from apify.scrapy.cache import from_gzip, read_gzip_time, to_gzip
44

5+
FIXTURE_DICT = {'name': 'Alice'}
6+
57
FIXTURE_BYTES = (
68
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xffk`\x99*\xcc\x00\x01\xb5SzX\xf2\x12s'
79
b'S\xa7\xf4\xb0:\xe6d&\xa7N)\xd6\x03\x00\x1c\xe8U\x9c\x1e\x00\x00\x00'
810
)
911

1012

1113
def test_gzip() -> None:
12-
assert from_gzip(to_gzip({'name': 'Alice'})) == {'name': 'Alice'}
14+
assert from_gzip(to_gzip(FIXTURE_DICT)) == FIXTURE_DICT
1315

1416

1517
def test_to_gzip() -> None:
16-
data_bytes = to_gzip({'name': 'Alice'}, mtime=0)
18+
data_bytes = to_gzip(FIXTURE_DICT, mtime=0)
1719

1820
assert data_bytes == FIXTURE_BYTES
1921

2022

2123
def test_from_gzip() -> None:
2224
data_dict = from_gzip(FIXTURE_BYTES)
2325

24-
assert data_dict == {'name': 'Alice'}
26+
assert data_dict == FIXTURE_DICT
2527

2628

2729
def test_read_gzip_time() -> None:
@@ -30,6 +32,6 @@ def test_read_gzip_time() -> None:
3032

3133
def test_read_gzip_time_non_zero() -> None:
3234
current_time = int(time())
33-
data_bytes = to_gzip({'name': 'Alice'}, mtime=current_time)
35+
data_bytes = to_gzip(FIXTURE_DICT, mtime=current_time)
3436

3537
assert read_gzip_time(data_bytes) == current_time

0 commit comments

Comments
 (0)