From f8f33940d188dfbdf306dd08673fa8d77dc2d869 Mon Sep 17 00:00:00 2001 From: tobitege Date: Tue, 4 Jun 2024 05:46:52 +0200 Subject: [PATCH 1/2] Fix agentskills tests --- opendevin/runtime/plugins/agent_skills/agentskills.py | 5 +++++ tests/unit/test_agent_skill.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/opendevin/runtime/plugins/agent_skills/agentskills.py b/opendevin/runtime/plugins/agent_skills/agentskills.py index 24d39927c503..a5ed7b62461c 100644 --- a/opendevin/runtime/plugins/agent_skills/agentskills.py +++ b/opendevin/runtime/plugins/agent_skills/agentskills.py @@ -130,6 +130,11 @@ def _cur_file_header(CURRENT_FILE, total_lines): return f'[File: {os.path.abspath(CURRENT_FILE)} ({total_lines} lines total)]\n' +def init_file(): + global CURRENT_FILE + CURRENT_FILE = None + + @update_pwd_decorator def open_file(path: str, line_number: Optional[int] = None) -> None: """ diff --git a/tests/unit/test_agent_skill.py b/tests/unit/test_agent_skill.py index 3c5f426a0dfb..60cc983240f8 100644 --- a/tests/unit/test_agent_skill.py +++ b/tests/unit/test_agent_skill.py @@ -10,6 +10,7 @@ edit_file, find_file, goto_line, + init_file, open_file, parse_docx, parse_latex, @@ -22,12 +23,21 @@ ) +# current file needs to be reset after each test or some +# tests will fail because they are dependent on the current +# file being set correctly +@pytest.fixture(autouse=True) +def reset_current_file(): + init_file() + + def test_open_file_unexist_path(): with pytest.raises(FileNotFoundError): open_file('/unexist/path/a.txt') def test_open_file(tmp_path): + assert tmp_path is not None temp_file_path = tmp_path / 'a.txt' temp_file_path.write_text('Line 1\nLine 2\nLine 3\nLine 4\nLine 5') From 85a1bbfabb33f301bfe0b9c0a9fe43b75a2f5055 Mon Sep 17 00:00:00 2001 From: tobitege Date: Tue, 4 Jun 2024 22:56:07 +0200 Subject: [PATCH 2/2] Improved test_agent_skill --- opendevin/runtime/plugins/agent_skills/agentskills.py | 5 ----- tests/unit/test_agent_skill.py | 9 ++++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/opendevin/runtime/plugins/agent_skills/agentskills.py b/opendevin/runtime/plugins/agent_skills/agentskills.py index a5ed7b62461c..24d39927c503 100644 --- a/opendevin/runtime/plugins/agent_skills/agentskills.py +++ b/opendevin/runtime/plugins/agent_skills/agentskills.py @@ -130,11 +130,6 @@ def _cur_file_header(CURRENT_FILE, total_lines): return f'[File: {os.path.abspath(CURRENT_FILE)} ({total_lines} lines total)]\n' -def init_file(): - global CURRENT_FILE - CURRENT_FILE = None - - @update_pwd_decorator def open_file(path: str, line_number: Optional[int] = None) -> None: """ diff --git a/tests/unit/test_agent_skill.py b/tests/unit/test_agent_skill.py index 60cc983240f8..9edfc5d26b1c 100644 --- a/tests/unit/test_agent_skill.py +++ b/tests/unit/test_agent_skill.py @@ -10,7 +10,6 @@ edit_file, find_file, goto_line, - init_file, open_file, parse_docx, parse_latex, @@ -23,12 +22,12 @@ ) -# current file needs to be reset after each test or some -# tests will fail because they are dependent on the current -# file being set correctly +# CURRENT_FILE must be reset for each test @pytest.fixture(autouse=True) def reset_current_file(): - init_file() + from opendevin.runtime.plugins.agent_skills import agentskills + + agentskills.CURRENT_FILE = None def test_open_file_unexist_path():