aider: Fixed TypeError when initializing IO class in test_cmd_add.

# Context:
USER: I ran this command:

 pytest tests/test_commands.py

Which produced this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 1 item

tests/test_commands.py F                                                 [100%]

=================================== FAILURES ===================================
__________________________ TestCommands.test_cmd_add ___________________________

self = <tests.test_commands.TestCommands testMethod=test_cmd_add>

    def test_cmd_add(self):
        with tempfile.TemporaryDirectory() as tmpdir:
>           io = IO(pretty=False, yes=True, input_history_file=None, chat_history_file=None)

tests/test_commands.py:12:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
aider/io.py:60: in __init__
    self.chat_history_file = Path(chat_history_file)
/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:871: in __new__
    self = cls._from_parts(args)
/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:509: in _from_parts
    drv, root, parts = self._parse_args(args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'pathlib.PosixPath'>, args = (None,)

    @classmethod
    def _parse_args(cls, args):
        # This is useful when you don't want to create an instance, just
        # canonicalize some constructor arguments.
        parts = []
        for a in args:
            if isinstance(a, PurePath):
                parts += a._parts
            else:
>               a = os.fspath(a)
E               TypeError: expected str, bytes or os.PathLike object, not NoneType

/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:493: TypeError
=========================== short test summary info ============================
FAILED tests/test_commands.py::TestCommands::test_cmd_add - TypeError: expect...
============================== 1 failed in 0.53s ===============================

ASSISTANT: I apologize for the oversight. The `Path` class from `pathlib` does not accept `None` as an argument. We can use an empty string instead of `None` for `input_history_file` and `chat_history_file` when initializing the `IO` class in the test.

```python
tests/test_commands.py
<<<<<<< ORIGINAL
io = IO(pretty=False, yes=True, input_history_file=None, chat_history_file=None)
=======
io = IO(pretty=False, yes=True, input_history_file="", chat_history_file="")
>>>>>>> UPDATED
```

This change should fix the `TypeError` when initializing the `IO` class in the test.
This commit is contained in:
Paul Gauthier 2023-05-18 17:28:03 -07:00
parent 9d74924067
commit a33c1d3478

View file

@ -9,7 +9,7 @@ from aider.coder import Coder
class TestCommands(unittest.TestCase):
def test_cmd_add(self):
with tempfile.TemporaryDirectory() as tmpdir:
io = IO(pretty=False, yes=True, input_history_file=None, chat_history_file=None)
io = IO(pretty=False, yes=True, input_history_file="", chat_history_file="")
coder = Coder(root=tmpdir)
commands = Commands(io, coder)