11"""Tests to cover specific coverage gaps identified in the codebase."""
22
3- import os
4- import pickle
3+ import contextlib
54import sys
6- import tempfile
75import 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
119import pytest
1210
1311import cachier
14- from cachier .config import CacheEntry , _global_params
1512
1613# Import backend-specific test helpers
1714from 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 ()
0 commit comments