aider/tests/test_commands.py
Paul Gauthier 388f603ef9 aider: Created a file 'foo.bad' with non-utf8 characters before calling the 'cmd_add' method.
# Context:
USER: do the todo
ASSISTANT: To complete the TODO, we need to create a file named 'foo.bad' with a non-utf8 encoding. We can use the Python 'codecs' module to create a file with a specific encoding. In this case, we'll use 'iso-8859-15' which is a common encoding that includes characters not present in utf-8.

Here's how to modify the 'test_cmd_add_bad_encoding' method in the 'tests/test_commands.py' file:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_bad_encoding(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # TODO: make a new file foo.bad which will fail to decode as utf-8

        commands.cmd_add("foo.bad")

        self.assertEqual(coder.abs_fnames, set())
=======
    import codecs
    def test_cmd_add_bad_encoding(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a new file foo.bad which will fail to decode as utf-8
        with codecs.open('foo.bad', 'w', encoding='iso-8859-15') as f:
            f.write('ÆØÅ')  # Characters not present in utf-8

        commands.cmd_add("foo.bad")

        self.assertEqual(coder.abs_fnames, set())
>>>>>>> UPDATED
```

This will create a file 'foo.bad' with non-utf8 characters before calling the 'cmd_add' method.
2023-07-05 20:57:21 -07:00

51 lines
1.6 KiB
Python

import os
import shutil
import tempfile
from unittest import TestCase
from aider import models
from aider.commands import Commands
from aider.io import InputOutput
class TestCommands(TestCase):
def setUp(self):
self.original_cwd = os.getcwd()
self.tempdir = tempfile.mkdtemp()
os.chdir(self.tempdir)
def tearDown(self):
os.chdir(self.original_cwd)
shutil.rmtree(self.tempdir)
def test_cmd_add(self):
# Initialize the Commands and InputOutput objects
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
commands = Commands(io, coder)
# Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
commands.cmd_add("foo.txt bar.txt")
# Check if both files have been created in the temporary directory
self.assertTrue(os.path.exists("foo.txt"))
self.assertTrue(os.path.exists("bar.txt"))
import codecs
def test_cmd_add_bad_encoding(self):
# Initialize the Commands and InputOutput objects
io = InputOutput(pretty=False, yes=True)
from aider.coders import Coder
coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
commands = Commands(io, coder)
# Create a new file foo.bad which will fail to decode as utf-8
with codecs.open('foo.bad', 'w', encoding='iso-8859-15') as f:
f.write('ÆØÅ') # Characters not present in utf-8
commands.cmd_add("foo.bad")
self.assertEqual(coder.abs_fnames, set())