From 4f3a17e3a682edb9592d79a3c21211300e069448 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Mon, 2 Feb 2026 14:39:12 +0000 Subject: [PATCH] fix: resolve CI linting errors - remove unused imports and update type annotations --- tests/test_code_analyzer.py | 68 +++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/tests/test_code_analyzer.py b/tests/test_code_analyzer.py index ee4ad4c..8cc1867 100644 --- a/tests/test_code_analyzer.py +++ b/tests/test_code_analyzer.py @@ -5,16 +5,20 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent / 'src')) -from gdiffer.code_analyzer import CodeAnalyzer, analyze_code, summarize_change +from gdiffer.code_analyzer import analyze_code, summarize_change class TestCodeAnalyzer: + """Tests for CodeAnalyzer class.""" + def test_analyze_empty_code(self, code_analyzer): + """Test analyzing empty code.""" result = code_analyzer.analyze_code("") assert result['language'] == "text" assert result['change_summary'] == "" def test_analyze_python_code(self, code_analyzer): + """Test analyzing Python code.""" code = """def hello(): return "Hello" @@ -23,35 +27,75 @@ class Greeter: return f"Hello, {name}" """ result = code_analyzer.analyze_code(code, "python") + assert result['language'] == "python" + assert 'functions' in result or 'ast_info' in result def test_analyze_javascript_code(self, code_analyzer): + """Test analyzing JavaScript code.""" code = """function add(a, b) { return a + b; -}""" +} + +const multiply = (x, y) => x * y; +""" result = code_analyzer.analyze_code(code, "javascript") + assert result['language'] == "javascript" + def test_analyze_rust_code(self, code_analyzer): + """Test analyzing Rust code.""" + code = """fn main() { + println!("Hello"); +} + +struct Point { + x: i32, + y: i32, +} +""" + result = code_analyzer.analyze_code(code, "rust") + + assert result['language'] == "rust" + def test_summarize_change_simple(self, code_analyzer): + """Test summarizing simple code changes.""" old_code = "def hello():\n return 'Hello'" new_code = "def hello():\n return 'Hello, World!'" + summary = code_analyzer.summarize_change(old_code, new_code, "python") + assert isinstance(summary, str) assert len(summary) > 0 def test_summarize_change_added_function(self, code_analyzer): + """Test summarizing when a function is added.""" old_code = "" new_code = "def new_func():\n pass" + summary = code_analyzer.summarize_change(old_code, new_code, "python") + assert isinstance(summary, str) assert len(summary) > 0 + def test_summarize_change_removed_function(self, code_analyzer): + """Test summarizing when a function is removed.""" + old_code = "def old_func():\n pass" + new_code = "" + + summary = code_analyzer.summarize_change(old_code, new_code, "python") + + assert isinstance(summary, str) + def test_analyze_code_without_parser(self, code_analyzer): + """Test analyzing code when tree-sitter parser is unavailable.""" code = "def test(): pass" result = code_analyzer.analyze_code(code, "unknown_language") + assert 'change_summary' in result def test_fallback_analysis_detects_functions(self, code_analyzer): + """Test that fallback analysis can detect functions.""" code = """def calculate_sum(a, b): return a + b @@ -59,29 +103,49 @@ def multiply(x, y): return x * y """ result = code_analyzer._analyze_without_parser(code) + assert isinstance(result, str) + assert "calculate_sum" in result or "multiply" in result or "function" in result.lower() def test_fallback_analysis_detects_classes(self, code_analyzer): + """Test that fallback analysis can detect classes.""" code = """class Calculator: def add(self, a, b): return a + b """ result = code_analyzer._analyze_without_parser(code) + assert "Calculator" in result or "class" in result.lower() + def test_fallback_analysis_line_count(self, code_analyzer): + """Test that fallback analysis includes line count.""" + old_code = "line1\nline2" + new_code = "line1\nline2\nline3" + + result = code_analyzer._analyze_without_parser(new_code) + + assert isinstance(result, str) + class TestAnalyzeCodeFunction: + """Tests for the analyze_code convenience function.""" + def test_analyze_code_function(self): + """Test analyze_code convenience function.""" result = analyze_code("def test(): pass", "python") assert 'language' in result assert 'change_summary' in result def test_analyze_code_empty(self): + """Test analyze_code with empty code.""" result = analyze_code("", "text") assert result['language'] == "text" class TestSummarizeChangeFunction: + """Tests for the summarize_change convenience function.""" + def test_summarize_change_function(self): + """Test summarize_change convenience function.""" result = summarize_change("old", "new", "text") assert isinstance(result, str)