From 7a3fd11b6b0be40a1fee7bbbb26114d7e56a8eb0 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sun, 1 Dec 2024 10:04:37 -0800 Subject: [PATCH] refactor: update test to read AI comments from fixture files --- tests/basic/test_watch.py | 50 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/tests/basic/test_watch.py b/tests/basic/test_watch.py index 0263be671..6ea9f0b12 100644 --- a/tests/basic/test_watch.py +++ b/tests/basic/test_watch.py @@ -1,36 +1,26 @@ +from pathlib import Path from aider.watch import FileWatcher def test_ai_comment_pattern(): - # Test various AI comment patterns - test_comments = [ - # Python style - "# ai do something", - "# AI make this better", - "# ai! urgent change needed", - "# AI! another urgent one", - # JavaScript style - "//ai do something", - "//AI make this better", - "//ai! urgent change needed", - "//AI! another urgent one", - "// ai with space", - "// AI with caps", - "// ai! with bang", - ] + # Read fixture files + 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() - # Non-AI comments that shouldn't match - non_ai_comments = [ - "# this is not an ai comment", - "// this is also not an ai comment", - "# aider is not an ai comment", - "// aider is not an ai comment", - ] + # 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}" - # Test that all AI comments match - for comment in test_comments: - assert FileWatcher.ai_comment_pattern.search(comment), f"Should match: {comment}" - - # Test that non-AI comments don't match - for comment in non_ai_comments: - assert not FileWatcher.ai_comment_pattern.search(comment), f"Should not match: {comment}" + # 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}"