20
20
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
21
21
# Visit https://github.com/nexB/scancode.io for support and download.
22
22
23
+ import tempfile
24
+ from pathlib import Path
23
25
24
26
from django .core .exceptions import ValidationError
25
27
from django .test import TestCase
26
28
27
29
from scanpipe .pipes .license_clarity import ClarityThresholdsPolicy
28
30
from scanpipe .pipes .license_clarity import load_clarity_thresholds_from_yaml
29
-
31
+ from scanpipe . pipes . license_clarity import load_clarity_thresholds_from_file
30
32
31
33
class ClarityThresholdsPolicyTest (TestCase ):
32
34
"""Test ClarityThresholdsPolicy class functionality."""
@@ -145,3 +147,24 @@ def test_yaml_string_invalid_yaml(self):
145
147
yaml_content = "license_clarity_thresholds: [80, 50"
146
148
with self .assertRaises (ValidationError ):
147
149
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