Skip to content

Commit c41211d

Browse files
authored
Merge branch 'master' into fix-xdg-cache-dir-support
2 parents 123b9c8 + 8bc7bec commit c41211d

7 files changed

Lines changed: 494 additions & 2 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,9 @@ Pipfile.lock
107107

108108
tags
109109

110+
# cursor rules, etc.
110111
.cursor
112+
113+
# created by backlog.md
114+
# https://github.com/MrLesk/Backlog.md
115+
backlog

CLAUDE.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,42 @@ ______________________________________________________________________
177177
- **Run example:** `python examples/redis_example.py`
178178
- **Update requirements:** Edit `tests/*_requirements.txt` as needed (sql_requirements.txt, redis_requirements.txt).
179179

180+
### MongoDB Local Testing
181+
182+
**Quick Start for MongoDB Testing:**
183+
184+
```bash
185+
# Option 1: Using the shell script (recommended)
186+
./scripts/test-mongo-local.sh # MongoDB tests only
187+
./scripts/test-mongo-local.sh --mode also-local # MongoDB + memory, pickle, maxage tests
188+
189+
# Option 2: Using make
190+
make test-mongo-local
191+
192+
# Option 3: Using docker-compose
193+
docker-compose -f scripts/docker-compose.mongodb.yml up -d
194+
CACHIER_TEST_HOST=localhost CACHIER_TEST_PORT=27017 CACHIER_TEST_VS_DOCKERIZED_MONGO=true pytest -m mongo
195+
docker-compose -f scripts/docker-compose.mongodb.yml down
196+
```
197+
198+
**Available Options:**
199+
200+
- `./scripts/test-mongo-local.sh` - Run MongoDB tests only (default)
201+
- `./scripts/test-mongo-local.sh --mode also-local` - Include memory, pickle, and maxage tests
202+
- `./scripts/test-mongo-local.sh --keep-running` - Keep MongoDB running after tests
203+
- `./scripts/test-mongo-local.sh --verbose` - Show verbose output
204+
- `./scripts/test-mongo-local.sh --coverage-html` - Generate HTML coverage report
205+
206+
**Make Targets:**
207+
208+
- `make test-mongo-local` - Run MongoDB tests with Docker
209+
- `make test-mongo-inmemory` - Run with in-memory MongoDB (default)
210+
- `make mongo-start` - Start MongoDB container
211+
- `make mongo-stop` - Stop MongoDB container
212+
- `make mongo-logs` - View MongoDB logs
213+
214+
**Note:** By default, MongoDB tests use `pymongo_inmemory` which doesn't require Docker. The above commands let you test against a real MongoDB instance matching the CI environment.
215+
180216
______________________________________________________________________
181217

182218
## 🧩 Claude Code Integration

