forked from agentstack-ai/AgentStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_templates.py
More file actions
83 lines (77 loc) · 2.9 KB
/
test_cli_templates.py
File metadata and controls
83 lines (77 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import subprocess
import os, sys
import unittest
from parameterized import parameterized
from pathlib import Path
import shutil
from agentstack.proj_templates import get_all_template_names
from cli_test_utils import run_cli
BASE_PATH = Path(__file__).parent
class CLITemplatesTest(unittest.TestCase):
def setUp(self):
self.framework = os.getenv('TEST_FRAMEWORK')
self.project_dir = BASE_PATH / 'tmp' / self.framework / 'cli_templates'
os.makedirs(self.project_dir, exist_ok=True)
os.chdir(self.project_dir)
def tearDown(self):
shutil.rmtree(self.project_dir, ignore_errors=True)
@parameterized.expand([(x,) for x in get_all_template_names()])
def test_init_command_for_template(self, template_name):
"""Test the 'init' command to create a project directory with a template."""
result = run_cli('init', 'test_project', '--template', template_name)
self.assertEqual(result.returncode, 0)
self.assertTrue((self.project_dir / 'test_project').exists())
@unittest.skip("We're trying a new base template. TODO: Fix this test.")
def test_export_template_v1(self):
result = self._run_cli('init', f"test_project")
self.assertEqual(result.returncode, 0)
os.chdir(self.project_dir / f"test_project")
result = self._run_cli('generate', 'agent', 'test_agent', '--llm', 'openai/gpt-4o')
self.assertEqual(result.returncode, 0)
result = self._run_cli('generate', 'task', 'test_task', '--agent', 'test_agent')
self.assertEqual(result.returncode, 0)
result = self._run_cli('tools', 'add', 'ftp', '--agents', 'test_agent')
self.assertEqual(result.returncode, 0)
result = self._run_cli('export', 'test_template.json')
print(result.stdout)
print(result.stderr)
self.assertEqual(result.returncode, 0)
self.assertTrue((self.project_dir / 'test_project/test_template.json').exists())
template_str = (self.project_dir / 'test_project/test_template.json').read_text()
self.maxDiff = None
self.assertEqual(
template_str,
"""{
"name": "test_project",
"description": "New agentstack project",
"template_version": 2,
"framework": "crewai",
"method": "sequential",
"agents": [
{
"name": "test_agent",
"role": "Add your role here",
"goal": "Add your goal here",
"backstory": "Add your backstory here",
"model": "openai/gpt-4o"
}
],
"tasks": [
{
"name": "test_task",
"description": "Add your description here",
"expected_output": "Add your expected_output here",
"agent": "test_agent"
}
],
"tools": [
{
"name": "upload_files",
"agents": [
"test_agent"
]
}
],
"inputs": {}
}""",
)