From e872d919721b6fa94cdb09599f7f120a7eaeb733 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:02:52 +0100 Subject: [PATCH] Test PrintContainer (#515) * Rename test_python_interpreter to test_local_python_executor * Test PrintContainer * Fix CI tests --- .github/workflows/tests.yml | 4 +-- ...reter.py => test_local_python_executor.py} | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) rename tests/{test_python_interpreter.py => test_local_python_executor.py} (98%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b4ccb81..5cf247b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -73,9 +73,9 @@ jobs: uv run pytest ./tests/test_monitoring.py if: ${{ success() || failure() }} - - name: Python interpreter tests + - name: Local Python executor tests run: | - uv run pytest ./tests/test_python_interpreter.py + uv run pytest ./tests/test_local_python_executor.py if: ${{ success() || failure() }} - name: Search tests diff --git a/tests/test_python_interpreter.py b/tests/test_local_python_executor.py similarity index 98% rename from tests/test_python_interpreter.py rename to tests/test_local_python_executor.py index 3e95711..200c221 100644 --- a/tests/test_python_interpreter.py +++ b/tests/test_local_python_executor.py @@ -23,6 +23,7 @@ import pytest from smolagents.default_tools import BASE_PYTHON_TOOLS from smolagents.local_python_executor import ( InterpreterError, + PrintContainer, evaluate_python_code, fix_final_answer_code, get_safe_module, @@ -1107,3 +1108,34 @@ def test_get_safe_module_handle_lazy_imports(): safe_module = get_safe_module(fake_module, dangerous_patterns=[], authorized_imports=set()) assert not hasattr(safe_module, "lazy_attribute") assert getattr(safe_module, "non_lazy_attribute") == "ok" + + +class TestPrintContainer: + def test_initial_value(self): + pc = PrintContainer() + assert pc.value == "" + + def test_append(self): + pc = PrintContainer() + pc.append("Hello") + assert pc.value == "Hello" + + def test_iadd(self): + pc = PrintContainer() + pc += "World" + assert pc.value == "World" + + def test_str(self): + pc = PrintContainer() + pc.append("Hello") + assert str(pc) == "Hello" + + def test_repr(self): + pc = PrintContainer() + pc.append("Hello") + assert repr(pc) == "PrintContainer(Hello)" + + def test_len(self): + pc = PrintContainer() + pc.append("Hello") + assert len(pc) == 5