diff --git a/tests/basic/test_watch.py b/tests/basic/test_watch.py index f8d8ab8b4..f3fa50536 100644 --- a/tests/basic/test_watch.py +++ b/tests/basic/test_watch.py @@ -1,27 +1,20 @@ from pathlib import Path - from aider.watch import FileWatcher def test_ai_comment_pattern(): - # Read fixture files + # Create a FileWatcher instance for testing + watcher = FileWatcher(None) fixtures_dir = Path(__file__).parent.parent / "fixtures" - with open(fixtures_dir / "watch.py") as f: - py_content = f.read() - with open(fixtures_dir / "watch.js") as f: - js_content = f.read() + # Test Python fixture + py_path = fixtures_dir / "watch.py" + py_lines, py_comments, py_has_bang = watcher.get_ai_comments(str(py_path)) + assert len(py_lines) == 11, f"Expected 11 AI comments in Python fixture, found {len(py_lines)}" + assert py_has_bang, "Expected at least one bang (!) comment in Python fixture" - # Count AI comments in Python fixture - py_matches = 0 - for line in py_content.splitlines(): - if FileWatcher.ai_comment_pattern.search(line): - py_matches += 1 - assert py_matches == 11, f"Expected 11 AI comments in Python fixture, found {py_matches}" - - # Count AI comments in JavaScript fixture - js_matches = 0 - for line in js_content.splitlines(): - if FileWatcher.ai_comment_pattern.search(line): - js_matches += 1 - assert js_matches == 11, f"Expected 11 AI comments in JavaScript fixture, found {js_matches}" + # Test JavaScript fixture + js_path = fixtures_dir / "watch.js" + js_lines, js_comments, js_has_bang = watcher.get_ai_comments(str(js_path)) + assert len(js_lines) == 11, f"Expected 11 AI comments in JavaScript fixture, found {len(js_lines)}" + assert js_has_bang, "Expected at least one bang (!) comment in JavaScript fixture"