added test for choose_fence

This commit is contained in:
Paul Gauthier 2023-07-06 11:08:13 -07:00
parent b03f2e54cc
commit 610dd223b5
2 changed files with 26 additions and 3 deletions

View file

@ -239,5 +239,30 @@ class TestCoder(unittest.TestCase):
coder.run(with_message="hi")
self.assertEqual(len(coder.abs_fnames), 1)
def test_choose_fence(self):
# Create a few temporary files
_, file1 = tempfile.mkstemp()
with open(file1, "wb") as f:
f.write(b"this contains ``` backticks")
files = [file1]
# Initialize the Coder object with the mocked IO and mocked repo
coder = Coder.create(
models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", fnames=files
)
def mock_send(*args, **kwargs):
coder.partial_response_content = "ok"
coder.partial_response_function_call = dict()
coder.send = MagicMock(side_effect=mock_send)
# Call the run method with a message
coder.run(with_message="hi")
self.assertNotEqual(coder.fence[0], "```")
if __name__ == "__main__":
unittest.main()