Use MockColonyClient for toolkit tests, accept client= injection#26
Merged
jackparnell merged 3 commits intomainfrom Apr 12, 2026
Merged
Use MockColonyClient for toolkit tests, accept client= injection#26jackparnell merged 3 commits intomainfrom
jackparnell merged 3 commits intomainfrom
Conversation
ColonyToolkit and AsyncColonyToolkit now accept a pre-built client via
client=, alongside the existing api_key= constructor. Backward compatible:
old api_key= calls still work unchanged.
Migrated tests/test_toolkit.py from unittest.mock.patch to
colony_sdk.testing.MockColonyClient injected via the new client=
parameter. The test file shrinks from 1009 → 968 lines while preserving
the same 81 tests, and gains:
- No more import-time patching (`with patch("langchain_colony.toolkit.ColonyClient") as MockClient: ...`)
- Real instances with structured `client.calls` recording instead of MagicMock attribute juggling
- A small `_toolkit_with(responses)` helper that returns (toolkit, mock_client) for one-line setup
Bumped colony-sdk constraint from >=1.5.0 → >=1.7.0 for MockColonyClient.
All 270 tests pass, lint/format/typecheck clean.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
The previous PR commit added a client= constructor parameter to both ColonyToolkit and AsyncColonyToolkit but didn't cover the new code paths in tests. Codecov flagged the coverage drop on the patch. This commit adds 7 tests covering: - ColonyToolkit accepts injected MockColonyClient - ColonyToolkit injected client overrides api_key - ColonyToolkit raises ValueError when neither api_key nor client provided - ColonyToolkit api_key path still constructs a real ColonyClient - AsyncColonyToolkit accepts injected MockColonyClient - AsyncColonyToolkit injected client overrides api_key - AsyncColonyToolkit raises ValueError when neither api_key nor client provided src/langchain_colony/toolkit.py now at 100% coverage (was 95%). 277 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add .coverage / htmlcov/ / coverage.xml to .gitignore so future coverage runs don't leak binary state into the repo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adopt the new
colony_sdk.testing.MockColonyClient(shipped in colony-sdk 1.7.0) for toolkit tests, replacing the existingunittest.mock.patchboilerplate. Also adds aclient=constructor parameter toColonyToolkit/AsyncColonyToolkitso users (and tests) can inject any client — perfect for testing, but also useful for sharing a client across toolkits or supplying a pre-configured one with custom retry / hooks / typed mode / etc.Fully backward compatible — existing
ColonyToolkit(api_key=...)calls still work unchanged.Changes
src/langchain_colony/toolkit.pyColonyToolkit.__init__addsclient: Any = Nonekwarg. When set,api_key/base_url/retryare ignored.AsyncColonyToolkit.__init__does the same.api_keyis now optional (must supply either it orclient); raisesValueErrorif both are missing.tests/test_toolkit.py_toolkit_with(responses)helper returns(toolkit, mock_client)for one-line setup.with patch(...)toMockColonyClient(responses=...)injected viaclient=.mock.method.assert_called_once_with(...)withmock.calls[-1] == ("method", {...}).pyproject.tomlcolony-sdk>=1.5.0→>=1.7.0(andcolony-sdk[async]>=1.5.0→>=1.7.0) forMockColonyClient.Why this matters
Test plan
🤖 Generated with Claude Code