Skip to content

Commit 6e08da3

Browse files
committed
feat(test): add comprehensive test coverage and implement improvements
- Added extensive unit tests for exception handling, unserializable objects, various argument types, cache purge, custom serializers, and high concurrency scenarios - Updated and optimized Lua scripts for improved performance, reliability, and Redis compatibility - Refactored test code for better readability and maintainability - Enhanced code style and type annotations across the codebase - Improved Redis Lua script cleaning logic, now handling absence of pygments or Lua lexer more gracefully - Migrated build and dependency management to uv (https://docs.astral.sh/uv/) - Updated documentation and configuration files - Switched test dependency to pytest for a more modern testing workflow - Changed Redis client factories from lambdas to named functions for better type checking and extensibility - Marked branches for missing pygments with # pragma: no cover in utils.py for improved coverage reporting
1 parent d8b47aa commit 6e08da3

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
# - id: check-docstring-first
2121

2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: v0.9.5
23+
rev: v0.12.0
2424
hooks:
2525
- id: ruff # Run the linter.
2626
types_or: [python, pyi, jupyter]
@@ -29,14 +29,14 @@ repos:
2929
types_or: [python, pyi, jupyter]
3030

3131
- repo: https://github.com/pre-commit/mirrors-mypy
32-
rev: "v1.15.0"
32+
rev: "v1.16.1"
3333
hooks:
3434
- id: mypy
3535
args: [--ignore-missing-imports, --config-file, .mypy.ini]
3636
additional_dependencies: [types-redis,types-PyYAML,types-Pygments]
3737

3838
- repo: https://github.com/python-jsonschema/check-jsonschema
39-
rev: "0.31.1"
39+
rev: "0.33.1"
4040
hooks:
4141
- id: check-github-workflows
4242
- id: check-readthedocs

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,27 @@
44

55
-**New Features:**
66
- Added `bson` and `yaml` serializer/deserializer support for the `RedisFuncCache` class.
7+
- Added comprehensive unit tests for exception handling, unserializable objects, various argument types, cache purge, custom serializers, and high concurrency scenarios (multi-thread/thread pool/concurrent exception handling).
78

89
- 💔 **Breaking Changes:**
910
- The `serializer` optional parameter in the `RedisFuncCache`'s `decorate` and `__call__` methods has been replaced. It now accepts a tuple of `(serializer, deserializer)` or simply the name of the serializer function.
1011

12+
- 🛠 **Improvements:**
13+
- Updated and optimized several Lua scripts to improve performance, reliability, and compatibility with Redis.
14+
- Refactored test code for better readability and maintainability.
15+
- Improved code style and type annotations across the codebase.
16+
- Improved Redis Lua script cleaning logic: now handles the absence of `pygments` or Lua lexer more gracefully, and marks these branches as uncovered for coverage tools.
17+
1118
- 📦 **Packaging:**
1219
- Added `bson`, `yaml` as optional dependencies, and `all` for all serializers.
1320
- Added `types-all`, `types-PyYAML`, and `types-Pygments` as optional dependencies for typing hints.
21+
- Build and dependency management migrated to [uv](https://docs.astral.sh/uv/).
22+
23+
- 📝 **Misc**
24+
- Minor adjustments to documentation and configuration files.
25+
- Switched test dependency to `pytest` for a more modern testing workflow.
26+
- Redis client factories changed from lambdas to named functions for better type checking and extensibility.
27+
- In `utils.py`, branches for missing `pygments` are now marked with `# pragma: no cover` to improve coverage reporting.
1428

1529
## v0.3
1630

src/redis_func_cache/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pygments.lexers import get_lexer_by_name
1818
from pygments.token import Comment, String
1919
except ImportError:
20-
pygments = None
20+
pygments = None # type: ignore[assignment]
2121
LUA_PYGMENTS_FILTER_TYPES = None
2222
else:
2323
LUA_PYGMENTS_FILTER_TYPES = (

tests/_catches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from os import getenv
2-
from typing import Callable, Dict, List, Optional
2+
from typing import Callable, Dict, List
33
from warnings import warn
44

55
from redis import Redis

tests/test_threads.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@ def test_high_concurrency(self):
7171
def test_concurrent_exception(self):
7272
"""多线程下被缓存函数抛异常时,所有线程都能收到异常。"""
7373
for cache in CACHES.values():
74+
7475
def fail(x):
7576
raise ValueError("fail")
77+
7678
_fail = cache.decorate(fail)
7779
errors = []
80+
7881
def f():
7982
try:
8083
_fail(1)
8184
except Exception as e:
8285
errors.append(e)
86+
8387
threads = [Thread(target=f) for _ in range(5)]
8488
for t in threads:
8589
t.start()

0 commit comments

Comments
 (0)