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
2423from pathlib import Path
2524
2625from django .core .exceptions import ValidationError
2726from django .test import TestCase
2827
2928from scanpipe .pipes .license_clarity import ClarityThresholdsPolicy
30- from scanpipe .pipes .license_clarity import load_clarity_thresholds_from_yaml
3129from scanpipe .pipes .license_clarity import load_clarity_thresholds_from_file
30+ from scanpipe .pipes .license_clarity import load_clarity_thresholds_from_yaml
31+
3232
3333class ClarityThresholdsPolicyTest (TestCase ):
34+ data = Path (__file__ ).parent .parent / "data"
3435 """Test ClarityThresholdsPolicy class functionality."""
3536
3637 def test_valid_thresholds_initialization (self ):
@@ -149,22 +150,13 @@ def test_yaml_string_invalid_yaml(self):
149150 load_clarity_thresholds_from_yaml (yaml_content )
150151
151152 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 ()
153+ test_file = self .data / "license_clarity" / "sample_thresholds.yml"
154+ policy = load_clarity_thresholds_from_file (test_file )
155+ self .assertIsNotNone (policy )
156+ self .assertEqual (policy .get_alert_for_score (95 ), "ok" )
157+ self .assertEqual (policy .get_alert_for_score (75 ), "warning" )
158+ self .assertEqual (policy .get_alert_for_score (50 ), "error" )
167159
168160 def test_load_from_nonexistent_file (self ):
169161 policy = load_clarity_thresholds_from_file ("/nonexistent/file.yml" )
170- self .assertIsNone (policy )
162+ self .assertIsNone (policy )
0 commit comments