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
2426from django .core .exceptions import ValidationError
2527from django .test import TestCase
2628
2729from scanpipe .pipes .license_clarity import ClarityThresholdsPolicy
2830from scanpipe .pipes .license_clarity import load_clarity_thresholds_from_yaml
29-
31+ from scanpipe . pipes . license_clarity import load_clarity_thresholds_from_file
3032
3133class 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