fix(#147): Fix linting violations in quality gate tests

Fixed code review findings:
- Removed unused mock_run variables (6 instances)
- Fixed line length violations (3 instances)
- All ruff checks now pass

All 36 tests still passing after fixes.
Quality gates: BuildGate, LintGate, TestGate, CoverageGate ready for use.
This commit is contained in:
2026-02-01 18:29:13 -06:00
parent f45dbac7b4
commit 38da576b69
4 changed files with 19 additions and 18 deletions

View File

@@ -3,8 +3,6 @@
import subprocess import subprocess
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest
from src.gates.build_gate import BuildGate from src.gates.build_gate import BuildGate
from src.gates.quality_gate import GateResult from src.gates.quality_gate import GateResult
@@ -48,7 +46,7 @@ class TestBuildGate:
"Found 2 errors in 2 files (checked 10 source files)" "Found 2 errors in 2 files (checked 10 source files)"
) )
with patch("subprocess.run", return_value=mock_result) as mock_run: with patch("subprocess.run", return_value=mock_result):
gate = BuildGate() gate = BuildGate()
result = gate.check() result = gate.check()
@@ -65,7 +63,7 @@ class TestBuildGate:
# Mock subprocess.run to raise CalledProcessError # Mock subprocess.run to raise CalledProcessError
with patch( with patch(
"subprocess.run", side_effect=subprocess.CalledProcessError(127, "mypy") "subprocess.run", side_effect=subprocess.CalledProcessError(127, "mypy")
) as mock_run: ):
gate = BuildGate() gate = BuildGate()
result = gate.check() result = gate.check()

View File

@@ -4,8 +4,6 @@ import json
import subprocess import subprocess
from unittest.mock import MagicMock, mock_open, patch from unittest.mock import MagicMock, mock_open, patch
import pytest
from src.gates.coverage_gate import CoverageGate from src.gates.coverage_gate import CoverageGate
from src.gates.quality_gate import GateResult from src.gates.quality_gate import GateResult
@@ -81,7 +79,10 @@ class TestCoverageGate:
"""Test that check() returns passed=False when coverage is below 85%.""" """Test that check() returns passed=False when coverage is below 85%."""
mock_result = MagicMock() mock_result = MagicMock()
mock_result.returncode = 1 # pytest-cov returns 1 when below threshold mock_result.returncode = 1 # pytest-cov returns 1 when below threshold
mock_result.stdout = "TOTAL 100 20 80%\nFAIL Required test coverage of 85% not reached. Total coverage: 80.00%" mock_result.stdout = (
"TOTAL 100 20 80%\n"
"FAIL Required test coverage of 85% not reached. Total coverage: 80.00%"
)
mock_result.stderr = "" mock_result.stderr = ""
coverage_data = {"totals": {"percent_covered": 80.0}} coverage_data = {"totals": {"percent_covered": 80.0}}
@@ -95,7 +96,10 @@ class TestCoverageGate:
# Verify result # Verify result
assert isinstance(result, GateResult) assert isinstance(result, GateResult)
assert result.passed is False assert result.passed is False
assert "below minimum" in result.message.lower() or "failed" in result.message.lower() assert (
"below minimum" in result.message.lower()
or "failed" in result.message.lower()
)
assert result.details["coverage_percent"] < 85.0 assert result.details["coverage_percent"] < 85.0
assert result.details["minimum_coverage"] == 85.0 assert result.details["minimum_coverage"] == 85.0
@@ -135,7 +139,10 @@ class TestCoverageGate:
# Verify result # Verify result
assert isinstance(result, GateResult) assert isinstance(result, GateResult)
assert result.passed is False assert result.passed is False
assert "no coverage data" in result.message.lower() or "not found" in result.message.lower() assert (
"no coverage data" in result.message.lower()
or "not found" in result.message.lower()
)
def test_check_failure_subprocess_error(self) -> None: def test_check_failure_subprocess_error(self) -> None:
"""Test that check() handles subprocess errors gracefully.""" """Test that check() handles subprocess errors gracefully."""

View File

@@ -3,8 +3,6 @@
import subprocess import subprocess
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest
from src.gates.lint_gate import LintGate from src.gates.lint_gate import LintGate
from src.gates.quality_gate import GateResult from src.gates.quality_gate import GateResult
@@ -49,7 +47,7 @@ class TestLintGate:
) )
mock_result.stderr = "" mock_result.stderr = ""
with patch("subprocess.run", return_value=mock_result) as mock_run: with patch("subprocess.run", return_value=mock_result):
gate = LintGate() gate = LintGate()
result = gate.check() result = gate.check()
@@ -84,7 +82,7 @@ class TestLintGate:
# Mock subprocess.run to raise CalledProcessError # Mock subprocess.run to raise CalledProcessError
with patch( with patch(
"subprocess.run", side_effect=subprocess.CalledProcessError(127, "ruff") "subprocess.run", side_effect=subprocess.CalledProcessError(127, "ruff")
) as mock_run: ):
gate = LintGate() gate = LintGate()
result = gate.check() result = gate.check()

View File

@@ -3,10 +3,8 @@
import subprocess import subprocess
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest
from src.gates.test_gate import TestGate
from src.gates.quality_gate import GateResult from src.gates.quality_gate import GateResult
from src.gates.test_gate import TestGate
class TestTestGate: class TestTestGate:
@@ -56,7 +54,7 @@ class TestTestGate:
) )
mock_result.stderr = "" mock_result.stderr = ""
with patch("subprocess.run", return_value=mock_result) as mock_run: with patch("subprocess.run", return_value=mock_result):
gate = TestGate() gate = TestGate()
result = gate.check() result = gate.check()
@@ -110,7 +108,7 @@ class TestTestGate:
# Mock subprocess.run to raise CalledProcessError # Mock subprocess.run to raise CalledProcessError
with patch( with patch(
"subprocess.run", side_effect=subprocess.CalledProcessError(127, "pytest") "subprocess.run", side_effect=subprocess.CalledProcessError(127, "pytest")
) as mock_run: ):
gate = TestGate() gate = TestGate()
result = gate.check() result = gate.check()