style: format test files with black

This commit is contained in:
2025-12-27 15:00:11 -08:00
parent 3a6c7e59d5
commit 3eac05a02a
18 changed files with 176 additions and 87 deletions
@@ -1,34 +1,39 @@
"""Tests for hanzo-tools-agent."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import agent
assert agent is not None
def test_import_tools(self):
from hanzo_tools.agent import TOOLS
assert len(TOOLS) > 0
def test_import_agent_tool(self):
from hanzo_tools.agent import AgentTool
assert AgentTool.name == "agent"
class TestAgentTool:
"""Tests for AgentTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.agent import AgentTool
return AgentTool()
def test_has_description(self, tool):
assert tool.description
assert "agent" in tool.description.lower()
def test_has_agent_configs(self, tool):
assert hasattr(tool, 'agents') or hasattr(tool, 'agent_configs')
assert hasattr(tool, "agents") or hasattr(tool, "agent_configs")
@@ -1,31 +1,39 @@
"""Tests for hanzo-tools-browser."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import browser
assert browser is not None
def test_import_tools(self):
from hanzo_tools.browser import TOOLS
assert len(TOOLS) > 0
def test_import_browser_tool(self):
from hanzo_tools.browser import BrowserTool
assert BrowserTool.name == "browser"
class TestBrowserTool:
"""Tests for BrowserTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.browser import BrowserTool
return BrowserTool()
def test_has_description(self, tool):
assert tool.description
assert "browser" in tool.description.lower() or "playwright" in tool.description.lower()
assert (
"browser" in tool.description.lower()
or "playwright" in tool.description.lower()
)
@@ -1,30 +1,35 @@
"""Tests for hanzo-tools-computer."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import computer
assert computer is not None
def test_import_tools(self):
from hanzo_tools.computer import TOOLS
assert len(TOOLS) > 0
def test_import_computer_tool(self):
from hanzo_tools.computer import ComputerTool
assert ComputerTool.name == "computer"
class TestComputerTool:
"""Tests for ComputerTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.computer import ComputerTool
return ComputerTool()
def test_has_description(self, tool):
assert tool.description
@@ -1,27 +1,31 @@
"""Tests for hanzo-tools-config."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import config
assert config is not None
def test_import_tools(self):
from hanzo_tools.config import TOOLS
assert len(TOOLS) > 0
class TestConfigTool:
"""Tests for config tools."""
@pytest.fixture
def tool(self):
from hanzo_tools.config import TOOLS
return TOOLS[0]() if TOOLS else None
def test_has_description(self, tool):
if tool:
assert tool.description
+12 -4
View File
@@ -250,14 +250,18 @@ class TestToolAsync:
"""Verify all tool .call() methods are async."""
import importlib
all_packages = REQUIRED_PACKAGES + [p for p in OPTIONAL_PACKAGES if _module_installed(p)]
all_packages = REQUIRED_PACKAGES + [
p for p in OPTIONAL_PACKAGES if _module_installed(p)
]
for pkg_name in all_packages:
pkg = importlib.import_module(pkg_name)
tools = getattr(pkg, "TOOLS", [])
for tool in tools:
if hasattr(tool, "call"):
assert asyncio.iscoroutinefunction(tool.call), f"{pkg_name}.{tool.name}.call() is not async"
assert asyncio.iscoroutinefunction(
tool.call
), f"{pkg_name}.{tool.name}.call() is not async"
class TestTotalToolCount:
@@ -296,7 +300,9 @@ class TestTotalToolCount:
pkg = importlib.import_module(pkg_name)
tools = getattr(pkg, "TOOLS", [])
actual = len(tools)
assert actual == expected_count, f"{pkg_name}: expected {expected_count} tools, got {actual}"
assert (
actual == expected_count
), f"{pkg_name}: expected {expected_count} tools, got {actual}"
total += actual
# Check variable packages (range allowed)
@@ -304,7 +310,9 @@ class TestTotalToolCount:
pkg = importlib.import_module(pkg_name)
tools = getattr(pkg, "TOOLS", [])
actual = len(tools)
assert min_count <= actual <= max_count, f"{pkg_name}: expected {min_count}-{max_count} tools, got {actual}"
assert (
min_count <= actual <= max_count
), f"{pkg_name}: expected {min_count}-{max_count} tools, got {actual}"
total += actual
# Required tools: 41 (7+7+1+9+1+2+1+1+8+1+3)
@@ -1,14 +1,17 @@
"""Tests for hanzo-tools-database."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import database
assert database is not None
def test_import_tools(self):
from hanzo_tools.database import TOOLS
assert len(TOOLS) > 0
@@ -1,14 +1,17 @@
"""Tests for hanzo-tools-editor."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import editor
assert editor is not None
def test_import_tools(self):
from hanzo_tools.editor import TOOLS
assert len(TOOLS) > 0
+17 -9
View File
@@ -1,39 +1,46 @@
"""Tests for hanzo-tools-fs."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import fs
assert fs is not None
def test_import_tools(self):
from hanzo_tools.fs import TOOLS
assert len(TOOLS) > 0
def test_import_read_tool(self):
from hanzo_tools.fs import ReadTool
assert ReadTool.name == "read"
def test_import_write_tool(self):
from hanzo_tools.fs import WriteTool
assert WriteTool.name == "write"
def test_import_edit_tool(self):
from hanzo_tools.fs import EditTool
assert EditTool.name == "edit"
class TestReadTool:
"""Tests for ReadTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.fs import ReadTool
return ReadTool()
def test_has_description(self, tool):
assert tool.description
assert "read" in tool.description.lower()
@@ -41,12 +48,13 @@ class TestReadTool:
class TestWriteTool:
"""Tests for WriteTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.fs import WriteTool
return WriteTool()
def test_has_description(self, tool):
assert tool.description
assert "write" in tool.description.lower()
@@ -1,14 +1,17 @@
"""Tests for hanzo-tools-jupyter."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import jupyter
assert jupyter is not None
def test_import_tools(self):
from hanzo_tools.jupyter import TOOLS
assert len(TOOLS) > 0
+5 -2
View File
@@ -1,14 +1,17 @@
"""Tests for hanzo-tools-llm."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import llm
assert llm is not None
def test_import_tools(self):
from hanzo_tools.llm import TOOLS
assert len(TOOLS) > 0
+10 -5
View File
@@ -1,30 +1,35 @@
"""Tests for hanzo-tools-lsp."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import lsp
assert lsp is not None
def test_import_tools(self):
from hanzo_tools.lsp import TOOLS
assert len(TOOLS) > 0
def test_import_lsp_tool(self):
from hanzo_tools.lsp import LspTool
assert LspTool.name == "lsp"
class TestLspTool:
"""Tests for LspTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.lsp import LspTool
return LspTool()
def test_has_description(self, tool):
assert tool.description
+5 -2
View File
@@ -1,14 +1,17 @@
"""Tests for hanzo-tools-mcp."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import mcp_tools
assert mcp_tools is not None
def test_import_tools(self):
from hanzo_tools.mcp_tools import TOOLS
assert len(TOOLS) > 0
@@ -1,27 +1,31 @@
"""Tests for hanzo-tools-memory."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import memory
assert memory is not None
def test_import_tools(self):
from hanzo_tools.memory import TOOLS
assert len(TOOLS) > 0
class TestMemoryTool:
"""Tests for MemoryTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.memory import TOOLS
return TOOLS[0]() if TOOLS else None
def test_has_description(self, tool):
if tool:
assert tool.description
@@ -1,35 +1,41 @@
"""Tests for hanzo-tools-reasoning."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import reasoning
assert reasoning is not None
def test_import_tools(self):
from hanzo_tools.reasoning import TOOLS
assert len(TOOLS) >= 2 # think, critic
def test_import_think_tool(self):
from hanzo_tools.reasoning import ThinkTool
assert ThinkTool.name == "think"
def test_import_critic_tool(self):
from hanzo_tools.reasoning import CriticTool
assert CriticTool.name == "critic"
class TestThinkTool:
"""Tests for ThinkTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.reasoning import ThinkTool
return ThinkTool()
def test_has_description(self, tool):
assert tool.description
assert "think" in tool.description.lower()
@@ -37,12 +43,13 @@ class TestThinkTool:
class TestCriticTool:
"""Tests for CriticTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.reasoning import CriticTool
return CriticTool()
def test_has_description(self, tool):
assert tool.description
assert "critic" in tool.description.lower()
@@ -1,31 +1,36 @@
"""Tests for hanzo-tools-refactor."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import refactor
assert refactor is not None
def test_import_tools(self):
from hanzo_tools.refactor import TOOLS
assert len(TOOLS) > 0
def test_import_refactor_tool(self):
from hanzo_tools.refactor import RefactorTool
assert RefactorTool.name == "refactor"
class TestRefactorTool:
"""Tests for RefactorTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.refactor import RefactorTool
return RefactorTool()
def test_has_description(self, tool):
assert tool.description
assert "refactor" in tool.description.lower()
+20 -13
View File
@@ -186,7 +186,10 @@ class TestSexpConversion:
}
def test_roundtrip(self):
original = {"type": "do", "steps": ["A", {"type": "all", "steps": ["B", "C"]}, "D"]}
original = {
"type": "do",
"steps": ["A", {"type": "all", "steps": ["B", "C"]}, "D"],
}
sexp = to_sexp(original)
recovered = from_sexp(sexp)
assert recovered == original
@@ -351,12 +354,12 @@ class TestPerformance:
parallel = "{ " + " & ".join([f"task{i}_{j}" for j in range(10)]) + " }"
parts.append(parallel)
src = " ; ".join(parts)
start = time.perf_counter()
ast = parse(src)
cmds = to_commands(ast)
elapsed = time.perf_counter() - start
print(f"\nLarge DAG (100x10): {elapsed*1000:.2f}ms")
assert elapsed < 0.1 # Should complete in under 100ms
assert len(cmds) == 100
@@ -368,7 +371,7 @@ class TestIntegration:
async def test_execute_sequential(self):
from hanzo_tools.shell import ZshTool
zsh = ZshTool()
result = await zsh.call(None, command="echo A ; echo B ; echo C")
assert "A" in result
@@ -377,7 +380,7 @@ class TestIntegration:
async def test_execute_parallel(self):
from hanzo_tools.shell import ZshTool
zsh = ZshTool()
result = await zsh.call(None, command="{ echo A & echo B & echo C }")
assert "A" in result
@@ -386,9 +389,11 @@ class TestIntegration:
async def test_execute_mixed(self):
from hanzo_tools.shell import ZshTool
zsh = ZshTool()
result = await zsh.call(None, command="echo start ; { echo A & echo B } ; echo end")
result = await zsh.call(
None, command="echo start ; { echo A & echo B } ; echo end"
)
assert "start" in result
assert "A" in result
assert "B" in result
@@ -396,28 +401,30 @@ class TestIntegration:
async def test_execute_with_bash(self):
from hanzo_tools.shell import BashTool
bash = BashTool()
result = await bash.call(None, command="echo start ; { echo A & echo B } ; echo end")
result = await bash.call(
None, command="echo start ; { echo A & echo B } ; echo end"
)
assert "start" in result
assert "end" in result
async def test_parallel_execution_time(self):
"""Parallel should be faster than sequential for sleep commands."""
from hanzo_tools.shell import ZshTool
zsh = ZshTool()
# Parallel: should take ~0.1s
start = time.perf_counter()
await zsh.call(None, command="{ sleep 0.1 & sleep 0.1 & sleep 0.1 }")
parallel_time = time.perf_counter() - start
# Sequential: should take ~0.3s
start = time.perf_counter()
await zsh.call(None, command="sleep 0.1 ; sleep 0.1 ; sleep 0.1")
sequential_time = time.perf_counter() - start
print(f"\nParallel: {parallel_time:.2f}s, Sequential: {sequential_time:.2f}s")
# Parallel should be at least 2x faster
assert parallel_time < sequential_time * 0.7
+10 -5
View File
@@ -1,31 +1,36 @@
"""Tests for hanzo-tools-todo."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import todo
assert todo is not None
def test_import_tools(self):
from hanzo_tools.todo import TOOLS
assert len(TOOLS) > 0
def test_import_todo_tool(self):
from hanzo_tools.todo import TodoTool
assert TodoTool.name == "todo"
class TestTodoTool:
"""Tests for TodoTool."""
@pytest.fixture
def tool(self):
from hanzo_tools.todo import TodoTool
return TodoTool()
def test_has_description(self, tool):
assert tool.description
assert "todo" in tool.description.lower()
@@ -1,14 +1,17 @@
"""Tests for hanzo-tools-vector."""
import pytest
class TestImports:
"""Test that all modules can be imported."""
def test_import_package(self):
from hanzo_tools import vector
assert vector is not None
def test_import_tools(self):
from hanzo_tools.vector import TOOLS
assert len(TOOLS) > 0