mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 21:04:59 +00:00
Modify test_commands.py to mock linter.lint method and assert it was called with the dirty file
This commit is contained in:
parent
05ee45c31f
commit
bb7465e05d
1 changed files with 6 additions and 13 deletions
|
@ -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
|
# Run cmd_lint
|
||||||
commands.cmd_lint()
|
commands.cmd_lint()
|
||||||
|
|
||||||
# Restore stdout
|
# Check if the linter was called with the dirty file
|
||||||
sys.stdout = sys.__stdout__
|
mock_lint.assert_called_once_with(filename)
|
||||||
|
|
||||||
# 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue