fix: Remove unused test cases for setup_git_home function

This commit is contained in:
Paul Gauthier 2024-08-28 15:15:16 -07:00 committed by Paul Gauthier (aider)
parent d05cd4b459
commit a0b330feda

View file

@ -77,94 +77,6 @@ class TestMain(TestCase):
self.assertTrue((subdir / "foo.txt").exists())
self.assertTrue((subdir / "bar.txt").exists())
@patch("aider.main.Path.home")
@patch("aider.main.Path.glob")
@patch("aider.main.os.chdir")
@patch("aider.main.InputOutput")
def test_setup_git_home_existing_repo(self, mock_io, mock_chdir, mock_glob, mock_home):
mock_home.return_value = Path("/home/user")
mock_glob.return_value = [Path("/home/user/repo1/.git"), Path("/home/user/repo2/.git")]
mock_io.return_value.prompt_ask.return_value = "1"
result = setup_git_home(mock_io.return_value)
mock_io.return_value.tool_output.assert_any_call(
"Found git repositories in your home directory:"
)
mock_io.return_value.prompt_ask.assert_called_once()
mock_chdir.assert_called_once_with(Path("/home/user/repo1"))
self.assertEqual(result, str(Path("/home/user/repo1")))
@patch("aider.main.Path.home")
@patch("aider.main.Path.glob")
@patch("aider.main.os.chdir")
@patch("aider.main.InputOutput")
@patch("pathlib.Path.mkdir")
def test_setup_git_home_new_project(
self, mock_mkdir, mock_io, mock_chdir, mock_glob, mock_home
):
mock_home.return_value = Path("/home/user")
mock_glob.return_value = [Path("/home/user/repo1/.git"), Path("/home/user/repo2/.git")]
mock_io.return_value.prompt_ask.return_value = "new_project"
result = setup_git_home(mock_io.return_value)
mock_io.return_value.tool_output.assert_any_call(
"Found git repositories in your home directory:"
)
mock_io.return_value.prompt_ask.assert_called_once()
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
mock_chdir.assert_called_once_with(Path("/home/user/new_project"))
self.assertEqual(result, str(Path("/home/user/new_project")))
@patch("aider.main.Path.home")
@patch("aider.main.Path.glob")
@patch("aider.main.os.chdir")
@patch("aider.main.InputOutput")
@patch("pathlib.Path.mkdir")
def test_setup_git_home_no_existing_repos(
self, mock_mkdir, mock_io, mock_chdir, mock_glob, mock_home
):
mock_home.return_value = Path("/home/user")
mock_glob.return_value = []
mock_io.return_value.prompt_ask.return_value = "new_project"
result = setup_git_home(mock_io.return_value)
mock_io.return_value.tool_output.assert_not_called()
mock_io.return_value.prompt_ask.assert_called_once_with(
"Enter a name for your new project directory:"
)
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
mock_chdir.assert_called_once_with(Path("/home/user/new_project"))
self.assertEqual(result, str(Path("/home/user/new_project")))
@patch("aider.main.Path.home")
@patch("aider.main.Path.glob")
@patch("aider.main.os.chdir")
@patch("aider.main.InputOutput")
@patch("pathlib.Path.mkdir")
def test_setup_git_home_directory_creation_error(
self, mock_mkdir, mock_io, mock_chdir, mock_glob, mock_home
):
mock_home.return_value = Path("/home/user")
mock_glob.return_value = []
mock_io.return_value.prompt_ask.return_value = "new_project"
mock_mkdir.side_effect = OSError("Permission denied")
result = setup_git_home(mock_io.return_value)
mock_io.return_value.tool_output.assert_not_called()
mock_io.return_value.prompt_ask.assert_called_once_with(
"Enter a name for your new project directory:"
)
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
mock_chdir.assert_not_called()
mock_io.return_value.tool_error.assert_called_once_with(
"Error creating directory: Permission denied"
)
self.assertIsNone(result)
def test_main_with_git_config_yml(self):
make_repo()