From 894eff4393eb1c4ca204c48027330e4da417080f Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 29 Jul 2024 16:30:08 -0300 Subject: [PATCH] Add a test that checks if the cmd_lint command correctly identifies a dirty file in a repository. --- tests/basic/test_commands.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index 263ea86fb..2d2dc38e3 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -701,3 +701,39 @@ class TestCommands(TestCase): self.assertNotIn(fname1, str(coder.abs_fnames)) self.assertNotIn(fname2, str(coder.abs_fnames)) self.assertNotIn(fname3, str(coder.abs_fnames)) + + def test_cmd_lint_with_dirty_file(self): + with GitTemporaryDirectory() as repo_dir: + repo = git.Repo(repo_dir) + io = InputOutput(pretty=False, yes=True) + coder = Coder.create(self.GPT35, None, io) + commands = Commands(io, coder) + + # Create and commit a file + filename = "test_file.py" + file_path = Path(repo_dir) / filename + file_path.write_text("def hello():\n print('Hello, World!')\n") + repo.git.add(filename) + repo.git.commit("-m", "Add test_file.py") + + # Modify the file to make it dirty + file_path.write_text("def hello():\n print('Hello, World!')\n\n# Dirty line\n") + + # Capture the output + captured_output = StringIO() + sys.stdout = captured_output + + # Run cmd_lint + commands.cmd_lint() + + # Restore stdout + sys.stdout = sys.__stdout__ + + # Check if the dirty file was detected + output = captured_output.getvalue() + self.assertIn("test_file.py", output) + self.assertIn("Dirty files to lint", output) + + del coder + del commands + del repo