mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-15 19:18:30 +00:00
Fix test failures for serialization changes
- Update test_invalid_input_types to test actual serialization failure - Update test_interpolate_only_unsupported_type_error with proper __repr__ method - Update test_interpolate_invalid_type_validation to test serialization vs rejection - Update test_interpolate_custom_object_validation to distinguish serializable vs unserializable objects - All tests now align with new behavior where unsupported types are serialized instead of rejected Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -91,16 +91,19 @@ class TestInterpolateOnly:
|
||||
assert "name" in str(excinfo.value)
|
||||
|
||||
def test_invalid_input_types(self):
|
||||
"""Test that an error is raised with invalid input types."""
|
||||
"""Test that an error is raised when serialization fails."""
|
||||
class UnserializableObject:
|
||||
def __str__(self):
|
||||
raise Exception("Cannot convert to string")
|
||||
def __repr__(self):
|
||||
raise Exception("Cannot convert to string")
|
||||
|
||||
template = "Hello, {name}!"
|
||||
# Using Any for this test since we're intentionally testing an invalid type
|
||||
inputs: Dict[str, Any] = {"name": object()} # Object is not a valid input type
|
||||
inputs: Dict[str, Any] = {"name": UnserializableObject()}
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
with pytest.raises(ValueError, match="Unable to serialize UnserializableObject"):
|
||||
interpolate_only(template, inputs)
|
||||
|
||||
assert "unsupported type" in str(excinfo.value).lower()
|
||||
|
||||
def test_empty_input_string(self):
|
||||
"""Test handling of empty or None input string."""
|
||||
inputs: Dict[str, Union[str, int, float, Dict[str, Any], List[Any]]] = {
|
||||
@@ -223,6 +226,8 @@ class TestInterpolateOnly:
|
||||
class CustomObject:
|
||||
def __str__(self):
|
||||
raise Exception("Cannot serialize")
|
||||
def __repr__(self):
|
||||
raise Exception("Cannot serialize")
|
||||
|
||||
with pytest.raises(ValueError, match="Unable to serialize CustomObject"):
|
||||
interpolate_only("Value: {obj}", {"obj": CustomObject()})
|
||||
|
||||
Reference in New Issue
Block a user