def validate() -> bool: """Check local files against schema.""" errors = [] try: validate_context() except ValidationError as e: errors.append(e) errors.extend(validate_local_state()) errors_by_severity = defaultdict(list) for error in errors: errors_by_severity[error.severity].append(error) if len(errors_by_severity[ValidationErrorSeverity.WARNING]) > 0: echo_warnings(errors_by_severity[ValidationErrorSeverity.WARNING]) echo_info('') if len(errors_by_severity[ValidationErrorSeverity.ERROR]) > 0: echo_errors(errors_by_severity[ValidationErrorSeverity.ERROR]) return False echo_info("Success: All files are valid.") return True
def test_validate_context_invalid_yaml(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) with Paths.context_file().open('w') as f: f.write('not:\nyaml') with pytest.raises(InvalidYamlFile): validate_context()
def test_validate_context_invalid(tmp_path, monkeypatch, context): monkeypatch.chdir(tmp_path) with Paths.context_file().open('w') as f: f.write(yaml.dump(context)) with pytest.raises(JsonSchemaError): validate_context()
def invoke(self, ctx: Context): from panoramic.cli.validate import validate_context try: validate_context() return super().invoke(ctx) except (ValidationError, SourceNotFoundException) as e: echo_error(str(e)) sys.exit(1)
def test_validate_context_valid(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) with Paths.context_file().open('w') as f: f.write(yaml.dump(VALID_CONTEXT)) validate_context()
def test_validate_context_missing_file(tmp_path, monkeypatch): monkeypatch.chdir(tmp_path) with pytest.raises(FileMissingError): validate_context()