[TESTS][Fix these tests]

pull/1126/head
Kye Gomez 2 days ago
parent 918dd41a38
commit eb18d416e4

@ -15,4 +15,4 @@ result = swarm.run(
task="Build a swarm to write a research paper on the topic of AI" 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))

@ -1,10 +1,8 @@
import uuid import uuid
from swarms.telemetry.main import ( from swarms.telemetry.main import (
generate_unique_identifier,
generate_user_id, generate_user_id,
get_machine_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) 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(): def test_generate_user_id_edge_case():
# Test generate_user_id with multiple calls # Test generate_user_id with multiple calls
user_ids = set() user_ids = set()
@ -69,33 +40,13 @@ def test_get_machine_id_edge_case():
assert len(machine_ids) == 100 # Ensure generated IDs are unique 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(): def test_all():
test_generate_user_id() test_generate_user_id()
test_get_machine_id() test_get_machine_id()
test_get_system_info()
test_generate_unique_identifier()
test_generate_user_id_edge_case() test_generate_user_id_edge_case()
test_get_machine_id_edge_case() test_get_machine_id_edge_case()
test_get_system_info_edge_case()
test_generate_unique_identifier_edge_case()
test_all() test_all()

@ -1,37 +1,29 @@
import os
import json import json
import os
from datetime import datetime from datetime import datetime
from typing import List, Dict, Any, Callable from typing import Any, Callable, Dict, List
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger
# Basic Imports for Swarms # Basic Imports for Swarms
from swarms.structs import ( from swarms.structs import (
Agent, Agent,
SequentialWorkflow,
ConcurrentWorkflow,
AgentRearrange, AgentRearrange,
MixtureOfAgents, ConcurrentWorkflow,
SpreadSheetSwarm,
GroupChat, GroupChat,
MultiAgentRouter, InteractiveGroupChat,
MajorityVoting, MajorityVoting,
SwarmRouter, MixtureOfAgents,
MultiAgentRouter,
RoundRobinSwarm, RoundRobinSwarm,
InteractiveGroupChat, SequentialWorkflow,
SpreadSheetSwarm,
SwarmRouter,
) )
# Import swarms not in __init__.py directly
from swarms.structs.hiearchical_swarm import HierarchicalSwarm from swarms.structs.hiearchical_swarm import HierarchicalSwarm
from swarms.structs.tree_swarm import ForestSwarm, Tree, TreeAgent 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 environment variables
load_dotenv() load_dotenv()
@ -463,8 +455,8 @@ def test_spreadsheet_swarm():
def test_hierarchical_swarm(): def test_hierarchical_swarm():
"""Test HierarchicalSwarm structure""" """Test HierarchicalSwarm structure"""
try: try:
from swarms.utils.litellm_wrapper import LiteLLM
from swarms.structs.hiearchical_swarm import SwarmSpec from swarms.structs.hiearchical_swarm import SwarmSpec
from swarms.utils.litellm_wrapper import LiteLLM
# Create worker agents # Create worker agents
workers = [ workers = [

@ -3,14 +3,6 @@ from dotenv import load_dotenv
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 = [ tools = [
{ {
"type": "function", "type": "function",

@ -1,6 +1,3 @@
#!/usr/bin/env python3
"""Test script to verify the improved formatter markdown rendering."""
from swarms.utils.formatter import Formatter from swarms.utils.formatter import Formatter

@ -1,21 +1,9 @@
import asyncio import asyncio
import sys
from loguru import logger from loguru import logger
from swarms.utils.litellm_wrapper import LiteLLM 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 = [ tools = [
{ {
"type": "function", "type": "function",

@ -1,4 +1,4 @@
from swarms.utils import math_eval from swarms.utils.math_eval import math_eval
def func1_no_exception(x): def func1_no_exception(x):

@ -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 import os
from dotenv import load_dotenv from dotenv import load_dotenv
# Load environment variables # Load environment variables
load_dotenv() load_dotenv()
from swarms import Agent from swarms import (
from swarms.structs import ( Agent,
SequentialWorkflow,
ConcurrentWorkflow, ConcurrentWorkflow,
GroupChat, GroupChat,
SequentialWorkflow,
) )
from swarms.utils.formatter import Formatter from swarms.utils.formatter import Formatter

@ -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": "<class 'list'>", "value2": "<class 'dict'>"}
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": "<class 'inspect._empty'>",
"value2": "<class 'inspect._empty'>",
}
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": "<class 'inspect._empty'>",
"value2": "<class 'int'>",
}
assert (
print_class_parameters(PartialAnnotations, api_format=True)
== output
)
@pytest.mark.parametrize(
"obj, expected",
[
(
TestObject,
{
"value1": "<class 'inspect._empty'>",
"value2": "<class 'int'>",
},
),
(
TestObject2,
{
"value1": "<class 'inspect._empty'>",
"value2": "<class 'int'>",
},
),
],
)
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": "<class 'inspect._empty'>",
"value2": "<class 'int'>",
}
print_class_parameters(TestObject)
# TODO: Capture printed output and assert correctness.
Loading…
Cancel
Save