From eb18d416e470889de34116be775bb537f56110d1 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Tue, 7 Oct 2025 01:33:00 -0700 Subject: [PATCH] [TESTS][Fix these tests] --- asb_research.py | 2 +- .../heavy_swarm_examples/heavy_swarm.py | 0 tests/prompts/test_prompt.py | 0 tests/telemetry/test_user_utils.py | 51 +------- tests/test_comprehensive_test.py | 30 ++--- tests/{utils => tools}/test_output_str_fix.py | 0 tests/utils/test_acompletions.py | 8 -- tests/{ => utils}/test_docstring_parser.py | 0 tests/utils/test_formatter.py | 3 - tests/utils/test_litellm_wrapper.py | 12 -- tests/utils/test_math_eval.py | 2 +- tests/utils/test_md_output.py | 14 +- tests/utils/test_print_class_parameters.py | 120 ------------------ 13 files changed, 19 insertions(+), 223 deletions(-) rename heavy_swarm.py => examples/multi_agent/heavy_swarm_examples/heavy_swarm.py (100%) delete mode 100644 tests/prompts/test_prompt.py rename tests/{utils => tools}/test_output_str_fix.py (100%) rename tests/{ => utils}/test_docstring_parser.py (100%) delete mode 100644 tests/utils/test_print_class_parameters.py diff --git a/asb_research.py b/asb_research.py index 00d778b3..f63f36ff 100644 --- a/asb_research.py +++ b/asb_research.py @@ -15,4 +15,4 @@ result = swarm.run( task="Build a swarm to write a research paper on the topic of AI" ) -print(json.dumps(result, indent=2)) +print(json.dumps(result, indent=2)) \ No newline at end of file diff --git a/heavy_swarm.py b/examples/multi_agent/heavy_swarm_examples/heavy_swarm.py similarity index 100% rename from heavy_swarm.py rename to examples/multi_agent/heavy_swarm_examples/heavy_swarm.py diff --git a/tests/prompts/test_prompt.py b/tests/prompts/test_prompt.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/telemetry/test_user_utils.py b/tests/telemetry/test_user_utils.py index d1f72404..26465fb5 100644 --- a/tests/telemetry/test_user_utils.py +++ b/tests/telemetry/test_user_utils.py @@ -1,10 +1,8 @@ import uuid from swarms.telemetry.main import ( - generate_unique_identifier, generate_user_id, get_machine_id, - get_system_info, ) @@ -24,33 +22,6 @@ def test_get_machine_id(): assert all(char in "0123456789abcdef" for char in machine_id) -def test_get_system_info(): - # Get system information and ensure it's a dictionary with expected keys - system_info = get_system_info() - assert isinstance(system_info, dict) - expected_keys = [ - "platform", - "platform_release", - "platform_version", - "architecture", - "hostname", - "ip_address", - "mac_address", - "processor", - "python_version", - ] - assert all(key in system_info for key in expected_keys) - - -def test_generate_unique_identifier(): - # Generate unique identifiers and ensure they are valid UUID strings - unique_id = generate_unique_identifier() - assert isinstance(unique_id, str) - assert uuid.UUID( - unique_id, version=5, namespace=uuid.NAMESPACE_DNS - ) - - def test_generate_user_id_edge_case(): # Test generate_user_id with multiple calls user_ids = set() @@ -69,33 +40,13 @@ def test_get_machine_id_edge_case(): assert len(machine_ids) == 100 # Ensure generated IDs are unique -def test_get_system_info_edge_case(): - # Test get_system_info for consistency - system_info1 = get_system_info() - system_info2 = get_system_info() - assert ( - system_info1 == system_info2 - ) # Ensure system info remains the same - - -def test_generate_unique_identifier_edge_case(): - # Test generate_unique_identifier for uniqueness - unique_ids = set() - for _ in range(100): - unique_id = generate_unique_identifier() - unique_ids.add(unique_id) - assert len(unique_ids) == 100 # Ensure generated IDs are unique - def test_all(): test_generate_user_id() test_get_machine_id() - test_get_system_info() - test_generate_unique_identifier() test_generate_user_id_edge_case() test_get_machine_id_edge_case() - test_get_system_info_edge_case() - test_generate_unique_identifier_edge_case() + test_all() diff --git a/tests/test_comprehensive_test.py b/tests/test_comprehensive_test.py index ed3e7a4f..f92682da 100644 --- a/tests/test_comprehensive_test.py +++ b/tests/test_comprehensive_test.py @@ -1,37 +1,29 @@ -import os import json +import os from datetime import datetime -from typing import List, Dict, Any, Callable +from typing import Any, Callable, Dict, List from dotenv import load_dotenv +from loguru import logger # Basic Imports for Swarms from swarms.structs import ( Agent, - SequentialWorkflow, - ConcurrentWorkflow, AgentRearrange, - MixtureOfAgents, - SpreadSheetSwarm, + ConcurrentWorkflow, GroupChat, - MultiAgentRouter, + InteractiveGroupChat, MajorityVoting, - SwarmRouter, + MixtureOfAgents, + MultiAgentRouter, RoundRobinSwarm, - InteractiveGroupChat, + SequentialWorkflow, + SpreadSheetSwarm, + SwarmRouter, ) - -# Import swarms not in __init__.py directly from swarms.structs.hiearchical_swarm import HierarchicalSwarm from swarms.structs.tree_swarm import ForestSwarm, Tree, TreeAgent -# Setup Logging -from loguru import logger - -logger.add( - "test_runs/test_failures.log", rotation="10 MB", level="ERROR" -) - # Load environment variables load_dotenv() @@ -463,8 +455,8 @@ def test_spreadsheet_swarm(): def test_hierarchical_swarm(): """Test HierarchicalSwarm structure""" try: - from swarms.utils.litellm_wrapper import LiteLLM from swarms.structs.hiearchical_swarm import SwarmSpec + from swarms.utils.litellm_wrapper import LiteLLM # Create worker agents workers = [ diff --git a/tests/utils/test_output_str_fix.py b/tests/tools/test_output_str_fix.py similarity index 100% rename from tests/utils/test_output_str_fix.py rename to tests/tools/test_output_str_fix.py diff --git a/tests/utils/test_acompletions.py b/tests/utils/test_acompletions.py index 3a73ab87..9a318cdd 100644 --- a/tests/utils/test_acompletions.py +++ b/tests/utils/test_acompletions.py @@ -3,14 +3,6 @@ from dotenv import load_dotenv load_dotenv() -## [OPTIONAL] REGISTER MODEL - not all ollama models support function calling, litellm defaults to json mode tool calls if native tool calling not supported. - -# litellm.register_model(model_cost={ -# "ollama_chat/llama3.1": { -# "supports_function_calling": true -# }, -# }) - tools = [ { "type": "function", diff --git a/tests/test_docstring_parser.py b/tests/utils/test_docstring_parser.py similarity index 100% rename from tests/test_docstring_parser.py rename to tests/utils/test_docstring_parser.py diff --git a/tests/utils/test_formatter.py b/tests/utils/test_formatter.py index 5feb8664..215c50ba 100644 --- a/tests/utils/test_formatter.py +++ b/tests/utils/test_formatter.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python3 -"""Test script to verify the improved formatter markdown rendering.""" - from swarms.utils.formatter import Formatter diff --git a/tests/utils/test_litellm_wrapper.py b/tests/utils/test_litellm_wrapper.py index e497e7d4..dd563c33 100644 --- a/tests/utils/test_litellm_wrapper.py +++ b/tests/utils/test_litellm_wrapper.py @@ -1,21 +1,9 @@ import asyncio -import sys from loguru import logger from swarms.utils.litellm_wrapper import LiteLLM -# Configure loguru logger -logger.remove() # Remove default handler -logger.add( - "test_litellm.log", - rotation="1 MB", - format="{time} | {level} | {message}", - level="DEBUG", -) -logger.add(sys.stdout, level="INFO") - - tools = [ { "type": "function", diff --git a/tests/utils/test_math_eval.py b/tests/utils/test_math_eval.py index ae7ee04c..642865b6 100644 --- a/tests/utils/test_math_eval.py +++ b/tests/utils/test_math_eval.py @@ -1,4 +1,4 @@ -from swarms.utils import math_eval +from swarms.utils.math_eval import math_eval def func1_no_exception(x): diff --git a/tests/utils/test_md_output.py b/tests/utils/test_md_output.py index d1693739..57316226 100644 --- a/tests/utils/test_md_output.py +++ b/tests/utils/test_md_output.py @@ -1,21 +1,17 @@ -#!/usr/bin/env python3 -""" -Test script demonstrating markdown output functionality with a real swarm -Uses the current state of formatter.py to show agent markdown output capabilities -""" - import os + from dotenv import load_dotenv # Load environment variables load_dotenv() -from swarms import Agent -from swarms.structs import ( - SequentialWorkflow, +from swarms import ( + Agent, ConcurrentWorkflow, GroupChat, + SequentialWorkflow, ) + from swarms.utils.formatter import Formatter diff --git a/tests/utils/test_print_class_parameters.py b/tests/utils/test_print_class_parameters.py deleted file mode 100644 index 9a133ae4..00000000 --- a/tests/utils/test_print_class_parameters.py +++ /dev/null @@ -1,120 +0,0 @@ -import pytest - -from swarms.utils import print_class_parameters - - -class TestObject: - def __init__(self, value1, value2: int): - pass - - -class TestObject2: - def __init__(self: "TestObject2", value1, value2: int = 5): - pass - - -def test_class_with_complex_parameters(): - class ComplexArgs: - def __init__(self, value1: list, value2: dict = {}): - pass - - output = {"value1": "", "value2": ""} - assert ( - print_class_parameters(ComplexArgs, api_format=True) == output - ) - - -def test_empty_class(): - class Empty: - pass - - with pytest.raises(Exception): - print_class_parameters(Empty) - - -def test_class_with_no_annotations(): - class NoAnnotations: - def __init__(self, value1, value2): - pass - - output = { - "value1": "", - "value2": "", - } - assert ( - print_class_parameters(NoAnnotations, api_format=True) - == output - ) - - -def test_class_with_partial_annotations(): - class PartialAnnotations: - def __init__(self, value1, value2: int): - pass - - output = { - "value1": "", - "value2": "", - } - assert ( - print_class_parameters(PartialAnnotations, api_format=True) - == output - ) - - -@pytest.mark.parametrize( - "obj, expected", - [ - ( - TestObject, - { - "value1": "", - "value2": "", - }, - ), - ( - TestObject2, - { - "value1": "", - "value2": "", - }, - ), - ], -) -def test_parametrized_class_parameters(obj, expected): - assert print_class_parameters(obj, api_format=True) == expected - - -@pytest.mark.parametrize( - "value", - [ - int, - float, - str, - list, - set, - dict, - bool, - tuple, - complex, - bytes, - bytearray, - memoryview, - range, - frozenset, - slice, - object, - ], -) -def test_not_class_exception(value): - with pytest.raises(Exception): - print_class_parameters(value) - - -def test_api_format_flag(): - assert print_class_parameters(TestObject2, api_format=True) == { - "value1": "", - "value2": "", - } - print_class_parameters(TestObject) - # TODO: Capture printed output and assert correctness.