Refactor test_get_tracked_files_with_new_staged_file to use a GitTemporaryDirectory and add new assertions.

This commit is contained in:
Paul Gauthier 2023-07-24 13:42:05 -03:00
parent 85166341d1
commit bef1d00ab1

View file

@ -2,14 +2,14 @@ import os
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from unittest.mock import patch, MagicMock
import git
from aider.dump import dump # noqa: F401
from aider.io import InputOutput
from aider.repo import GitRepo
from tests.utils import GitTemporaryDirectory
class TestRepo(unittest.TestCase):
@patch("aider.repo.simple_send_with_retries")
@ -80,3 +80,37 @@ class TestRepo(unittest.TestCase):
# Assert that coder.get_tracked_files() returns the three filenames
self.assertEqual(set(tracked_files), set(created_files))
def test_get_tracked_files_with_new_staged_file(self):
# Mock the IO object
mock_io = MagicMock()
with GitTemporaryDirectory():
# new repo
repo = git.Repo()
# add it, but no commits at all in the repo yet
fname = Path("new.txt")
fname.touch()
repo.git.add(str(fname))
coder = GitRepo(InputOutput(), None)
# better be there
fnames = coder.get_tracked_files()
self.assertIn(str(fname), fnames)
# commit it, better still be there
repo.git.commit("-m", "new")
fnames = coder.get_tracked_files()
self.assertIn(str(fname), fnames)
# new file, added but not committed
fname2 = Path("new2.txt")
fname2.touch()
repo.git.add(str(fname2))
# both should be there
fnames = coder.get_tracked_files()
self.assertIn(str(fname), fnames)
self.assertIn(str(fname2), fnames)