Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/structs/test_base_swarm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

Check failure

Code scanning / Pyre

Undefined import Error test

Undefined import [21]: Could not find a module corresponding to import pytest.


def test_base_swarm_module_can_be_imported():
"""Test that base_swarm module can be imported"""
from swarms.structs import base_swarm
assert base_swarm is not None


def test_base_swarm_class_exists():
"""Test that BaseSwarm class exists"""
from swarms.structs.base_swarm import BaseSwarm
assert BaseSwarm is not None


def test_base_swarm_is_abstract():
"""Test that BaseSwarm is an abstract base class"""
from swarms.structs.base_swarm import BaseSwarm
from abc import ABC
assert issubclass(BaseSwarm, ABC)
17 changes: 17 additions & 0 deletions tests/structs/test_base_swarm_placeholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

Check failure

Code scanning / Pyre

Undefined import Error test

Undefined import [21]: Could not find a module corresponding to import pytest.


def test_base_swarm_module_imports():
"""Test that base_swarm module can be imported"""
try:
from swarms.structs import base_swarm
assert base_swarm is not None
except ImportError:
pytest.skip("base_swarm module not found")


def test_base_swarm_placeholder():
"""Placeholder test for base_swarm - primarily contains classes"""
# base_swarm.py contains primarily class definitions
# Tests for class-based code would require more complex setup
assert True
104 changes: 104 additions & 0 deletions tests/structs/test_collaborative_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import pytest

Check failure

Code scanning / Pyre

Undefined import Error test

Undefined import [21]: Could not find a module corresponding to import pytest.
from swarms.structs.collaborative_utils import talk_to_agent
from swarms.structs.agent import Agent


def create_test_agent(name: str, description: str = "Test agent") -> Agent:
"""Create a real Agent instance for testing"""
return Agent(
agent_name=name,
agent_description=description,
system_prompt=f"You are {name}, a helpful test assistant.",
model_name="gpt-4o-mini",
max_loops=1,
verbose=False,
)


def test_talk_to_agent_success():
"""Test successful agent-to-agent communication"""
current_agent = create_test_agent("CurrentAgent")
target_agent = create_test_agent("TargetAgent")

agents = [current_agent, target_agent]

result = talk_to_agent(
current_agent=current_agent,
agents=agents,
task="What is 2+2?",
agent_name="TargetAgent",
max_loops=1
)

assert result is not None
# Result should be a list or string from the debate
assert len(str(result)) > 0


def test_talk_to_agent_not_found():
"""Test error when target agent not found"""
current_agent = create_test_agent("CurrentAgent")

agents = [current_agent]

with pytest.raises(ValueError, match="Agent 'NonExistent' not found"):
talk_to_agent(
current_agent=current_agent,
agents=agents,
task="Test task",
agent_name="NonExistent"
)


def test_talk_to_agent_with_max_loops():
"""Test talk_to_agent with custom max_loops"""
current_agent = create_test_agent("CurrentAgent")
target_agent = create_test_agent("TargetAgent")

agents = [current_agent, target_agent]

result = talk_to_agent(
current_agent=current_agent,
agents=agents,
task="Discuss the weather briefly",
agent_name="TargetAgent",
max_loops=2
)

assert result is not None


def test_talk_to_agent_no_agent_name_attribute():
"""Test when target agent is not found by name"""
current_agent = create_test_agent("CurrentAgent")
# Create another agent with different name
other_agent = create_test_agent("OtherAgent")

agents = [current_agent, other_agent]

with pytest.raises(ValueError, match="Agent 'TargetAgent' not found"):
talk_to_agent(
current_agent=current_agent,
agents=agents,
task="Test",
agent_name="TargetAgent"
)


def test_talk_to_agent_output_type():
"""Test talk_to_agent with custom output_type"""
current_agent = create_test_agent("CurrentAgent")
target_agent = create_test_agent("TargetAgent")

agents = [current_agent, target_agent]

result = talk_to_agent(
current_agent=current_agent,
agents=agents,
task="Say hello",
agent_name="TargetAgent",
output_type="str",
max_loops=1
)

assert result is not None
68 changes: 68 additions & 0 deletions tests/structs/test_concat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pytest

Check failure

Code scanning / Pyre

Undefined import Error test

Undefined import [21]: Could not find a module corresponding to import pytest.
from swarms.structs.concat import concat_strings


def test_concat_strings_basic():
"""Test basic string concatenation"""
result = concat_strings(["hello", " ", "world"])
assert result == "hello world"


def test_concat_strings_empty_list():
"""Test concatenation with empty list"""
result = concat_strings([])
assert result == ""


def test_concat_strings_single_element():
"""Test concatenation with single element"""
result = concat_strings(["hello"])
assert result == "hello"


def test_concat_strings_multiple_elements():
"""Test concatenation with multiple elements"""
result = concat_strings(["a", "b", "c", "d", "e"])
assert result == "abcde"


def test_concat_strings_with_special_characters():
"""Test concatenation with special characters"""
result = concat_strings(["hello", "\n", "world", "\t", "!"])
assert result == "hello\nworld\t!"


def test_concat_strings_not_list_raises_typeerror():
"""Test that non-list input raises TypeError"""
with pytest.raises(TypeError, match="Input must be a list of strings"):
concat_strings("not a list")


def test_concat_strings_non_string_element_raises_typeerror():
"""Test that list with non-string elements raises TypeError"""
with pytest.raises(TypeError, match="All elements in the list must be strings"):
concat_strings(["hello", 123, "world"])


def test_concat_strings_mixed_types_raises_typeerror():
"""Test that list with mixed types raises TypeError"""
with pytest.raises(TypeError, match="All elements in the list must be strings"):
concat_strings(["hello", None, "world"])


def test_concat_strings_with_numbers_raises_typeerror():
"""Test that list containing numbers raises TypeError"""
with pytest.raises(TypeError, match="All elements in the list must be strings"):
concat_strings([1, 2, 3])


def test_concat_strings_empty_strings():
"""Test concatenation with empty strings"""
result = concat_strings(["", "", ""])
assert result == ""


def test_concat_strings_unicode():
"""Test concatenation with unicode characters"""
result = concat_strings(["Hello", " ", "世界", " ", "🌍"])
assert result == "Hello 世界 🌍"
Loading
Loading