|
6 | 6 | import unittest |
7 | 7 | from unittest.mock import MagicMock, call, patch |
8 | 8 |
|
9 | | -from tools.private.release import changelog_news, release as releaser, utils |
| 9 | +from tools.private.release import changelog_news, git, release as releaser, utils |
10 | 10 | from tools.private.release.gh import MultipleTrackingIssuesError, NoTrackingIssueError |
11 | 11 |
|
12 | 12 |
|
@@ -1676,5 +1676,42 @@ def mock_resolve(items): |
1676 | 1676 | self.mock_git.push.assert_not_called() |
1677 | 1677 |
|
1678 | 1678 |
|
| 1679 | +class GitCheckoutTest(unittest.TestCase): |
| 1680 | + @patch("tools.private.release.git.run_cmd") |
| 1681 | + def test_checkout_simple(self, mock_run_cmd): |
| 1682 | + git.checkout("my-branch") |
| 1683 | + mock_run_cmd.assert_called_once_with( |
| 1684 | + "git", "checkout", "my-branch", capture_output=False |
| 1685 | + ) |
| 1686 | + |
| 1687 | + @patch("tools.private.release.git.branch_exists") |
| 1688 | + @patch("tools.private.release.git.run_cmd") |
| 1689 | + def test_checkout_track_remote_new_branch(self, mock_run_cmd, mock_branch_exists): |
| 1690 | + mock_branch_exists.return_value = False |
| 1691 | + |
| 1692 | + git.checkout("my-branch", track_remote="origin") |
| 1693 | + |
| 1694 | + mock_branch_exists.assert_called_once_with("my-branch") |
| 1695 | + mock_run_cmd.assert_called_once_with( |
| 1696 | + "git", "checkout", "--track", "origin/my-branch", capture_output=False |
| 1697 | + ) |
| 1698 | + |
| 1699 | + @patch("tools.private.release.git.reset_hard") |
| 1700 | + @patch("tools.private.release.git.branch_exists") |
| 1701 | + @patch("tools.private.release.git.run_cmd") |
| 1702 | + def test_checkout_track_remote_existing_branch( |
| 1703 | + self, mock_run_cmd, mock_branch_exists, mock_reset_hard |
| 1704 | + ): |
| 1705 | + mock_branch_exists.return_value = True |
| 1706 | + |
| 1707 | + git.checkout("my-branch", track_remote="origin") |
| 1708 | + |
| 1709 | + mock_branch_exists.assert_called_once_with("my-branch") |
| 1710 | + mock_run_cmd.assert_called_once_with( |
| 1711 | + "git", "checkout", "my-branch", capture_output=False |
| 1712 | + ) |
| 1713 | + mock_reset_hard.assert_called_once_with("origin/my-branch") |
| 1714 | + |
| 1715 | + |
1679 | 1716 | if __name__ == "__main__": |
1680 | 1717 | unittest.main() |
0 commit comments