mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 04:44:59 +00:00
aider: Added a test that creates a temporary directory, initializes a git repository there, adds three empty files, creates a Coder
object on that directory, and asserts that coder.get_tracked_files()
returns the three filenames.
# Aider chat conversation: USER: make a test which creates a tempdir and inits a git repo there. it should add 3 empty files with the filenames below. the test should create a Coder on that and make sure that coder.get_tracked_files() returns the 3 filenames. Here are the filenames: README.md doc/fänny_dirname/README.md doc/systemüberblick.md ASSISTANT: To create this test, we need to modify the `tests/test_coder.py` file. We will add a new test method named `test_get_tracked_files` in the `TestCoder` class. This method will create a temporary directory, initialize a git repository there, add three empty files, create a `Coder` object on that directory, and assert that `coder.get_tracked_files()` returns the three filenames. Here is the code change: ```python tests/test_coder.py <<<<<<< ORIGINAL if __name__ == "__main__": unittest.main() ======= def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp()) # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) # Create three empty files and add them to the git repository filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] for filename in filenames: (tempdir / filename).touch() repo.git.add(filename) # Create a Coder object on the temporary directory coder = Coder.create(models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir) # Assert that coder.get_tracked_files() returns the three filenames self.assertEqual(set(coder.get_tracked_files()), set(filenames)) if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This code assumes that the `Coder` class has a `get_tracked_files` method that returns the filenames of the tracked files in the git repository. If such a method does not exist, it should be implemented in the `Coder` class.
This commit is contained in:
parent
2f4e20658d
commit
f1b61d49e9
1 changed files with 19 additions and 0 deletions
|
@ -360,5 +360,24 @@ class TestCoder(unittest.TestCase):
|
|||
with self.assertRaises(openai.error.InvalidRequestError):
|
||||
coder.run(with_message="hi")
|
||||
|
||||
def test_get_tracked_files(self):
|
||||
# Create a temporary directory
|
||||
tempdir = Path(tempfile.mkdtemp())
|
||||
|
||||
# Initialize a git repository in the temporary directory
|
||||
repo = git.Repo.init(tempdir)
|
||||
|
||||
# Create three empty files and add them to the git repository
|
||||
filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"]
|
||||
for filename in filenames:
|
||||
(tempdir / filename).touch()
|
||||
repo.git.add(filename)
|
||||
|
||||
# Create a Coder object on the temporary directory
|
||||
coder = Coder.create(models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir)
|
||||
|
||||
# Assert that coder.get_tracked_files() returns the three filenames
|
||||
self.assertEqual(set(coder.get_tracked_files()), set(filenames))
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue