(self)
| 1649 | self.assertEqual(len(coder.abs_read_only_fnames), 0) |
| 1650 | |
| 1651 | def test_cmd_diff(self): |
| 1652 | with GitTemporaryDirectory() as repo_dir: |
| 1653 | repo = git.Repo(repo_dir) |
| 1654 | io = InputOutput(pretty=False, fancy_input=False, yes=True) |
| 1655 | coder = Coder.create(self.GPT35, None, io) |
| 1656 | commands = Commands(io, coder) |
| 1657 | |
| 1658 | # Create and commit a file |
| 1659 | filename = "test_file.txt" |
| 1660 | file_path = Path(repo_dir) / filename |
| 1661 | file_path.write_text("Initial content\n") |
| 1662 | repo.git.add(filename) |
| 1663 | repo.git.commit("-m", "Initial commit\n") |
| 1664 | |
| 1665 | # Modify the file to make it dirty |
| 1666 | file_path.write_text("Modified content") |
| 1667 | |
| 1668 | # Mock repo.get_commit_message to return a canned commit message |
| 1669 | with mock.patch.object( |
| 1670 | coder.repo, "get_commit_message", return_value="Canned commit message" |
| 1671 | ): |
| 1672 | # Run cmd_commit |
| 1673 | commands.cmd_commit() |
| 1674 | |
| 1675 | # Capture the output of cmd_diff |
| 1676 | with mock.patch("builtins.print") as mock_print: |
| 1677 | commands.cmd_diff("") |
| 1678 | |
| 1679 | # Check if the diff output is correct |
| 1680 | mock_print.assert_called_with(mock.ANY) |
| 1681 | diff_output = mock_print.call_args[0][0] |
| 1682 | self.assertIn("-Initial content", diff_output) |
| 1683 | self.assertIn("+Modified content", diff_output) |
| 1684 | |
| 1685 | # Modify the file again |
| 1686 | file_path.write_text("Further modified content") |
| 1687 | |
| 1688 | # Run cmd_commit again |
| 1689 | commands.cmd_commit() |
| 1690 | |
| 1691 | # Capture the output of cmd_diff |
| 1692 | with mock.patch("builtins.print") as mock_print: |
| 1693 | commands.cmd_diff("") |
| 1694 | |
| 1695 | # Check if the diff output is correct |
| 1696 | mock_print.assert_called_with(mock.ANY) |
| 1697 | diff_output = mock_print.call_args[0][0] |
| 1698 | self.assertIn("-Modified content", diff_output) |
| 1699 | self.assertIn("+Further modified content", diff_output) |
| 1700 | |
| 1701 | # Modify the file a third time |
| 1702 | file_path.write_text("Final modified content") |
| 1703 | |
| 1704 | # Run cmd_commit again |
| 1705 | commands.cmd_commit() |
| 1706 | |
| 1707 | # Capture the output of cmd_diff |
| 1708 | with mock.patch("builtins.print") as mock_print: |
nothing calls this directly
no test coverage detected