mirror of
https://github.com/microsoft/autogen.git
synced 2025-11-14 00:54:58 +00:00
Update test_add_conditional_edges to work with string conditions
Co-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
This commit is contained in:
parent
247dae035b
commit
cf0a38cd41
@ -1040,27 +1040,17 @@ def test_add_conditional_edges() -> None:
|
|||||||
edges = builder.nodes["A"].edges
|
edges = builder.nodes["A"].edges
|
||||||
assert len(edges) == 2
|
assert len(edges) == 2
|
||||||
|
|
||||||
# Conditions are now lambda functions, so we can't directly compare them
|
# Extract the condition strings to compare them
|
||||||
# We'll test them with mock messages
|
conditions = [e.condition for e in edges]
|
||||||
yes_message = TextMessage(content="This contains yes", source="test")
|
assert "yes" in conditions
|
||||||
no_message = TextMessage(content="This contains no", source="test")
|
assert "no" in conditions
|
||||||
other_message = TextMessage(content="This contains nothing", source="test")
|
|
||||||
|
|
||||||
# Find edges by testing with each message
|
# Match edge targets with conditions
|
||||||
yes_matches = [e for e in edges if e.check_condition(yes_message)]
|
yes_edge = next(e for e in edges if e.condition == "yes")
|
||||||
no_matches = [e for e in edges if e.check_condition(no_message)]
|
no_edge = next(e for e in edges if e.condition == "no")
|
||||||
|
|
||||||
# Should be exactly one edge that matches each message
|
assert yes_edge.target == "B"
|
||||||
assert len(yes_matches) == 1
|
assert no_edge.target == "C"
|
||||||
assert len(no_matches) == 1
|
|
||||||
|
|
||||||
# These edges should go to the expected targets
|
|
||||||
assert yes_matches[0].target == "B"
|
|
||||||
assert no_matches[0].target == "C"
|
|
||||||
|
|
||||||
# Check if "other_message" doesn't match any edge, meaning neither "yes" nor "no" is in it
|
|
||||||
other_matches = [e for e in edges if e.check_condition(other_message)]
|
|
||||||
assert len(other_matches) == 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_entry_point() -> None:
|
def test_set_entry_point() -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user