Makefile

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Cachier Makefile
2+
# Development tasks and shortcuts
3+
4+
.PHONY: help test test-all test-mongo-local test-mongo-docker test-mongo-inmemory \
5+
test-mongo-also-local mongo-start mongo-stop mongo-logs lint type-check format clean \
6+
install install-dev install-all
7+
8+
# Default target
9+
help:
10+
@echo "Cachier Development Commands:"
11+
@echo ""
12+
@echo "Testing:"
13+
@echo " make test - Run all tests"
14+
@echo " make test-mongo-local - Run MongoDB tests with Docker"
15+
@echo " make test-mongo-also-local - Run MongoDB + memory, pickle, maxage tests with Docker"
16+
@echo " make test-mongo-inmemory - Run MongoDB tests with in-memory backend"
17+
@echo " make mongo-start - Start MongoDB container"
18+
@echo " make mongo-stop - Stop MongoDB container"
19+
@echo " make mongo-logs - View MongoDB container logs"
20+
@echo ""
21+
@echo "Code Quality:"
22+
@echo " make lint - Run ruff linter"
23+
@echo " make type-check - Run mypy type checker"
24+
@echo " make format - Format code with ruff"
25+
@echo ""
26+
@echo "Installation:"
27+
@echo " make install - Install package"
28+
@echo " make install-dev - Install with development dependencies"
29+
@echo " make install-all - Install with all optional dependencies"
30+
@echo ""
31+
@echo "Other:"
32+
@echo " make clean - Clean build artifacts"
33+
34+
# Installation targets
35+
install:
36+
pip install -e .
37+
38+
install-dev:
39+
pip install -e .
40+
pip install -r tests/requirements.txt
41+
42+
install-all:
43+
pip install -e .[all]
44+
pip install -r tests/requirements.txt
45+
pip install -r tests/sql_requirements.txt
46+
pip install -r tests/redis_requirements.txt
47+
48+
# Testing targets
49+
test:
50+
pytest
51+
52+
test-all: test
53+
54+
# MongoDB testing targets
55+
test-mongo-inmemory:
56+
@echo "Running MongoDB tests with in-memory backend..."
57+
pytest -m mongo --cov=cachier --cov-report=term
58+
59+
test-mongo-docker:
60+
@echo "Running MongoDB tests against Docker MongoDB..."
61+
./scripts/test-mongo-local.sh
62+
63+
test-mongo-local: test-mongo-docker
64+
65+
test-mongo-also-local:
66+
@echo "Running MongoDB tests with local core tests..."
67+
./scripts/test-mongo-local.sh --mode also-local
68+
69+
# MongoDB container management
70+
mongo-start:
71+
@echo "Starting MongoDB container..."
72+
@docker ps -q -f name=cachier-test-mongo | grep -q . && \
73+
(echo "MongoDB container already running" && exit 0) || \
74+
(docker run -d -p 27017:27017 --name cachier-test-mongo mongo:latest && \
75+
echo "Waiting for MongoDB to start..." && sleep 5)
76+
77+
mongo-stop:
78+
@echo "Stopping MongoDB container..."
79+
@docker ps -q -f name=cachier-test-mongo | grep -q . && \
80+
(docker stop cachier-test-mongo && docker rm cachier-test-mongo) || \
81+
echo "MongoDB container not running"
82+
83+
mongo-logs:
84+
@docker logs cachier-test-mongo
85+
86+
# Code quality targets
87+
lint:
88+
ruff check .
89+
90+
type-check:
91+
mypy src/cachier/
92+
93+
format:
94+
ruff format .
95+
96+
# Clean targets
97+
clean:
98+
rm -rf build/
99+
rm -rf dist/
100+
rm -rf *.egg-info
101+
rm -rf .coverage
102+
rm -rf htmlcov/
103+
rm -rf .pytest_cache/
104+
rm -rf .mypy_cache/
105+
rm -rf .ruff_cache/
106+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
107+
find . -type f -name "*.pyc" -delete

README.rst

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,45 @@ To run all tests EXCEPT memory core AND MongoDB core related tests, use:
535535
Running MongoDB tests against a live MongoDB instance
536536
-----------------------------------------------------
537537

538-
**Note to developers:** By default, all MongoDB tests are run against a mocked MongoDB instance, provided by the ``pymongo_inmemory`` package. To run them against a live MongoDB instance, the ``CACHIER_TEST_VS_DOCKERIZED_MONGO`` environment variable is set to ``True`` in the ``test`` environment of this repository (and additional environment variables are populated with the appropriate credentials), used by the GitHub Action running tests on every commit and pull request.
538+
**Note to developers:** By default, all MongoDB tests are run against a mocked MongoDB instance, provided by the ``pymongo_inmemory`` package. To run them against a live MongoDB instance, you now have several options:
539539

