This document provides instructions for running tests in the embedding_tools repository.
Ensure you have the package installed in development mode:
cd embedding_tools
pip install -e ".[dev]"To test specific backends, install their dependencies:
# For JAX backend tests
pip install -e ".[jax]"
# For PyTorch backend tests
pip install -e ".[torch]"
# For MLX backend tests (macOS only)
pip install -e ".[mlx]"
# For all backends
pip install -e ".[all]"pytest tests/ -vJAX Backend Tests:
pytest tests/test_jax_backend.py -vNumPy Backend Tests:
pytest tests/test_arrays.py::TestNumpyBackend -vMLX Backend Tests (macOS only):
pytest tests/test_arrays.py::TestMLXBackend -vPyTorch Backend Tests:
pytest tests/test_torch_backend.py -vEmbeddingStore Tests:
pytest tests/test_memory.py -vConfiguration/Hashing Tests:
pytest tests/test_config.py -vInstallation Tests:
pytest tests/test_installation.py -vpytest tests/test_jax_backend.py::TestJAXBackend::test_cosine_similarity -vShow print statements and full output:
pytest tests/test_jax_backend.py -v -sShow full tracebacks on failures:
pytest tests/test_jax_backend.py -v --tb=longStop on first failure:
pytest tests/ -v -xThe test suite is organized as follows:
tests/
├── test_arrays.py # Backend operations (NumPy, MLX)
├── test_config.py # Configuration hashing
├── test_installation.py # Installation validation
├── test_jax_backend.py # JAX backend (23 tests)
├── test_memory.py # EmbeddingStore functionality
└── test_torch_backend.py # PyTorch backend
Total: 75 tests
- 71 PASSED
- 1 FAILED (test_mlx_backend_conditional - MLX not available)
- 3 ERROR (MLX tests - MLX not available on Linux)
Total: 75 tests
- 75 PASSED (all backends available)
Total: 23 tests
- 23 PASSED
To run tests with coverage reporting:
pytest tests/ --cov=embedding_tools --cov-report=htmlView the coverage report:
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # LinuxTests should pass on all platforms except:
- MLX tests will skip/fail on non-macOS platforms
- GPU-specific tests may skip if no GPU available
If you see ModuleNotFoundError, ensure the package is installed:
pip install -e .If a specific backend test fails:
-
Check if the backend is installed:
python -c "import jax; print('JAX available')" python -c "import torch; print('PyTorch available')" python -c "import mlx.core; print('MLX available')"
-
Install the missing backend:
pip install -e ".[jax]" # or torch, mlx
MLX is only available on Apple Silicon (M-series Macs). On Linux, MLX tests will error - this is expected behavior.
# Build test container
docker build -t embedding-tools-test .
# Run tests
docker run embedding-tools-test pytest tests/ -vAfter making changes, run this quick validation:
# Test core functionality
pytest tests/test_installation.py -v
# Test your specific backend
pytest tests/test_jax_backend.py -v
# Test no regressions
pytest tests/test_arrays.py::TestNumpyBackend -vWhen adding new functionality:
- Add tests to the appropriate test file
- Follow the existing test patterns
- Use pytest fixtures for setup
- Mark backend-specific tests with
@pytest.mark.skipif
Example:
@pytest.mark.skipif(not JAX_AVAILABLE, reason="JAX not installed")
def test_jax_feature(self):
backend = JAXBackend()
# ... test code