Test PrintContainer (#515)

* Rename test_python_interpreter to test_local_python_executor

* Test PrintContainer

* Fix CI tests
This commit is contained in:
Albert Villanova del Moral 2025-02-06 14:02:52 +01:00 committed by GitHub
parent 6cd5b6adaf
commit e872d91972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View File

@ -73,9 +73,9 @@ jobs:
uv run pytest ./tests/test_monitoring.py uv run pytest ./tests/test_monitoring.py
if: ${{ success() || failure() }} if: ${{ success() || failure() }}
- name: Python interpreter tests - name: Local Python executor tests
run: | run: |
uv run pytest ./tests/test_python_interpreter.py uv run pytest ./tests/test_local_python_executor.py
if: ${{ success() || failure() }} if: ${{ success() || failure() }}
- name: Search tests - name: Search tests

View File

@ -23,6 +23,7 @@ import pytest
from smolagents.default_tools import BASE_PYTHON_TOOLS from smolagents.default_tools import BASE_PYTHON_TOOLS
from smolagents.local_python_executor import ( from smolagents.local_python_executor import (
InterpreterError, InterpreterError,
PrintContainer,
evaluate_python_code, evaluate_python_code,
fix_final_answer_code, fix_final_answer_code,
get_safe_module, 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()) safe_module = get_safe_module(fake_module, dangerous_patterns=[], authorized_imports=set())
assert not hasattr(safe_module, "lazy_attribute") assert not hasattr(safe_module, "lazy_attribute")
assert getattr(safe_module, "non_lazy_attribute") == "ok" 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