Skip to content

Commit 9a9bc2d

Browse files
committed
pre-commit fixes
1 parent 193982e commit 9a9bc2d

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

tests/test_coverage_gaps.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
"""Tests to cover specific coverage gaps identified in the codebase."""
22

3-
import os
4-
import pickle
3+
import contextlib
54
import sys
6-
import tempfile
75
import time
8-
from datetime import datetime, timedelta
9-
from unittest.mock import Mock, patch
6+
from datetime import timedelta
7+
from unittest.mock import patch
108

119
import pytest
1210

1311
import cachier
14-
from cachier.config import CacheEntry, _global_params
1512

1613
# Import backend-specific test helpers
1714
from tests.test_mongo_core import _test_mongetter
@@ -43,15 +40,18 @@ def returns_none():
4340

4441

4542
# Test 3: MongoDB delete_stale_entries (lines 162-163)
46-
# Removed - redundant with test_mongo_delete_stale_direct in test_coverage_gaps_simple.py
43+
# Removed - redundant with test_mongo_delete_stale_direct in
44+
# test_coverage_gaps_simple.py
4745

4846

4947
# Test 4: Pickle _clear_being_calculated_all_cache_files (lines 183-189)
50-
# Removed - redundant with test_pickle_clear_being_calculated_separate_files in test_coverage_gaps_simple.py
48+
# Removed - redundant with test_pickle_clear_being_calculated_separate_files in
49+
# test_coverage_gaps_simple.py
5150

5251

5352
# Test 5: Pickle save_cache with hash_str (line 205)
54-
# Removed - redundant with test_pickle_save_with_hash_str in test_coverage_gaps_simple.py
53+
# Removed - redundant with test_pickle_save_with_hash_str in
54+
# test_coverage_gaps_simple.py
5555

5656

5757
# Test 6: Redis import error handling (lines 14-15)
@@ -65,14 +65,13 @@ def test_redis_import_error_handling():
6565
if "cachier.cores.redis" in sys.modules:
6666
del sys.modules["cachier.cores.redis"]
6767

68+
# Test import failure
6869
try:
69-
from cachier.cores.redis import _RedisCore
70+
from cachier.cores.redis import _RedisCore # noqa: F401
7071

71-
# If we get here, redis was imported successfully (shouldn't happen in test)
7272
pytest.skip("Redis is installed, cannot test import error")
73-
except ImportError as e:
74-
# This is expected - verify the error message
75-
assert "No module named 'redis'" in str(e) or "redis" in str(e)
73+
except ImportError:
74+
pass # Expected behavior
7675

7776

7877
# Test 7: Redis corrupted entry handling (lines 112-114)
@@ -161,11 +160,13 @@ def mock_delete(*args):
161160

162161

163162
# Test 9: SQL allow_none=False handling (line 128)
164-
# Removed - redundant with test_sql_allow_none_false_not_stored in test_coverage_gaps_simple.py
163+
# Removed - redundant with test_sql_allow_none_false_not_stored in
164+
# test_coverage_gaps_simple.py
165165

166166

167167
# Test 10: SQL delete_stale_entries (lines 302-312)
168-
# Removed - redundant with test_sql_delete_stale_direct in test_coverage_gaps_simple.py
168+
# Removed - redundant with test_sql_delete_stale_direct in
169+
# test_coverage_gaps_simple.py
169170

170171

171172
# Test 11: Pickle timeout during wait (line 398)
@@ -220,7 +221,8 @@ def call_slow_func():
220221

221222

222223
# Test 12: Redis stale deletion with cache size tracking (lines 374-375, 380)
223-
# Removed - redundant with test_redis_stale_delete_size_tracking in test_coverage_gaps_simple.py
224+
# Removed - redundant with test_redis_stale_delete_size_tracking in
225+
# test_coverage_gaps_simple.py
224226

225227

226228
# Test 13: Redis non-bytes timestamp handling (line 364)
@@ -266,10 +268,9 @@ def test_func(x):
266268
)
267269
core.set_func(test_func)
268270

269-
# Try to delete stale entries - should handle non-bytes timestamp gracefully
270-
try:
271+
# Try to delete stale entries - should handle non-bytes timestamp
272+
# gracefully
273+
with contextlib.suppress(Exception):
271274
core.delete_stale_entries(timedelta(seconds=1))
272-
except Exception:
273-
pass # Expected to handle gracefully
274275

275276
test_func.clear_cache()

tests/test_coverage_gaps_simple.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
"""Simple tests to cover specific coverage gaps."""
22

33
import os
4-
import sys
54
import tempfile
65
import time
76
from datetime import datetime, timedelta
8-
from unittest.mock import Mock, patch
97

108
import pytest
119

@@ -116,7 +114,7 @@ def test_func(x):
116114
from cachier.cores.mongo import _MongoCore
117115

118116
# Get the collection
119-
collection = _test_mongetter()
117+
_test_mongetter() # Ensure connection is available
120118

121119
# Create a core instance just for deletion
122120
core = _MongoCore(
@@ -299,17 +297,14 @@ def test_redis_import_error():
299297
# Test creating a Redis core without providing a client
300298
import warnings
301299

302-
with warnings.catch_warnings(record=True) as w:
300+
with warnings.catch_warnings(record=True):
303301
warnings.simplefilter("always")
304302

305-
try:
303+
with pytest.raises(Exception, match="redis_client"):
306304

307305
@cachier.cachier(backend="redis", redis_client=None)
308306
def test_func():
309307
return "test"
310-
except Exception as e:
311-
# Expected to fail with MissingRedisClient
312-
assert "redis_client" in str(e)
313308

314309

315310
# Test 9: Redis corrupted entry in LRU eviction

0 commit comments

Comments
 (0)