|
7 | 7 |
|
8 | 8 | import abc |
9 | 9 | import itertools |
| 10 | +import warnings |
10 | 11 | from collections import defaultdict |
11 | 12 | import json |
12 | 13 | from dataclasses import dataclass, field |
@@ -231,13 +232,14 @@ def _iter_failing_rules( |
231 | 232 | yield self.issue_formatter(rule) |
232 | 233 |
|
233 | 234 | def validate(self, glob: str) -> ValidationResult: |
234 | | - if not self.policy_file: |
235 | | - raise ValueError("Policy file must be set before validation.") |
236 | 235 |
|
237 | 236 | mc = self.mediaconch or self._get_media_conch() |
238 | | - if not self.validate_policy_file(self.policy_file): |
239 | | - raise ValueError("Policy file must be valid policy file.") |
240 | | - mc.add_policy(str(self.policy_file)) |
| 237 | + if not self.policy_file: |
| 238 | + warnings.warn(UserWarning("No policy was set before validation")) |
| 239 | + else: |
| 240 | + if not self.validate_policy_file(self.policy_file): |
| 241 | + raise ValueError("Policy file must be valid policy file.") |
| 242 | + mc.add_policy(str(self.policy_file)) |
241 | 243 | final_results = MediaConchValidator._Results() |
242 | 244 |
|
243 | 245 | try: |
@@ -280,7 +282,7 @@ def get_mediaconch_results( |
280 | 282 | assert item["ref"] == str(filepath), ( |
281 | 283 | f"Expected {item['ref']} to be {filepath}" |
282 | 284 | ) |
283 | | - failing_rules = set(self._iter_failing_rules(item["policies"])) |
| 285 | + failing_rules = set(self._iter_failing_rules(item.get("policies", []))) |
284 | 286 | if failing_rules: |
285 | 287 | file_is_valid = False |
286 | 288 | results.files_with_issues.add( |
|
0 commit comments