Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 73bb88c

Browse files
fix: handle None diffs in coverage change checks
1 parent 6196550 commit 73bb88c

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

services/notification/notifiers/comment/conditions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def _check_unexpected_changes(comparison: ComparisonProxy) -> bool:
108108
def _check_coverage_change(comparison: ComparisonProxy) -> bool:
109109
"""Returns a bool that indicates wether there is any change in coverage"""
110110
diff = comparison.get_diff()
111+
if diff is None:
112+
return False
111113
res = comparison.head.report.calculate_diff(diff)
112114
return res is not None and res["general"].lines > 0
113115

@@ -151,6 +153,8 @@ def _check_coverage_drop(comparison: ComparisonProxy) -> bool:
151153
@staticmethod
152154
def _check_uncovered_patch(comparison: ComparisonProxy) -> bool:
153155
diff = comparison.get_diff(use_original_base=True)
156+
if diff is None:
157+
return False
154158
totals = comparison.head.report.apply_diff(diff)
155159
coverage_not_affected_by_patch = totals and totals.lines == 0
156160
if totals is None or coverage_not_affected_by_patch:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import unittest
2+
from decimal import Decimal
3+
from unittest.mock import MagicMock, patch
4+
5+
from services.comparison import ComparisonProxy
6+
from services.notification.notifiers.base import AbstractBaseNotifier
7+
from services.notification.notifiers.comment.conditions import (
8+
HasEnoughRequiredChanges,
9+
NotifyCondition,
10+
)
11+
from shared.validation.types import CoverageCommentRequiredChanges
12+
13+
14+
class TestHasEnoughRequiredChanges(unittest.TestCase):
15+
def setUp(self):
16+
self.notifier = MagicMock(spec=AbstractBaseNotifier)
17+
self.comparison = MagicMock(spec=ComparisonProxy)
18+
19+
def test_check_coverage_change_with_none_diff(self):
20+
# Arrange
21+
self.comparison.get_diff.return_value = None
22+
23+
# Act
24+
result = HasEnoughRequiredChanges._check_coverage_change(self.comparison)
25+
26+
# Assert
27+
self.assertFalse(result)
28+
self.comparison.get_diff.assert_called_once()
29+
self.comparison.head.report.calculate_diff.assert_not_called()
30+
31+
def test_check_uncovered_patch_with_none_diff(self):
32+
# Arrange
33+
self.comparison.get_diff.return_value = None
34+
35+
# Act
36+
result = HasEnoughRequiredChanges._check_uncovered_patch(self.comparison)
37+
38+
# Assert
39+
self.assertFalse(result)
40+
self.comparison.get_diff.assert_called_once_with(use_original_base=True)
41+
self.comparison.head.report.apply_diff.assert_not_called()
42+
43+
def test_check_any_change_with_none_diff(self):
44+
# Arrange
45+
self.comparison.get_diff.return_value = None
46+
47+
# Mock _check_unexpected_changes to return False
48+
with patch.object(HasEnoughRequiredChanges, '_check_unexpected_changes', return_value=False):
49+
# Act
50+
result = HasEnoughRequiredChanges._check_any_change(self.comparison)
51+
52+
# Assert
53+
self.assertFalse(result)
54+
self.comparison.get_diff.assert_called_once()

0 commit comments

Comments
 (0)