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

Commit 7ba2907

Browse files
committed
clean up
1 parent 73bb88c commit 7ba2907

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

services/notification/notifiers/comment/conditions.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ 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
113-
res = comparison.head.report.calculate_diff(diff)
111+
res = None if not diff else comparison.head.report.calculate_diff(diff)
114112
return res is not None and res["general"].lines > 0
115113

116114
@staticmethod
@@ -153,9 +151,7 @@ def _check_coverage_drop(comparison: ComparisonProxy) -> bool:
153151
@staticmethod
154152
def _check_uncovered_patch(comparison: ComparisonProxy) -> bool:
155153
diff = comparison.get_diff(use_original_base=True)
156-
if diff is None:
157-
return False
158-
totals = comparison.head.report.apply_diff(diff)
154+
totals = None if not diff else comparison.head.report.apply_diff(diff)
159155
coverage_not_affected_by_patch = totals and totals.lines == 0
160156
if totals is None or coverage_not_affected_by_patch:
161157
# The patch doesn't affect coverage. So we don't show a comment.
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import unittest
2-
from decimal import Decimal
32
from unittest.mock import MagicMock, patch
43

54
from services.comparison import ComparisonProxy
65
from services.notification.notifiers.base import AbstractBaseNotifier
76
from services.notification.notifiers.comment.conditions import (
87
HasEnoughRequiredChanges,
9-
NotifyCondition,
108
)
11-
from shared.validation.types import CoverageCommentRequiredChanges
129

1310

1411
class TestHasEnoughRequiredChanges(unittest.TestCase):
@@ -17,38 +14,29 @@ def setUp(self):
1714
self.comparison = MagicMock(spec=ComparisonProxy)
1815

1916
def test_check_coverage_change_with_none_diff(self):
20-
# Arrange
2117
self.comparison.get_diff.return_value = None
22-
23-
# Act
2418
result = HasEnoughRequiredChanges._check_coverage_change(self.comparison)
25-
26-
# Assert
2719
self.assertFalse(result)
2820
self.comparison.get_diff.assert_called_once()
2921
self.comparison.head.report.calculate_diff.assert_not_called()
3022

3123
def test_check_uncovered_patch_with_none_diff(self):
32-
# Arrange
3324
self.comparison.get_diff.return_value = None
34-
35-
# Act
3625
result = HasEnoughRequiredChanges._check_uncovered_patch(self.comparison)
37-
38-
# Assert
3926
self.assertFalse(result)
4027
self.comparison.get_diff.assert_called_once_with(use_original_base=True)
4128
self.comparison.head.report.apply_diff.assert_not_called()
4229

4330
def test_check_any_change_with_none_diff(self):
44-
# Arrange
4531
self.comparison.get_diff.return_value = None
46-
32+
4733
# Mock _check_unexpected_changes to return False
48-
with patch.object(HasEnoughRequiredChanges, '_check_unexpected_changes', return_value=False):
34+
with patch.object(
35+
HasEnoughRequiredChanges, "_check_unexpected_changes", return_value=False
36+
):
4937
# Act
5038
result = HasEnoughRequiredChanges._check_any_change(self.comparison)
51-
39+
5240
# Assert
5341
self.assertFalse(result)
54-
self.comparison.get_diff.assert_called_once()
42+
self.comparison.get_diff.assert_called_once()

0 commit comments

Comments
 (0)