Skip to content

Commit 158b714

Browse files
committed
Only run LangGraph tests if FRAMEWORK == langgraph. Additional tests for swarm.
1 parent 02afaae commit 158b714

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

tests/test_frameworks_langgraph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
class FrameworksLanggraphTest(unittest.TestCase):
2020
def setUp(self):
2121
self.framework = os.getenv('TEST_FRAMEWORK')
22+
23+
if not self.framework == frameworks.LANGGRAPH:
24+
self.skipTest("These tests are only for the LangGraph framework")
25+
2226
self.project_dir = BASE_PATH / 'tmp' / self.framework / 'langgraph'
2327
conf.set_path(self.project_dir)
2428
os.makedirs(self.project_dir / 'src/config')
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import os, sys
2+
import shutil
3+
import unittest
4+
from pathlib import Path
5+
import ast
6+
from agentstack import conf
7+
from agentstack.exceptions import ValidationError
8+
from agentstack import frameworks
9+
from agentstack.frameworks.openai_swarm import ENTRYPOINT, SwarmFile
10+
from agentstack.agents import AGENTS_FILENAME, AgentConfig
11+
from agentstack.tasks import TASKS_FILENAME, TaskConfig
12+
13+
BASE_PATH = Path(__file__).parent
14+
15+
16+
class FrameworksOpenAISwarmTest(unittest.TestCase):
17+
def setUp(self):
18+
self.framework = os.getenv('TEST_FRAMEWORK')
19+
20+
if not self.framework == frameworks.OPENAI_SWARM:
21+
self.skipTest("These tests are only for the OpenAI Swarm framework")
22+
23+
self.project_dir = BASE_PATH / 'tmp' / self.framework / 'openai_swarm'
24+
conf.set_path(self.project_dir)
25+
os.makedirs(self.project_dir / 'src/config')
26+
27+
shutil.copy(BASE_PATH / 'fixtures/agentstack.json', self.project_dir / 'agentstack.json')
28+
with conf.ConfigFile() as config:
29+
config.framework = frameworks.OPENAI_SWARM
30+
31+
def tearDown(self):
32+
shutil.rmtree(self.project_dir)
33+
34+
def test_missing_base_class(self):
35+
"""A class with the name *Stack does not exist in the entrypoint"""
36+
entrypoint_src = """
37+
class FooBar:
38+
pass
39+
"""
40+
with open(self.project_dir / ENTRYPOINT, 'w') as f:
41+
f.write(entrypoint_src)
42+
43+
entrypoint = SwarmFile(self.project_dir / ENTRYPOINT)
44+
with self.assertRaises(ValidationError):
45+
entrypoint.get_base_class()
46+
47+
def test_missing_run_method(self):
48+
"""A method named `run` does not exist in the base class"""
49+
entrypoint_src = """
50+
class TestStack:
51+
def foo(self):
52+
pass
53+
"""
54+
with open(self.project_dir / ENTRYPOINT, 'w') as f:
55+
f.write(entrypoint_src)
56+
57+
entrypoint = SwarmFile(self.project_dir / ENTRYPOINT)
58+
with self.assertRaises(ValidationError):
59+
entrypoint.get_run_method()
60+
61+
def test_invalid_run_method(self):
62+
"""The run method does not have the correct signature"""
63+
entrypoint_src = """
64+
class TestStack:
65+
def run(self, foo):
66+
pass
67+
"""
68+
with open(self.project_dir / ENTRYPOINT, 'w') as f:
69+
f.write(entrypoint_src)
70+
71+
entrypoint = SwarmFile(self.project_dir / ENTRYPOINT)
72+
with self.assertRaises(ValidationError):
73+
entrypoint.get_run_method()
74+

0 commit comments

Comments
 (0)