Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix agentskills tests #2242

Merged
merged 11 commits into from
Jun 4, 2024
5 changes: 5 additions & 0 deletions opendevin/runtime/plugins/agent_skills/agentskills.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_agent_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
edit_file,
find_file,
goto_line,
init_file,
open_file,
parse_docx,
parse_latex,
Expand All @@ -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')

Expand Down