Skip to content

Commit 11a9116

Browse files
committed
testing extend for clarity-score
Signed-off-by: NucleonGodX <racerpro41@gmail.com>
1 parent 54e5db2 commit 11a9116

File tree

2 files changed

+24
-162
lines changed

2 files changed

+24
-162
lines changed

scanpipe/pipes/license_clarity_compliance.py

Lines changed: 0 additions & 161 deletions
This file was deleted.

scanpipe/tests/pipes/test_license_clarity.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/nexB/scancode.io for support and download.
2222

23+
import tempfile
24+
from pathlib import Path
2325

2426
from django.core.exceptions import ValidationError
2527
from django.test import TestCase
2628

2729
from scanpipe.pipes.license_clarity import ClarityThresholdsPolicy
2830
from scanpipe.pipes.license_clarity import load_clarity_thresholds_from_yaml
29-
31+
from scanpipe.pipes.license_clarity import load_clarity_thresholds_from_file
3032

3133
class ClarityThresholdsPolicyTest(TestCase):
3234
"""Test ClarityThresholdsPolicy class functionality."""
@@ -145,3 +147,24 @@ def test_yaml_string_invalid_yaml(self):
145147
yaml_content = "license_clarity_thresholds: [80, 50"
146148
with self.assertRaises(ValidationError):
147149
load_clarity_thresholds_from_yaml(yaml_content)
150+
151+
def test_load_from_existing_file(self):
152+
yaml_content = """
153+
license_clarity_thresholds:
154+
90: ok
155+
70: warning
156+
"""
157+
with tempfile.NamedTemporaryFile(mode="w", suffix=".yml", delete=False) as f:
158+
f.write(yaml_content)
159+
temp_path = f.name
160+
161+
try:
162+
policy = load_clarity_thresholds_from_file(temp_path)
163+
self.assertIsNotNone(policy)
164+
self.assertEqual(policy.get_alert_for_score(95), "ok")
165+
finally:
166+
Path(temp_path).unlink()
167+
168+
def test_load_from_nonexistent_file(self):
169+
policy = load_clarity_thresholds_from_file("/nonexistent/file.yml")
170+
self.assertIsNone(policy)

0 commit comments

Comments
 (0)