Skip to content

Commit 73bdf34

Browse files
committed
Full CLI test coverage (progress)
TODO: When installing tools dependency resolution hangs in test environment
1 parent deefba2 commit 73bdf34

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

tests/test_cli_init.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CLIInitTest(unittest.TestCase):
1818
def setUp(self):
1919
self.project_dir = Path(BASE_PATH / 'tmp/cli_init')
2020
os.makedirs(self.project_dir)
21+
os.chdir(self.project_dir)
2122

2223
def tearDown(self):
2324
shutil.rmtree(self.project_dir)
@@ -28,15 +29,13 @@ def _run_cli(self, *args):
2829

2930
def test_init_command(self):
3031
"""Test the 'init' command to create a project directory."""
31-
os.chdir(self.project_dir)
32-
result = self._run_cli('init', str(self.project_dir))
32+
result = self._run_cli('init', 'test_project')
3333
self.assertEqual(result.returncode, 0)
34-
self.assertTrue(self.project_dir.exists())
34+
self.assertTrue((self.project_dir / 'test_project').exists())
3535

3636
@parameterized.expand([(x,) for x in get_all_template_names()])
3737
def test_init_command_for_template(self, template_name):
3838
"""Test the 'init' command to create a project directory with a template."""
39-
os.chdir(self.project_dir)
40-
result = self._run_cli('init', str(self.project_dir), '--template', template_name)
39+
result = self._run_cli('init', 'test_project', '--template', template_name)
4140
self.assertEqual(result.returncode, 0)
42-
self.assertTrue(self.project_dir.exists())
41+
self.assertTrue((self.project_dir / 'test_project').exists())

tests/test_cli_tools.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import subprocess
2+
import os, sys
3+
import unittest
4+
from parameterized import parameterized
5+
from pathlib import Path
6+
import shutil
7+
from agentstack.tools import get_all_tool_names
8+
9+
BASE_PATH = Path(__file__).parent
10+
CLI_ENTRY = [
11+
sys.executable,
12+
"-m",
13+
"agentstack.main",
14+
]
15+
16+
17+
# TODO parameterized framework
18+
class CLIToolsTest(unittest.TestCase):
19+
def setUp(self):
20+
self.project_dir = Path(BASE_PATH / 'tmp/cli_tools')
21+
os.makedirs(self.project_dir)
22+
os.chdir(self.project_dir)
23+
24+
def tearDown(self):
25+
shutil.rmtree(self.project_dir)
26+
27+
def _run_cli(self, *args):
28+
"""Helper method to run the CLI with arguments."""
29+
return subprocess.run([*CLI_ENTRY, *args], capture_output=True, text=True)
30+
31+
@parameterized.expand([(x,) for x in get_all_tool_names()])
32+
@unittest.skip("Dependency resolution issue")
33+
def test_add_tool(self, tool_name):
34+
"""Test the adding every tool to a project."""
35+
result = self._run_cli('init', f"{tool_name}_project")
36+
self.assertEqual(result.returncode, 0)
37+
os.chdir(self.project_dir/f"{tool_name}_project")
38+
result = self._run_cli('generate', 'agent', 'test_agent', '--llm', 'opeenai/gpt-4o')
39+
self.assertEqual(result.returncode, 0)
40+
result = self._run_cli('generate', 'task', 'test_task')
41+
self.assertEqual(result.returncode, 0)
42+
43+
result = self._run_cli('tools', 'add', tool_name)
44+
print(result.stdout)
45+
self.assertEqual(result.returncode, 0)
46+
self.assertTrue(self.project_dir.exists())
47+

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ deps =
1212
parameterized
1313
mypy: mypy
1414
commands =
15-
pytest -v
15+
pytest -v {posargs}
1616
mypy: mypy agentops
1717
setenv =
1818
AGENTSTACK_TELEMETRY_OPT_OUT = 1

0 commit comments

Comments
 (0)