|
| 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 | + |
0 commit comments