Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit e7820ed

Browse files
committed
modified: CHANGELOG.md
modified: simpletool/models.py modified: tests/conftest.py modified: tests/test_errors.py
1 parent 91994e2 commit e7820ed

File tree

4 files changed

+38
-32
lines changed

4 files changed

+38
-32
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/),
66
and this project adheres to [SimpleTool](https://github.com/nchekwa/simpletool-python/tree/master).
77

8+
# [0.0.16] - 2025-01-11 Milestone Alpha2
9+
10+
## Fixed
11+
- incorrect `SimpleToolResponseModel` Pydantic model configuration + from_attributes allow easy serialize/deserialize
12+
813
# [0.0.15] - 2025-01-09 Milestone Alpha2
914

1015
## Fixed

simpletool/models.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ class SimpleToolResponseModel(BaseModel):
4646

4747
class Config:
4848
"""Pydantic model configuration."""
49-
schema_extra = {
50-
"example": {
51-
"name": "example_tool",
52-
"description": "An example tool for demonstration",
53-
"input_schema": {
54-
"type": "object",
55-
"properties": {
56-
"input": {"type": "string"}
49+
model_config = {
50+
"json_schema_extra": {
51+
"example": {
52+
"name": "example_tool",
53+
"description": "An example tool for demonstration",
54+
"input_schema": {
55+
"type": "object",
56+
"properties": {
57+
"input": {"type": "string"}
58+
}
5759
}
5860
}
59-
}
61+
},
62+
"from_attributes": True # Enables serialization from other types
6063
}

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def pytest_collection_modifyitems(config, items):
2020
warnings.filterwarnings(
2121
"ignore",
2222
category=pytest.PytestCollectionWarning,
23-
message=f"{item} cannot collect test class .* because it has a __init__ constructor"
23+
message=r".*cannot collect test class .* because it has a __init__ constructor"
2424
)

tests/test_errors.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,32 @@
55
from simpletool.errors import SimpleToolError, ValidationError
66

77

8-
def test_simple_tool_error():
9-
"""Test SimpleToolError initialization and attributes."""
10-
error = SimpleToolError(
11-
message="Test error",
12-
code=501,
13-
details={"context": "test"}
14-
)
15-
16-
assert str(error) == "Test error"
17-
assert error.message == "Test error"
18-
assert error.code == 501
19-
assert error.details == {"context": "test"}
8+
@pytest.mark.parametrize("error_class,input_data,expected", [
9+
(
10+
SimpleToolError,
11+
{"message": "Test error", "code": 501, "details": {"context": "test"}},
12+
{"str": "Test error", "code": 501, "details": {"context": "test"}}
13+
),
14+
(
15+
SimpleToolError,
16+
{"message": "Default error"},
17+
{"str": "Default error", "code": 500, "details": {}}
18+
),
19+
])
20+
def test_error_initialization(error_class, input_data, expected):
21+
"""Test error class initialization with various inputs."""
22+
error = error_class(**input_data)
2023

21-
22-
def test_simple_tool_error_default_values():
23-
"""Test SimpleToolError with default values."""
24-
error = SimpleToolError("Default error")
25-
26-
assert str(error) == "Default error"
27-
assert error.message == "Default error"
28-
assert error.code == 500
29-
assert error.details == {}
24+
assert str(error) == expected["str"]
25+
assert error.message == expected["str"]
26+
assert error.code == expected["code"]
27+
assert error.details == expected["details"]
3028

3129

3230
def test_validation_error():
3331
"""Test ValidationError initialization."""
3432
error = ValidationError(field="test_field", reason="Invalid input")
35-
33+
3634
assert str(error) == "Validation failed for field 'test_field': Invalid input"
3735
assert error.message == "Validation failed for field 'test_field': Invalid input"
3836
assert error.code == 400

0 commit comments

Comments
 (0)