cleanup operaiton

pull/1175/head
Kye Gomez 4 days ago
parent e7b43eef1e
commit 97ebbb9e55

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "8.5.4"
version = "8.6.0"
description = "Swarms - TGSC"
license = "MIT"
authors = ["Kye Gomez <kye@swarms.world>"]

@ -57,7 +57,10 @@ def test_initialization():
)
assert len(agent_rearrange.agents) == 3
assert agent_rearrange.flow == "ResearchAgent -> WriterAgent -> ReviewerAgent"
assert (
agent_rearrange.flow
== "ResearchAgent -> WriterAgent -> ReviewerAgent"
)
assert agent_rearrange.max_loops == 1
assert agent_rearrange.verbose is True
print("✓ test_initialization passed")
@ -74,7 +77,10 @@ def test_initialization_with_team_awareness():
verbose=True,
)
assert agent_rearrange.flow == "ResearchAgent -> WriterAgent -> ReviewerAgent"
assert (
agent_rearrange.flow
== "ResearchAgent -> WriterAgent -> ReviewerAgent"
)
print("✓ test_initialization_with_team_awareness passed")
@ -317,7 +323,9 @@ def test_get_agent_sequential_awareness():
verbose=True,
)
awareness = agent_rearrange.get_agent_sequential_awareness("WriterAgent")
awareness = agent_rearrange.get_agent_sequential_awareness(
"WriterAgent"
)
assert awareness is not None
assert isinstance(awareness, str)
print("✓ test_get_agent_sequential_awareness passed")
@ -506,9 +514,9 @@ def main():
test_complete_workflow,
]
print("="*60)
print("=" * 60)
print("Running AgentRearrange Tests")
print("="*60)
print("=" * 60)
for test in tests:
try:
@ -516,9 +524,9 @@ def main():
except Exception as e:
print(f"{test.__name__} failed: {e}")
print("="*60)
print("=" * 60)
print("All tests completed!")
print("="*60)
print("=" * 60)
if __name__ == "__main__":

