Modify test_commands.py to mock linter.lint method and assert it was called with the dirty file

This commit is contained in:
Paul Gauthier 2024-07-29 16:45:18 -03:00 committed by Paul Gauthier (aider)
parent 05ee45c31f
commit bb7465e05d

View file

@ -719,20 +719,13 @@ class TestCommands(TestCase):
# Modify the file to make it dirty # Modify the file to make it dirty
file_path.write_text("def hello():\n print('Hello, World!')\n\n# Dirty line\n") file_path.write_text("def hello():\n print('Hello, World!')\n\n# Dirty line\n")
# Capture the output # Mock the linter.lint method
captured_output = StringIO() with unittest.mock.patch.object(coder.linter, "lint") as mock_lint:
sys.stdout = captured_output # Run cmd_lint
commands.cmd_lint()
# Run cmd_lint # Check if the linter was called with the dirty file
commands.cmd_lint() mock_lint.assert_called_once_with(filename)
# 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 coder
del commands del commands