Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
ok
thomashebrard5c71591fe893
diff --git a/tests/unit/core/stuffs/data.py b/tests/unit/core/stuffs/data.pynew file mode 100644index 000000000..1195a32e9--- /dev/null+++ b/tests/unit/core/stuffs/data.py@@ -0,0 +1,304 @@+from typing import ClassVar++from pydantic import Field++from pipelex.client.protocol import StuffContentOrData+from pipelex.core.concepts.concept_blueprint import ConceptBlueprint+from pipelex.core.concepts.concept_factory import ConceptFactory+from pipelex.core.concepts.concept_native import NativeConceptCode+from pipelex.core.stuffs.list_content import ListContent+from pipelex.core.stuffs.structured_content import StructuredContent+from pipelex.core.stuffs.stuff import Stuff+from pipelex.core.stuffs.text_content import TextContent+++class MySubClass(StructuredContent):+ arg4: str = Field(description="Test argument 4")+++class MyConcept(StructuredContent):+ arg1: str = Field(description="Test argument 1")+ arg2: int = Field(description="Test argument 2")+ arg3: MySubClass = Field(description="Test argument 3")+++class TestData:+ CASE: ClassVar[list[tuple[str, StuffContentOrData, str, str, Stuff]]] = [+ # Case 1.1: Content is a string+ (+ "case-1.1-string",+ "Lorem Ipsum",+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="Lorem Ipsum"),+ ),+ ),+ # Case 1.2: Content is a list of strings+ (+ "case-1.2-list-of-strings",+ ["Lorem Ipsum 1", "Lorem Ipsum 2", "Lorem Ipsum 3"],+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=ListContent(+ items=[+ TextContent(text="Lorem Ipsum 1"),+ TextContent(text="Lorem Ipsum 2"),+ TextContent(text="Lorem Ipsum 3"),+ ]+ ),+ ),+ ),+ # Case 1.3: Content is a StuffContent object+ (+ "case-1.3-stuff-content-object",+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ ),+ ),+ # Case 1.4: Content is a list of StuffContent objects+ (+ "case-1.4-list-of-stuff-content-objects",+ [+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ],+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=ListContent(+ items=[+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ]+ ),+ ),+ ),+ # Case 2.1: Content is a string+ (+ "case-2.1-dict-with-string-content",+ {"concept": "Text", "content": "my text"},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="my text"),+ ),+ ),+ # Case 2.1b: Content is a string with native prefix+ (+ "case-2.1b-dict-with-string-content-native-prefix",+ {"concept": "native.Text", "content": "my text"},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="my text"),+ ),+ ),+ # case 2.1c: Content is a string but the concept is not native.Text, but a concept initiable by str+ (+ "case-2.1c-dict-with-string-content-not-native-text",+ {"concept": "test_domain.MyConceptNotNativeText", "content": "my text"},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make_from_blueprint(+ domain="test_domain",+ concept_code="MyConceptNotNativeText",+ blueprint=ConceptBlueprint(+ description="Test concept for unit tests",+ ),+ ),+ content=TextContent(text="my text"),+ ),+ ),+ # Case 2.2: Content is a list of strings+ (+ "case-2.2-dict-with-list-of-strings",+ {"concept": "Text", "content": ["text1", "text2", "text3"]},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=ListContent(+ items=[+ TextContent(text="text1"),+ TextContent(text="text2"),+ TextContent(text="text3"),+ ]+ ),+ ),+ ),+ # case 2.2b: Content is a list of strings but the concept is not native.Text, but a concept initiable by str+ (+ "case-2.2b-dict-with-list-of-strings-not-native-text",+ {"concept": "test_domain.MyConceptNotNativeText", "content": ["text1", "text2", "text3"]},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make_from_blueprint(+ domain="test_domain",+ concept_code="MyConceptNotNativeText",+ blueprint=ConceptBlueprint(+ description="Test concept for unit tests",+ ),+ ),+ content=ListContent(+ items=[+ TextContent(text="text1"),+ TextContent(text="text2"),+ TextContent(text="text3"),+ ]+ ),+ ),+ ),+ # Case 2.3: Content is a StuffContent object+ (+ "case-2.3-dict-with-stuff-content-object",+ {+ "concept": "test_domain.MyConcept",+ "content": MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ ),+ ),+ # Case 2.4: Content is a list of StuffContent objects+ (+ "case-2.4-dict-with-list-of-stuff-content-objects",+ {+ "concept": "test_domain.MyConcept",+ "content": [+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ],+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=ListContent(+ items=[+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ]+ ),+ ),+ ),+ # Case 2.5: Content is a dict+ (+ "case-2.5-dict-with-dict-content",+ {+ "concept": "test_domain.MyConcept",+ "content": {+ "arg1": "something",+ "arg2": 1,+ "arg3": {"arg4": "something else else"},+ },+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),+ ),+ ),+ # Case 2.6: Content is a list of dicts+ (+ "case-2.6-dict-with-list-of-dicts",+ {+ "concept": "test_domain.MyConcept",+ "content": [+ {+ "arg1": "something",+ "arg2": 1,+ "arg3": {"arg4": "something else else"},+ },+ {+ "arg1": "something else",+ "arg2": 2,+ "arg3": {"arg4": "something else else else"},+ },+ ],+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=ListContent(+ items=[+ MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),+ MyConcept(arg1="something else", arg2=2, arg3=MySubClass(arg4="something else else else")),+ ]+ ),+ ),+ ),+ ]diff --git a/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py b/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.pyindex e4ff3fc16..f62a835ee 100644--- a/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py+++ b/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py@@ -1,34 +1,20 @@import os-from typing import Anyimport pytest-from pydantic import Fieldfrom pipelex import logfrom pipelex.client.protocol import StuffContentOrDatafrom pipelex.core.concepts.concept_blueprint import ConceptBlueprintfrom pipelex.core.concepts.concept_factory import ConceptFactory-from pipelex.core.concepts.concept_native import NativeConceptCode-from pipelex.core.stuffs.list_content import ListContentfrom pipelex.core.stuffs.structured_content import StructuredContentfrom pipelex.core.stuffs.stuff import Stufffrom pipelex.core.stuffs.stuff_factory import StuffFactory-from pipelex.core.stuffs.text_content import TextContentfrom pipelex.hub import get_concept_libraryfrom pipelex.system.registries.class_registry_utils import ClassRegistryUtils+from tests.unit.core.stuffs.data import TestData-class MySubClass(StructuredContent):- arg4: str = Field(description="Test argument 4")---class MyConcept(StructuredContent):- arg1: str = Field(description="Test argument 1")- arg2: int = Field(description="Test argument 2")- arg3: MySubClass = Field(description="Test argument 3")--[email protected](scope="class")def setup_test_concept():# Register the class in the class registryClassRegistryUtils.register_classes_in_file(@@ -78,88 +64,10 @@ class TestStuffFactoryImplicitMemory:@pytest.mark.parametrize(("test_name", "stuff_content_or_data", "stuff_name", "stuff_code", "expected_stuff"),- [- # Case 1.1: Content is a string- pytest.param(- "case-1.1-string",- "Lorem Ipsum",- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=TextContent(text="Lorem Ipsum"),- ),- ),- # Case 1.2: Content is a list of strings- pytest.param(- "case-1.2-list-of-strings",- ["Lorem Ipsum 1", "Lorem Ipsum 2", "Lorem Ipsum 3"],- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=ListContent(- items=[- TextContent(text="Lorem Ipsum 1"),- TextContent(text="Lorem Ipsum 2"),- TextContent(text="Lorem Ipsum 3"),- ]- ),- ),- ),- # Case 1.3: Content is a StuffContent object- pytest.param(- "case-1.3-stuff-content-object",- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- ),- ),- # Case 1.4: Content is a list of StuffContent objects- pytest.param(- "case-1.4-list-of-stuff-content-objects",- [- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ],- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=ListContent(- items=[- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ]- ),- ),- ),- ],+ TestData.CASE,)- def test_case1_direct_content(+ def test_case(self,- setup_test_concept: Any,test_name: str,stuff_content_or_data: StuffContentOrData,stuff_name: str,@@ -175,231 +83,6 @@ class TestStuffFactoryImplicitMemory:)assert result == expected_stuff- @pytest.mark.parametrize(- ("test_name", "stuff_content_or_data", "stuff_name", "stuff_code", "expected_stuff"),- [- # Case 2.1: Content is a string- pytest.param(- "case-2.1-dict-with-string-content",- {"concept": "Text", "content": "my text"},- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=TextContent(text="my text"),- ),- ),- # Case 2.1b: Content is a string with native prefix- pytest.param(- "case-2.1b-dict-with-string-content-native-prefix",- {"concept": "native.Text", "content": "my text"},- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=TextContent(text="my text"),- ),- ),- # case 2.1c: Content is a string but the concept is not native.Text, but a concept initiable by str- pytest.param(- "case-2.1c-dict-with-string-content-not-native-text",- {"concept": "test_domain.MyConceptNotNativeText", "content": "my text"},- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make_from_blueprint(- domain="test_domain",- concept_code="MyConceptNotNativeText",- blueprint=ConceptBlueprint(- description="Test concept for unit tests",- ),- ),- content=TextContent(text="my text"),- ),- ),- # Case 2.2: Content is a list of strings- pytest.param(- "case-2.2-dict-with-list-of-strings",- {"concept": "Text", "content": ["text1", "text2", "text3"]},- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=ListContent(- items=[- TextContent(text="text1"),- TextContent(text="text2"),- TextContent(text="text3"),- ]- ),- ),- ),- # case 2.2b: Content is a list of strings but the concept is not native.Text, but a concept initiable by str- pytest.param(- "case-2.2b-dict-with-list-of-strings-not-native-text",- {"concept": "test_domain.MyConceptNotNativeText", "content": ["text1", "text2", "text3"]},- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make_from_blueprint(- domain="test_domain",- concept_code="MyConceptNotNativeText",- blueprint=ConceptBlueprint(- description="Test concept for unit tests",- ),- ),- content=ListContent(- items=[- TextContent(text="text1"),- TextContent(text="text2"),- TextContent(text="text3"),- ]- ),- ),- ),- # Case 2.3: Content is a StuffContent object- pytest.param(- "case-2.3-dict-with-stuff-content-object",- {- "concept": "test_domain.MyConcept",- "content": MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- },- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- ),- ),- # Case 2.4: Content is a list of StuffContent objects- pytest.param(- "case-2.4-dict-with-list-of-stuff-content-objects",- {- "concept": "test_domain.MyConcept",- "content": [- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ],- },- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=ListContent(- items=[- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ]- ),- ),- ),- # Case 2.5: Content is a dict- pytest.param(- "case-2.5-dict-with-dict-content",- {- "concept": "test_domain.MyConcept",- "content": {- "arg1": "something",- "arg2": 1,- "arg3": {"arg4": "something else else"},- },- },- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),- ),- ),- # Case 2.6: Content is a list of dicts- pytest.param(- "case-2.6-dict-with-list-of-dicts",- {- "concept": "test_domain.MyConcept",- "content": [- {- "arg1": "something",- "arg2": 1,- "arg3": {"arg4": "something else else"},- },- {- "arg1": "something else",- "arg2": 2,- "arg3": {"arg4": "something else else else"},- },- ],- },- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=ListContent(- items=[- MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),- MyConcept(arg1="something else", arg2=2, arg3=MySubClass(arg4="something else else else")),- ]- ),- ),- ),- ],- )- def test_case2_dict_with_concept_and_content(- self,- setup_test_concept: Any,- test_name: str,- stuff_content_or_data: StuffContentOrData,- stuff_name: str,- stuff_code: str,- expected_stuff: Stuff,- ):- """Test Case 2: Dict with concept and content keys."""- log.info(f"Test Case 2: Dict with concept and content keys. {test_name}")- log.debug(f"setup_test_concept: {setup_test_concept}")- result = StuffFactory.make_stuff_from_stuff_content_or_data(- name=stuff_name,- code=stuff_code,- stuff_content_or_data=stuff_content_or_data,- )- assert result == expected_stuff-# class TestStuffFactoryImplicitMemoryEdgeCases:# """Test edge cases and error conditions."""