@ -37,6 +37,7 @@ def create_sample_agents():
),
]
# ============================================================================
# Initialization Tests
# ============================================================================
@ -67,7 +68,7 @@ def test_default_initialization():
def test_custom_initialization():
"""Test SwarmRouter with custom parameters."""
sample_agents = create_sample_agents()
router = SwarmRouter(
name="test-router",
description="Test router description",
@ -102,7 +103,7 @@ def test_custom_initialization():
def test_initialization_with_heavy_swarm_config():
"""Test SwarmRouter with HeavySwarm specific configuration."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
swarm_type="HeavySwarm",
@ -114,7 +115,9 @@ def test_initialization_with_heavy_swarm_config():
assert router.swarm_type == "HeavySwarm"
assert router.heavy_swarm_loops_per_agent == 2
assert router.heavy_swarm_question_agent_model_name == "gpt-4o-mini"
assert (
router.heavy_swarm_question_agent_model_name == "gpt-4o-mini"
)
assert router.heavy_swarm_worker_model_name == "gpt-4o-mini"
assert router.heavy_swarm_swarm_show_output is False
@ -132,6 +135,7 @@ def test_initialization_with_agent_rearrange_config():
assert router.swarm_type == "AgentRearrange"
assert router.rearrange_flow == "ResearchAgent -> CodeAgent"
# ============================================================================
# Configuration Tests
# ============================================================================
@ -140,7 +144,7 @@ def test_initialization_with_agent_rearrange_config():
def test_initialization_with_shared_memory():
"""Test SwarmRouter with shared memory system."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
shared_memory_system=None, # Test with None for now
@ -152,7 +156,7 @@ def test_initialization_with_shared_memory():
def test_initialization_with_worker_tools():
"""Test SwarmRouter with worker tools."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
worker_tools=[], # Empty list for now
@ -160,6 +164,7 @@ def test_initialization_with_worker_tools():
assert router.worker_tools == []
# ============================================================================
# Document Management Tests
# ============================================================================
@ -193,6 +198,7 @@ def test_router_with_documents():
assert router.documents[0].file_path == "/path/to/doc1.txt"
assert router.documents[1].file_path == "/path/to/doc2.txt"
# ============================================================================
# Configuration Class Tests
# ============================================================================
@ -249,6 +255,7 @@ def test_router_with_config():
assert router.swarm_type == config.swarm_type
assert router.rules == config.rules
# ============================================================================
# Basic Execution Tests
# ============================================================================
@ -257,7 +264,7 @@ def test_router_with_config():
def test_run_with_sequential_workflow():
"""Test running SwarmRouter with SequentialWorkflow."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
swarm_type="SequentialWorkflow",
@ -297,6 +304,7 @@ def test_run_with_none_task():
result = router.run(None)
assert result is not None
# ============================================================================
# Batch Processing Tests
# ============================================================================
@ -305,7 +313,7 @@ def test_run_with_none_task():
def test_batch_run_with_tasks():
"""Test batch processing with multiple tasks."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
verbose=False,
@ -313,7 +321,7 @@ def test_batch_run_with_tasks():
tasks = ["What is 1+1?", "What is 2+2?"]
results = router.batch_run(tasks)
assert len(results) == 2
assert all(result is not None for result in results)
@ -321,7 +329,7 @@ def test_batch_run_with_tasks():
def test_batch_run_with_empty_tasks():
"""Test batch processing with empty task list."""
sample_agents = create_sample_agents()
router = SwarmRouter(agents=sample_agents)
results = router.batch_run([])
@ -335,6 +343,7 @@ def test_batch_run_with_no_agents():
with pytest.raises(RuntimeError):
router.batch_run(["Test task"])
# ============================================================================
# Call Method Tests
# ============================================================================
@ -343,7 +352,7 @@ def test_batch_run_with_no_agents():
def test_call_method():
"""Test __call__ method."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
verbose=False,
@ -356,7 +365,7 @@ def test_call_method():
def test_call_with_image():
"""Test __call__ method with image."""
sample_agents = create_sample_agents()
router = SwarmRouter(
agents=sample_agents,
verbose=False,
@ -366,6 +375,7 @@ def test_call_with_image():
result = router("Describe this image", img=None)
assert result is not None
# ============================================================================
# Output Type Tests
# ============================================================================
@ -374,17 +384,18 @@ def test_call_with_image():
def test_different_output_types():
"""Test router with different output types."""
sample_agents = create_sample_agents()
for output_type in ["dict", "json", "string", "list"]:
router = SwarmRouter(
agents=sample_agents,
output_type=output_type,
verbose=False,
)
result = router.run("Simple test task")
assert result is not None
# ============================================================================
# Error Handling Tests
# ============================================================================
@ -413,9 +424,12 @@ def test_invalid_swarm_type():
)
# But should raise ValueError during execution when creating swarm
with pytest.raises(ValueError, match="Invalid swarm type: InvalidSwarmType"):
with pytest.raises(
ValueError, match="Invalid swarm type: InvalidSwarmType"
):
router.run("Test task")
# ============================================================================
# Integration Tests
# ============================================================================
@ -425,7 +439,7 @@ def test_complete_workflow():
"""Test complete workflow from initialization to execution."""
# Create agents
agents = create_sample_agents()
# Create router with configuration
router = SwarmRouter(
name="integration-test-router",
@ -436,11 +450,11 @@ def test_complete_workflow():
verbose=False,
output_type="string",
)
# Execute single task
result = router.run("Calculate the sum of 5 and 7")
assert result is not None
# Execute batch tasks
tasks = [
"What is 10 + 15?",
@ -448,7 +462,7 @@ def test_complete_workflow():
"What is 6 * 7?",
]
batch_results = router.batch_run(tasks)
assert len(batch_results) == 3
assert all(result is not None for result in batch_results)
@ -456,22 +470,22 @@ def test_complete_workflow():
def test_router_reconfiguration():
"""Test reconfiguring router after initialization."""
sample_agents = create_sample_agents()
router = SwarmRouter(agents=sample_agents)
# Change configuration
router.max_loops = 3
router.output_type = "json"
router.verbose = False
assert router.max_loops == 3
assert router.output_type == "json"
assert router.verbose is False
# Test execution with new configuration
result = router.run("Test reconfiguration")
assert result is not None
if __name__ == "__main__":
pytest.main([__file__, "-v"])
pytest.main([__file__, "-v"])

@ -6,7 +6,7 @@ from typing import Any, Callable, Dict, List
from dotenv import load_dotenv
from loguru import logger
from swarms.structs import (
from swarms import (
Agent,
AgentRearrange,
ConcurrentWorkflow,
@ -19,8 +19,9 @@ from swarms.structs import (
SequentialWorkflow,
SpreadSheetSwarm,
SwarmRouter,
HierarchicalSwarm,
)
from swarms.structs.hiearchical_swarm import HierarchicalSwarm
from swarms.structs.tree_swarm import ForestSwarm, Tree, TreeAgent
load_dotenv()
@ -35,10 +36,18 @@ def write_markdown_report(
results: List[Dict[str, Any]], filename: str
):
"""Write test results to a markdown file"""
if not os.path.exists("test_runs"):
os.makedirs("test_runs")
workspace_dir = os.getenv("WORKSPACE_DIR")
if not workspace_dir:
raise ValueError(
"WORKSPACE_DIR environment variable is not set"
)
test_runs_dir = os.path.join(workspace_dir, "test_runs")
if not os.path.exists(test_runs_dir):
os.makedirs(test_runs_dir)
with open(f"test_runs/{filename}.md", "w") as f:
file_path = os.path.join(test_runs_dir, f"{filename}.md")
with open(file_path, "w") as f:
f.write("# Swarms Comprehensive Test Report\n\n")
f.write(
f"Test Run: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
Loading…
Cancel
Save