Skip to content

Commit f88a57d

Browse files
committed
fix tests
Signed-off-by: NucleonGodX <[email protected]>
1 parent 9a1ffa0 commit f88a57d

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

scanpipe/pipes/compliance_thresholds.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def validate_thresholds(self, threshold_dict):
9292
try:
9393
threshold = self.THRESHOLD_TYPE(key)
9494
except (ValueError, TypeError):
95-
type_name = "integers" if self.THRESHOLD_TYPE == int else "numbers"
95+
type_name = (
96+
"integers" if issubclass(self.THRESHOLD_TYPE, int) else "numbers"
97+
)
9698
raise ValidationError(f"Threshold keys must be {type_name}, got: {key}")
9799

98100
if threshold in seen:
@@ -101,7 +103,8 @@ def validate_thresholds(self, threshold_dict):
101103

102104
if value not in ["ok", "warning", "error"]:
103105
raise ValidationError(
104-
f"Compliance alert must be one of 'ok', 'warning', 'error', got: {value}"
106+
f"Compliance alert must be one of 'ok', 'warning', 'error', "
107+
f"got: {value}"
105108
)
106109
validated[threshold] = value
107110

@@ -138,7 +141,7 @@ class ScorecardThresholdsPolicy(BaseThresholdsPolicy):
138141

139142

140143
def load_thresholds_from_yaml(yaml_content, policy_class):
141-
"""Generic function to load thresholds from YAML."""
144+
"""Load thresholds from YAML."""
142145
data = load_yaml_content(yaml_content)
143146

144147
if not isinstance(data, dict):
@@ -153,7 +156,7 @@ def load_thresholds_from_yaml(yaml_content, policy_class):
153156

154157

155158
def load_thresholds_from_file(file_path, policy_class):
156-
"""Generic function to load thresholds from file."""
159+
"""Load thresholds from file."""
157160
file_path = Path(file_path)
158161
if not file_path.exists():
159162
return

scanpipe/tests/pipes/test_compliance_thresholds.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class ClarityThresholdsPolicyTest(TestCase):
3535
"""Test ClarityThresholdsPolicy class functionality."""
36-
36+
3737
data = Path(__file__).parent.parent / "data"
3838

3939
def test_valid_thresholds_initialization(self):
@@ -152,21 +152,25 @@ def test_yaml_string_invalid_yaml(self):
152152
load_thresholds_from_yaml(yaml_content, ClarityThresholdsPolicy)
153153

154154
def test_load_from_existing_file(self):
155-
test_file = self.data / "compliance-thresholds" / "clarity_sample_thresholds.yml"
155+
test_file = (
156+
self.data / "compliance-thresholds" / "clarity_sample_thresholds.yml"
157+
)
156158
policy = load_thresholds_from_file(test_file, ClarityThresholdsPolicy)
157159
self.assertIsNotNone(policy)
158160
self.assertEqual(policy.get_alert_for_score(95), "ok")
159161
self.assertEqual(policy.get_alert_for_score(75), "warning")
160162
self.assertEqual(policy.get_alert_for_score(50), "error")
161163

162164
def test_load_from_nonexistent_file(self):
163-
policy = load_thresholds_from_file("/nonexistent/file.yml", ClarityThresholdsPolicy)
165+
policy = load_thresholds_from_file(
166+
"/nonexistent/file.yml", ClarityThresholdsPolicy
167+
)
164168
self.assertIsNone(policy)
165169

166170

167171
class ScorecardThresholdsPolicyTest(TestCase):
168172
"""Test ScorecardThresholdsPolicy class functionality."""
169-
173+
170174
data = Path(__file__).parent.parent / "data"
171175

172176
def test_valid_thresholds_initialization(self):
@@ -286,14 +290,17 @@ def test_yaml_string_invalid_yaml(self):
286290
load_thresholds_from_yaml(yaml_content, ScorecardThresholdsPolicy)
287291

288292
def test_load_from_existing_file(self):
289-
test_file = self.data / "compliance-thresholds" / "scorecard_sample_thresholds.yml"
293+
test_file = (
294+
self.data / "compliance-thresholds" / "scorecard_sample_thresholds.yml"
295+
)
290296
policy = load_thresholds_from_file(test_file, ScorecardThresholdsPolicy)
291297
self.assertIsNotNone(policy)
292298
self.assertEqual(policy.get_alert_for_score(9.5), "ok")
293299
self.assertEqual(policy.get_alert_for_score(8.0), "warning")
294300
self.assertEqual(policy.get_alert_for_score(5.0), "error")
295301

296302
def test_load_from_nonexistent_file(self):
297-
policy = load_thresholds_from_file("/nonexistent/file.yml", ScorecardThresholdsPolicy)
303+
policy = load_thresholds_from_file(
304+
"/nonexistent/file.yml", ScorecardThresholdsPolicy
305+
)
298306
self.assertIsNone(policy)
299-

0 commit comments

Comments
 (0)