Skip to content

Commit

Permalink
Merge pull request #186 from netomi/further-unit-test-fixes
Browse files Browse the repository at this point in the history
Further unit test fixes
  • Loading branch information
JWCook committed Oct 3, 2023
2 parents 8ed3214 + 8f787d0 commit c7ec56f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions test/integration/base_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ async def test_keys_values(self):
for k, v in test_data.items():
await cache.write(k, v)

assert sorted([k async for k in cache.keys()]) == sorted(test_data.keys())
assert sorted([v async for v in cache.values()]) == sorted(test_data.values())
assert sorted([k async for k in cache.keys()]) == sorted(test_data.keys())
assert sorted([v async for v in cache.values()]) == sorted(test_data.values())

async def test_size(self):
async with self.init_cache() as cache:
assert await cache.size() == 0
for k, v in self.test_data.items():
await cache.write(k, v)

assert await cache.size() == len(self.test_data)
assert await cache.size() == len(self.test_data)

async def test_clear(self):
async with self.init_cache() as cache:
Expand Down
4 changes: 0 additions & 4 deletions test/integration/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ class TestRedisCache(BaseStorageTest):

class TestRedisBackend(BaseBackendTest):
backend_class = RedisBackend

@pytest.mark.skip(reason='Test not yet working for Redis backend')
async def test_gather(self):
super().test_gather()
10 changes: 6 additions & 4 deletions test/integration/test_sqlite.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import asyncio
import os
from tempfile import gettempdir
from unittest.mock import patch
from unittest.mock import MagicMock, patch

import pytest

from aiohttp_client_cache.backends import CacheBackend
from aiohttp_client_cache.backends.sqlite import SQLiteBackend, SQLiteCache, SQLitePickleCache
from test.conftest import CACHE_NAME, httpbin, skip_37
from test.integration import BaseBackendTest, BaseStorageTest
Expand Down Expand Up @@ -139,6 +138,7 @@ async def test_close(self):


class TestSQLitePickleCache(BaseStorageTest):
init_kwargs = {'use_temp': True}
picklable = True
storage_class = SQLitePickleCache

Expand All @@ -148,10 +148,12 @@ class TestSQLiteBackend(BaseBackendTest):
init_kwargs = {'use_temp': True}

@skip_37
@patch.object(CacheBackend, 'close')
async def test_autoclose__default(self, mock_close):
async def test_autoclose__default(self):
"""By default, the backend should be closed when the session is closed"""

async with self.init_session() as session:
mock_close = MagicMock(wraps=session.cache.close)
session.cache.close = mock_close

await session.get(httpbin('get'))
mock_close.assert_called_once()

0 comments on commit c7ec56f

Please sign in to comment.