feat: use IgnorantTemporaryDirectory and create actual repo1 and repo2 subdirs in test_setup_git_home_invalid_choice

This commit is contained in:
Paul Gauthier (aider) 2024-08-28 15:24:07 -07:00
parent 4d08f9c6c5
commit 715a9a9c71

View file

@ -664,16 +664,18 @@ class TestMain(TestCase):
mock_io_instance.prompt_ask.assert_not_called() mock_io_instance.prompt_ask.assert_not_called()
@patch("aider.main.InputOutput") @patch("aider.main.InputOutput")
@patch("aider.main.Path") def test_setup_git_home_invalid_choice(self, mock_io):
def test_setup_git_home_invalid_choice(self, mock_path, mock_io):
mock_io_instance = mock_io.return_value mock_io_instance = mock_io.return_value
mock_io_instance.prompt_ask.side_effect = ["3", "1"] mock_io_instance.prompt_ask.side_effect = ["3", "1"]
mock_path.home.return_value.glob.return_value = [
Path("/home/user/repo1/.git"), with IgnorantTemporaryDirectory() as temp_home:
Path("/home/user/repo2/.git"), with patch("aider.main.Path.home", return_value=Path(temp_home)):
] # Create actual repo1 and repo2 subdirectories with .git folders
Path(temp_home, "repo1", ".git").mkdir(parents=True)
Path(temp_home, "repo2", ".git").mkdir(parents=True)
result = setup_git_home(mock_io_instance) result = setup_git_home(mock_io_instance)
self.assertEqual(result, Path("/home/user/repo1")) self.assertEqual(result, Path(temp_home) / "repo1")
mock_io_instance.tool_error.assert_called_with("Please enter a number between 1 and 2") mock_io_instance.tool_error.assert_called_with("Please enter a number between 1 and 2")
mock_io_instance.tool_output.assert_called_with("Found git repositories in your home directory:")