mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-14 15:25:17 +02:00
fixbug: Optional not working
This commit is contained in:
parent
0592b1f9e1
commit
e199c6b476
2 changed files with 31 additions and 5 deletions
|
|
@ -6,7 +6,7 @@
|
|||
@File : test_action_node.py
|
||||
"""
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel, Field, ValidationError
|
||||
|
|
@ -302,6 +302,18 @@ def test_action_node_from_pydantic_and_print_everything():
|
|||
assert "tasks" in code, "tasks should be in code"
|
||||
|
||||
|
||||
def test_optional():
|
||||
mapping = {
|
||||
"Logic Analysis": (Optional[List[Tuple[str, str]]], Field(default=None)),
|
||||
"Task list": (Optional[List[str]], None),
|
||||
"Anything UNCLEAR": (Optional[str], None),
|
||||
}
|
||||
m = {"Anything UNCLEAR": "a"}
|
||||
t = ActionNode.create_model_class("test_class_1", mapping)
|
||||
|
||||
t1 = t(**m)
|
||||
assert t1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_create_model_class()
|
||||
test_create_model_class_with_mapping()
|
||||
pytest.main([__file__, "-s"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue