"""Unit tests for code_exec tool."""

import pytest

from navi.tools.code_exec import CodeExecTool


class TestCodeExecTool:
    @pytest.fixture
    def tool(self):
        return CodeExecTool()

    async def test_hello_world(self, tool):
        result = await tool.execute({"code": "print('hello')"})
        assert result.success
        assert "hello" in result.output

    async def test_math(self, tool):
        result = await tool.execute({"code": "print(2 + 3)"})
        assert result.success
        assert "5" in result.output

    async def test_stderr(self, tool):
        result = await tool.execute({"code": "import sys; print('err', file=sys.stderr)"})
        # stderr is captured but the tool may or may not consider it an error
        assert "err" in (result.output or result.error or "")

    async def test_syntax_error(self, tool):
        result = await tool.execute({"code": "print("})
        assert not result.success