540-
Contributors are not expected to run these tests against a live MongoDB instance when developing, as credentials for the testing instance used will NOT be shared, but rather use the testing against the in-memory MongoDB instance as a good proxy.
540+
**Option 1: Using the test script (recommended)**
541+
542+
.. code-block:: bash
543+
544+
./scripts/test-mongo-local.sh # MongoDB tests only (default)
545+
./scripts/test-mongo-local.sh --mode also-local # MongoDB + memory, pickle, maxage tests
546+
547+
This script automatically handles Docker container lifecycle, environment variables, and cleanup. Additional options:
548+
549+
- ``--mode also-local``: Include memory, pickle, and maxage tests alongside MongoDB tests
550+
- ``--keep-running``: Keep MongoDB container running after tests
551+
- ``--verbose``: Show verbose output
552+
- ``--coverage-html``: Generate HTML coverage report
553+
554+
**Option 2: Using Make**
555+
556+
.. code-block:: bash
557+
558+
make test-mongo-local # Run tests with Docker MongoDB
559+
make test-mongo-inmemory # Run tests with in-memory MongoDB (default)
560+
561+
**Option 3: Manual setup**
562+
563+
.. code-block:: bash
564+
565+
# Start MongoDB with Docker
566+
docker run -d -p 27017:27017 --name cachier-test-mongo mongo:latest
567+
568+
# Run tests
569+
CACHIER_TEST_HOST=localhost CACHIER_TEST_PORT=27017 CACHIER_TEST_VS_DOCKERIZED_MONGO=true pytest -m mongo
570+
571+
# Clean up
572+
docker stop cachier-test-mongo && docker rm cachier-test-mongo
573+
574+
**CI Environment:** The ``CACHIER_TEST_VS_DOCKERIZED_MONGO`` environment variable is set to ``True`` in the GitHub Actions CI environment, which runs tests against a real MongoDB instance on every commit and pull request.
575+
576+
Contributors are encouraged to test against a real MongoDB instance before submitting PRs to ensure compatibility, though the in-memory MongoDB instance serves as a good proxy for most development.
541577

542578
**HOWEVER, the tests run against a live MongoDB instance when you submit a PR are the determining tests for deciding whether your code functions correctly against MongoDB.**
543579

scripts/docker-compose.mongodb.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Docker Compose configuration for local MongoDB testing
2+
# This file provides an alternative to the shell script approach
3+
4+
version: "3.8"
5+
6+
services:
7+
mongodb:
8+
image: mongo:latest
9+
container_name: cachier-test-mongo
10+
ports:
11+
- "27017:27017"
12+
environment:
13+
MONGO_INITDB_DATABASE: cachier_test
14+
healthcheck:
15+
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
16+
interval: 5s
17+
timeout: 5s
18+
retries: 5
19+
start_period: 10s
20+
volumes:
21+
# Optional: persist data between test runs
22+
# - cachier-mongo-data:/data/db
23+
# Optional: custom initialization scripts
24+
# - ./scripts/mongo-init:/docker-entrypoint-initdb.d
25+
networks:
26+
- cachier-test
27+
28+
networks:
29+
cachier-test:
30+
driver: bridge
31+
# Optional: volume for data persistence
32+
# volumes:
33+
# cachier-mongo-data:
34+
35+
# Usage:
36+
# 1. Start MongoDB: docker-compose -f scripts/docker-compose.mongodb.yml up -d
37+
# 2. Run tests with environment variables:
38+
# CACHIER_TEST_HOST=localhost CACHIER_TEST_PORT=27017 CACHIER_TEST_VS_DOCKERIZED_MONGO=true pytest -m "mongo"
39+
# 3. Stop MongoDB: docker-compose -f scripts/docker-compose.mongodb.yml down
40+
41+
# Alternative one-liner:
42+
# docker-compose -f scripts/docker-compose.mongodb.yml run --rm -e CACHIER_TEST_HOST=localhost -e CACHIER_TEST_PORT=27017 -e CACHIER_TEST_VS_DOCKERIZED_MONGO=true test

0 commit comments

Comments
 (0)