Skip to content

Commit e05265d

Browse files
authored
Merge pull request #1311 from tiovikram/tiovikram/add-filesystem-tests
Add Filesystem tests
2 parents d256321 + 2cd05c2 commit e05265d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
poetry install
3333
- name: Test with pytest
3434
run: |
35-
poetry run pytest -s -x
35+
poetry run pytest -s -x -k test_
3636
env:
3737
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import unittest
2+
from unittest import mock
3+
4+
from interpreter.core.computer.files.files import Files
5+
6+
7+
class TestFiles(unittest.TestCase):
8+
def setUp(self):
9+
self.files = Files(mock.Mock())
10+
11+
@mock.patch("interpreter.core.computer.files.files.aifs")
12+
def test_search(self, mock_aifs):
13+
# Arrange
14+
mock_args = ["foo", "bar"]
15+
mock_kwargs = {"foo": "bar"}
16+
17+
# Act
18+
self.files.search(mock_args, mock_kwargs)
19+
20+
# Assert
21+
mock_aifs.search.assert_called_once_with(mock_args, mock_kwargs)
22+
23+
def test_edit_original_text_in_filedata(self):
24+
# Arrange
25+
mock_open = mock.mock_open(read_data="foobar")
26+
mock_write = mock_open.return_value.write
27+
28+
# Act
29+
with mock.patch("interpreter.core.computer.files.files.open", mock_open):
30+
self.files.edit("example/filepath/file", "foobar", "foobarbaz")
31+
32+
# Assert
33+
mock_open.assert_any_call("example/filepath/file", "r")
34+
mock_open.assert_any_call("example/filepath/file", "w")
35+
mock_write.assert_called_once_with("foobarbaz")
36+
37+
def test_edit_original_text_not_in_filedata(self):
38+
# Arrange
39+
mock_open = mock.mock_open(read_data="foobar")
40+
41+
# Act
42+
with self.assertRaises(ValueError) as context_manager:
43+
with mock.patch("interpreter.core.computer.files.files.open", mock_open):
44+
self.files.edit("example/filepath/file", "barbaz", "foobarbaz")
45+
46+
# Assert
47+
mock_open.assert_any_call("example/filepath/file", "r")
48+
self.assertEqual(
49+
str(context_manager.exception),
50+
"Original text not found. Did you mean one of these? foobar",
51+
)

0 commit comments

Comments
 (0)