Skip to content

Commit 11df37a

Browse files
committed
Merge branch 'lint/line-120' of https://github.com/python-cachier/cachier into lint/line-120
2 parents 905cd10 + a238973 commit 11df37a

9 files changed

Lines changed: 82 additions & 52 deletions

File tree

.github/workflows/ci-test.yml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ jobs:
5353
uses: actions/setup-python@v6
5454
with:
5555
python-version: ${{ matrix.python-version }}
56+
cache: "pip"
5657

57-
- name: Install dependencies
58-
run: |
59-
python -m pip install --upgrade pip
60-
python -m pip install -e . -r tests/requirements.txt
58+
- name: Install package & dependencies
59+
run: python -m pip install -e . -r tests/requirements.txt
6160

6261
- name: Lower inotify instance limit (Linux only, for Issue #24 test)
6362
if: runner.os == 'Linux' && matrix.backend == 'local'
@@ -75,14 +74,18 @@ jobs:
7574
colima start
7675
# For testcontainers to find the Colima socket
7776
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
77+
78+
- name: Install other test dependencies
79+
if: matrix.backend != 'local'
80+
run: python -m pip install -e . -r tests/requirements_${{ matrix.backend }}.txt
81+
7882
# ToDo: find a way to cache docker images
7983
#- name: Cache Container Images
8084
# if: matrix.backend == 'mongodb'
8185
# uses: borda/cache-container-images-action@b32a5e804cb39af3c3d134fc03ab76eac0bfcfa9
8286
# with:
8387
# prefix-key: "mongo-db"
8488
# images: mongo:latest
85-
8689
- name: Start MongoDB in docker
8790
if: matrix.backend == 'mongodb'
8891
run: |
@@ -93,11 +96,6 @@ jobs:
9396
# show running containers
9497
docker ps -a
9598
96-
- name: Install MongoDB core test dependencies
97-
if: matrix.backend == 'mongodb'
98-
run: |
99-
python -m pip install -e . -r tests/mongodb_requirements.txt
100-
10199
- name: Unit tests (DB)
102100
if: matrix.backend == 'mongodb'
103101
run: pytest -m "mongo" --cov=cachier --cov-report=term --cov-report=xml:cov.xml
@@ -117,11 +115,6 @@ jobs:
117115
sleep 10
118116
docker ps -a
119117
120-
- name: Install SQL core test dependencies (SQL/Postgres)
121-
if: matrix.backend == 'postgres'
122-
run: |
123-
python -m pip install -e . -r tests/sql_requirements.txt
124-
125118
- name: Unit tests (SQL/Postgres)
126119
if: matrix.backend == 'postgres'
127120
env:
@@ -138,11 +131,6 @@ jobs:
138131
sleep 5
139132
docker ps -a
140133
141-
- name: Install Redis core test dependencies
142-
if: matrix.backend == 'redis'
143-
run: |
144-
python -m pip install -e . -r tests/redis_requirements.txt
145-
146134
- name: Unit tests (Redis)
147135
if: matrix.backend == 'redis'
148136
run: pytest -m redis --cov=cachier --cov-report=term --cov-report=xml:cov.xml

AGENTS.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cachier/
3636
│ └── __main__.py
3737
├── tests/ # Pytest-based tests, backend-marked
3838
│ ├── test_*.py
39-
│ └── *_requirements.txt # Backend-specific test requirements
39+
│ └── requirements_*.txt # Backend-specific test requirements
4040
├── examples/ # Usage examples
4141
├── README.rst # Main documentation
4242
├── pyproject.toml # Build, lint, type, test config
@@ -55,7 +55,7 @@ ______________________________________________________________________
5555
pip install .[all]
5656
```
5757

58-
- For backend-specific dev: see `tests/*_requirements.txt`.
58+
- For backend-specific dev: see `tests/requirements_*.txt`.
5959

6060
2. **Run tests:**
6161

@@ -111,7 +111,7 @@ ______________________________________________________________________
111111
- **Default:** Pickle (local file cache, `~/.cachier/`)
112112
- **Others:** Memory, MongoDB, SQL, Redis
113113
- **Adding a backend:** Implement in `src/cachier/cores/`, subclass `BaseCore`, add tests with appropriate markers, update docs, and CI matrix if needed.
114-
- **Optional dependencies:** Code/tests must gracefully skip if backend deps are missing. Install backend-specific deps via `tests/*_requirements.txt`.
114+
- **Optional dependencies:** Code/tests must gracefully skip if backend deps are missing. Install backend-specific deps via `tests/requirements_*.txt`.
115115
- **Requirements files:** `tests/sql_requirements.txt`, `tests/redis_requirements.txt` for backend-specific dependencies.
116116

117117
### 3. **Decorator Usage**
@@ -125,7 +125,7 @@ ______________________________________________________________________
125125
- **Run all tests:** `pytest`
126126
- **Backend-specific:** Use markers, e.g. `pytest -m mongo`, `pytest -m redis`, `pytest -m sql`
127127
- **Available markers:** `mongo`, `memory`, `pickle`, `redis`, `sql`, `maxage` (see `pyproject.toml`)
128-
- **Requirements:** See `tests/*_requirements.txt` for backend test deps.
128+
- **Requirements:** See `tests/requirements_*.txt` for backend test deps.
129129
- **CI:** Matrix covers OS/backend combinations. Mongo/SQL/Redis require Dockerized services.
130130
- **Missing deps:** Tests gracefully skip if optional backend dependencies are missing.
131131

@@ -406,9 +406,9 @@ ______________________________________________________________________
406406
pip install -e .
407407
pip install -r tests/requirements.txt
408408
# For specific backends:
409-
pip install -r tests/mongodb_requirements.txt
410-
pip install -r tests/redis_requirements.txt
411-
pip install -r tests/sql_requirements.txt
409+
pip install -r tests/requirements_mongodb.txt
410+
pip install -r tests/requirements_redis.txt
411+
pip install -r tests/requirements_postgres.txt
412412
```
413413
- **Run all tests:** `pytest`
414414
- **Run backend-specific tests:** `pytest -m <backend>` (mongo, redis, sql, memory, pickle, maxage)
@@ -421,7 +421,7 @@ ______________________________________________________________________
421421
- **Build package:** `python -m build`
422422
- **Check docs:** `python setup.py checkdocs`
423423
- **Run example:** `python examples/redis_example.py`
424-
- **Update requirements:** Edit `tests/*_requirements.txt` as needed (sql_requirements.txt, redis_requirements.txt).
424+
- **Update requirements:** Edit `tests/requirements_*.txt` as needed (sql_requirements.txt, redis_requirements.txt).
425425

426426
### Local Testing with Docker
427427

@@ -488,7 +488,7 @@ ______________________________________________________________________
488488

489489
### b. **Best Practices for Coding Assistance Agents**
490490

491-
- **Always check for backend-specific requirements** before running backend tests or code (see `tests/*_requirements.txt`).
491+
- **Always check for backend-specific requirements** before running backend tests or code (see `tests/requirements_*.txt`).
492492
- **When adding a backend:** Update all relevant places (core, tests, docs, CI matrix, requirements files).
493493
- **When editing core logic:** Ensure all backends are still supported and tested.
494494
- **When updating the decorator API:** Update docstrings, README, and tests.

CLAUDE.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cachier/
3636
│ └── __main__.py
3737
├── tests/ # Pytest-based tests, backend-marked
3838
│ ├── test_*.py
39-
│ └── *_requirements.txt # Backend-specific test requirements
39+
│ └── requirements_*.txt # Backend-specific test requirements
4040
├── examples/ # Usage examples
4141
├── README.rst # Main documentation
4242
├── pyproject.toml # Build, lint, type, test config
@@ -55,7 +55,7 @@ ______________________________________________________________________
5555
pip install .[all]
5656
```
5757

58-
- For backend-specific dev: see `tests/*_requirements.txt`.
58+
- For backend-specific dev: see `tests/requirements_*.txt`.
5959

6060
2. **Run tests:**
6161

@@ -111,7 +111,7 @@ ______________________________________________________________________
111111
- **Default:** Pickle (local file cache, `~/.cachier/`)
112112
- **Others:** Memory, MongoDB, SQL, Redis
113113
- **Adding a backend:** Implement in `src/cachier/cores/`, subclass `BaseCore`, add tests with appropriate markers, update docs, and CI matrix if needed.
114-
- **Optional dependencies:** Code/tests must gracefully skip if backend deps are missing. Install backend-specific deps via `tests/*_requirements.txt`.
114+
- **Optional dependencies:** Code/tests must gracefully skip if backend deps are missing. Install backend-specific deps via `tests/requirements_*.txt`.
115115
- **Requirements files:** `tests/sql_requirements.txt`, `tests/redis_requirements.txt` for backend-specific dependencies.
116116

117117
### 3. **Decorator Usage**
@@ -125,7 +125,7 @@ ______________________________________________________________________
125125
- **Run all tests:** `pytest`
126126
- **Backend-specific:** Use markers, e.g. `pytest -m mongo`, `pytest -m redis`, `pytest -m sql`
127127
- **Available markers:** `mongo`, `memory`, `pickle`, `redis`, `sql`, `maxage` (see `pyproject.toml`)
128-
- **Requirements:** See `tests/*_requirements.txt` for backend test deps.
128+
- **Requirements:** See `tests/requirements_*.txt` for backend test deps.
129129
- **CI:** Matrix covers OS/backend combinations. Mongo/SQL/Redis require Dockerized services.
130130
- **Missing deps:** Tests gracefully skip if optional backend dependencies are missing.
131131

@@ -406,9 +406,9 @@ ______________________________________________________________________
406406
pip install -e .
407407
pip install -r tests/requirements.txt
408408
# For specific backends:
409-
pip install -r tests/mongodb_requirements.txt
410-
pip install -r tests/redis_requirements.txt
411-
pip install -r tests/sql_requirements.txt
409+
pip install -r tests/requirements_mongodb.txt
410+
pip install -r tests/requirements_redis.txt
411+
pip install -r tests/requirements_postgres.txt
412412
```
413413
- **Run all tests:** `pytest`
414414
- **Run backend-specific tests:** `pytest -m <backend>` (mongo, redis, sql, memory, pickle, maxage)
@@ -421,7 +421,7 @@ ______________________________________________________________________
421421
- **Build package:** `python -m build`
422422
- **Check docs:** `python setup.py checkdocs`
423423
- **Run example:** `python examples/redis_example.py`
424-
- **Update requirements:** Edit `tests/*_requirements.txt` as needed (sql_requirements.txt, redis_requirements.txt).
424+
- **Update requirements:** Edit `tests/requirements_*.txt` as needed (sql_requirements.txt, redis_requirements.txt).
425425

426426
### Local Testing with Docker
427427

@@ -488,7 +488,7 @@ ______________________________________________________________________
488488

489489
### b. **Best Practices for Claude**
490490

491-
- **Always check for backend-specific requirements** before running backend tests or code (see `tests/*_requirements.txt`).
491+
- **Always check for backend-specific requirements** before running backend tests or code (see `tests/requirements_*.txt`).
492492
- **When adding a backend:** Update all relevant places (core, tests, docs, CI matrix, requirements files).
493493
- **When editing core logic:** Ensure all backends are still supported and tested.
494494
- **When updating the decorator API:** Update docstrings, README, and tests.

scripts/README-local-testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ The script automatically sets the required environment variables:
154154
2. **Python dependencies** - Install test requirements:
155155
```bash
156156
pip install -r tests/requirements.txt
157-
pip install -r tests/mongodb_requirements.txt # For MongoDB tests
158-
pip install -r tests/redis_requirements.txt # For Redis tests
159-
pip install -r tests/sql_requirements.txt # For SQL tests
157+
pip install -r tests/requirements_mongodb.txt # For MongoDB tests
158+
pip install -r tests/requirements_redis.txt # For Redis tests
159+
pip install -r tests/requirements_postgres.txt # For SQL tests
160160
```
161161

162162
## Troubleshooting

src/cachier/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def set_global_params(**params: Any) -> None:
136136
import cachier
137137

138138
valid_params = {k: v for k, v in params.items() if hasattr(cachier.config._global_params, k)}
139-
cachier.config._global_params = replace(cachier.config._global_params, **valid_params)
139+
cachier.config._global_params = replace(
140+
cachier.config._global_params,
141+
**valid_params,
142+
)
140143

141144

142145
def get_default_params() -> Params:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
-r requirements.txt
22
# to connect to the test mongodb server
33
pymongo
44
dnspython
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-r requirements.txt
12
# for SQL core tests
23
SQLAlchemy
34
psycopg2-binary
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-r requirements.txt
2+
13
redis>=4.0.0
24
pandas>=1.3.0
35
birch>=0.0.35

tests/test_redis_core.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,22 @@ def test_redis_import_warning():
429429
"""Test that import warning is raised when redis is not available."""
430430
ptc = patch("cachier.cores.redis.REDIS_AVAILABLE", False)
431431
with ptc, pytest.warns(ImportWarning, match="`redis` was not found"):
432-
_RedisCore(hash_func=None, redis_client=Mock(), wait_for_calc_timeout=None)
432+
_RedisCore(
433+
hash_func=None,
434+
redis_client=Mock(),
435+
wait_for_calc_timeout=None,
436+
)
433437

434438

435439
@pytest.mark.redis
436440
def test_missing_redis_client():
437441
"""Test MissingRedisClient exception when redis_client is None."""
438442
with pytest.raises(MissingRedisClient, match="must specify ``redis_client``"):
439-
_RedisCore(hash_func=None, redis_client=None, wait_for_calc_timeout=None)
443+
_RedisCore(
444+
hash_func=None,
445+
redis_client=None,
446+
wait_for_calc_timeout=None,
447+
)
440448

441449

442450
@pytest.mark.redis
@@ -451,7 +459,11 @@ def test_redis_core_exceptions():
451459
mock_client.keys = MagicMock(side_effect=Exception("Redis keys error"))
452460
mock_client.delete = MagicMock(side_effect=Exception("Redis delete error"))
453461

454-
core = _RedisCore(hash_func=None, redis_client=mock_client, wait_for_calc_timeout=10)
462+
core = _RedisCore(
463+
hash_func=None,
464+
redis_client=mock_client,
465+
wait_for_calc_timeout=10,
466+
)
455467

456468
# Set a mock function
457469
def mock_func():
@@ -474,7 +486,11 @@ def mock_func():
474486
test_mock_client.hset = MagicMock(side_effect=Exception("Redis write error"))
475487

476488
# Create a new core with this specific mock
477-
test_core = _RedisCore(hash_func=None, redis_client=test_mock_client, wait_for_calc_timeout=10)
489+
test_core = _RedisCore(
490+
hash_func=None,
491+
redis_client=test_mock_client,
492+
wait_for_calc_timeout=10,
493+
)
478494
test_core.set_func(mock_func)
479495

480496
# Override _should_store to return True
@@ -529,7 +545,11 @@ def test_redis_delete_stale_entries():
529545
"""Test delete_stale_entries method with various scenarios."""
530546
mock_client = MagicMock()
531547

532-
core = _RedisCore(hash_func=None, redis_client=mock_client, wait_for_calc_timeout=10)
548+
core = _RedisCore(
549+
hash_func=None,
550+
redis_client=mock_client,
551+
wait_for_calc_timeout=10,
552+
)
533553

534554
# Set a mock function
535555
def mock_func():
@@ -561,7 +581,11 @@ def mock_func():
561581
delete_mock_client.delete = MagicMock()
562582

563583
# Create a new core for this test
564-
delete_core = _RedisCore(hash_func=None, redis_client=delete_mock_client, wait_for_calc_timeout=10)
584+
delete_core = _RedisCore(
585+
hash_func=None,
586+
redis_client=delete_mock_client,
587+
wait_for_calc_timeout=10,
588+
)
565589
delete_core.set_func(mock_func)
566590

567591
# Need to mock _resolve_redis_client to return our mock
@@ -613,7 +637,11 @@ def test_redis_wait_on_entry_calc_no_entry():
613637
def mock_get_entry_by_key(self, key):
614638
return key, None
615639

616-
core = _RedisCore(hash_func=None, redis_client=mock_client, wait_for_calc_timeout=10)
640+
core = _RedisCore(
641+
hash_func=None,
642+
redis_client=mock_client,
643+
wait_for_calc_timeout=10,
644+
)
617645

618646
# Set a mock function
619647
def mock_func():
@@ -634,7 +662,11 @@ def test_redis_set_entry_should_not_store():
634662
"""Test set_entry when value should not be stored (None not allowed)."""
635663
mock_client = MagicMock()
636664

637-
core = _RedisCore(hash_func=None, redis_client=mock_client, wait_for_calc_timeout=10)
665+
core = _RedisCore(
666+
hash_func=None,
667+
redis_client=mock_client,
668+
wait_for_calc_timeout=10,
669+
)
638670

639671
# Mock _should_store to return False
640672
core._should_store = Mock(return_value=False)
@@ -665,7 +697,11 @@ def test_redis_clear_being_calculated_with_pipeline():
665697
pipeline_mock.hset = MagicMock()
666698
pipeline_mock.execute = MagicMock()
667699

668-
core = _RedisCore(hash_func=None, redis_client=pipeline_mock_client, wait_for_calc_timeout=10)
700+
core = _RedisCore(
701+
hash_func=None,
702+
redis_client=pipeline_mock_client,
703+
wait_for_calc_timeout=10,
704+
)
669705

670706
# Set a mock function
671707
def mock_func():

0 commit comments

Comments
 (0)