Skip to content

Commit

Permalink
removed bad tests for building models from typing.Any as it is not …
Browse files Browse the repository at this point in the history
…supported by pydantic or LLMs
  • Loading branch information
nicholishen committed Sep 25, 2024
1 parent a3ca984 commit 04a9a6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ def test_complex_nested_structure():
assert validated_data.profile.details.hobbies == ["reading", "swimming"]


def test_dynamic_field_types():
from typing import Any
# def test_dynamic_field_types():
# from typing import Any

dynamic_schema = {"value": Any}
model_name = "DynamicFieldModel"
Model = ModelBuilder().model_from_dict(dynamic_schema, model_name)
# dynamic_schema = {"value": Any}
# model_name = "DynamicFieldModel"
# Model = ModelBuilder().model_from_dict(dynamic_schema, model_name)

for input_value in [123, "abc", [1, 2, 3], {"key": "value"}]:
data = {"value": input_value}
validated_data = Model(**data)
assert validated_data.value == input_value
# for input_value in [123, "abc", [1, 2, 3], {"key": "value"}]:
# data = {"value": input_value}
# validated_data = Model(**data)
# assert validated_data.value == input_value


import pytest
Expand Down
12 changes: 6 additions & 6 deletions tests/test_builder_refactored.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ def test_create_model_with_nested_lists():
assert validated_data.items[1].quantity == 10


def test_create_model_with_any_type():
schema = {"value": Any}
Model = ModelBuilder().model_from_dict(schema, "AnyTypeModel")
# def test_create_model_with_any_type():
# schema = {"value": Any}
# Model = ModelBuilder().model_from_dict(schema, "AnyTypeModel")

for input_value in [123, "abc", [1, 2, 3], {"key": "value"}]:
validated_data = Model(value=input_value)
assert validated_data.value == input_value
# for input_value in [123, "abc", [1, 2, 3], {"key": "value"}]:
# validated_data = Model(value=input_value)
# assert validated_data.value == input_value


# JSON Schema Tests
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def test_rename_tool(tools):
assert tools['x'](x=1) == 1
assert tools['x']('{"x":1}') == 1
assert tools['x'].name == 'x'
assert list(tools)[-1]['function']['name'] == 'x'
assert list(tools.schemas)[-1]['function']['name'] == 'x'

def test_tool_dispatch_union():
tools = ToolDispatch(get_weather, get_sports_scores, base_model=BASE_MODEL)
other_tools = ToolDispatch(used_name, base_model=BASE_MODEL, __doc__="OTHER_TOOLS")
new_tools = tools | other_tools
new_tools['x'] = async_tool
assert len(list(new_tools)) == 4
assert len(list(new_tools.schemas)) == 4
assert 'x' in new_tools
func_disp = {**new_tools}
assert len(func_disp) == 4
assert 'x' in func_disp
assert all(isinstance(x, dict) for x in tools)
assert all(isinstance(x, dict) for x in tools.schemas)

def test_async_tool(tools):
tools['async_tool'] = async_tool
Expand Down

0 comments on commit 04a9a6c

Please sign in to comment.