Skip to content

Commit 663b7e4

Browse files
authored
test: improve coverage for models and toolset modules (76% → 87%) (#67)
* refactor(toolset): remove unused _matches_filter method Remove the _matches_filter method from StackOneToolSet as it was never called in the source code (only used in tests). This reduces code complexity and improves test coverage percentage. The existing _filter_by_provider and _filter_by_action methods provide equivalent functionality and are actually used in fetch_tools. * test: improve coverage for models and toolset modules Add comprehensive tests for previously uncovered code paths: models.py (78% -> 95%): - validate_method unsupported HTTP method error - ExecuteConfig validation - Parameter location handling (PATH, QUERY, BODY) - HTTP error handling (JSON and text response bodies) - RequestError handling - Non-dict response wrapping - OpenAI conversion (enum, array, object, non-dict properties) - LangChain conversion (number, integer, boolean types) - Async _arun method - Tools container iteration and account ID methods toolset.py (52% -> 77%): - _StackOneRpcTool execution (basic, JSON string, payloads) - Header handling (Authorization stripping, None value skipping) - Argument parsing edge cases Overall coverage improved from 76% to 87%.
1 parent 9d180ef commit 663b7e4

File tree

4 files changed

+736
-56
lines changed

4 files changed

+736
-56
lines changed

stackone_ai/toolset.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -253,34 +253,6 @@ def __init__(
253253
self.base_url = base_url or DEFAULT_BASE_URL
254254
self._account_ids: list[str] = []
255255

256-
def _matches_filter(self, tool_name: str, filter_pattern: str | list[str]) -> bool:
257-
"""Check if a tool name matches the filter pattern
258-
259-
Args:
260-
tool_name: Name of the tool to check
261-
filter_pattern: String or list of glob patterns to match against.
262-
Patterns starting with ! are treated as negative matches.
263-
264-
Returns:
265-
True if the tool name matches any positive pattern and no negative patterns,
266-
False otherwise
267-
"""
268-
patterns = [filter_pattern] if isinstance(filter_pattern, str) else filter_pattern
269-
270-
# Split into positive and negative patterns
271-
positive_patterns = [p for p in patterns if not p.startswith("!")]
272-
negative_patterns = [p[1:] for p in patterns if p.startswith("!")]
273-
274-
# If no positive patterns, treat as match all
275-
matches_positive = (
276-
any(fnmatch.fnmatch(tool_name, p) for p in positive_patterns) if positive_patterns else True
277-
)
278-
279-
# If any negative pattern matches, exclude the tool
280-
matches_negative = any(fnmatch.fnmatch(tool_name, p) for p in negative_patterns)
281-
282-
return matches_positive and not matches_negative
283-
284256
def set_accounts(self, account_ids: list[str]) -> StackOneToolSet:
285257
"""Set account IDs for filtering tools
286258

0 commit comments

Comments
 (0)