Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reformat invalid schema error messages #1

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cloudbuild_validator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def validate(self, yaml_file_path: Path) -> List[str]:
try:
yamale.validate(self.schema, content)
except yamale.YamaleError as e:
raise validators.CloudBuildValidationError(e) from e
errors = []
for result in e.results:
errors.extend(result.errors)
return errors

content = content[0][0]

errors = []
Expand Down
3 changes: 2 additions & 1 deletion src/cloudbuild_validator/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class Validator(ABC):
@abstractmethod
def validate(self, yaml_file_content: str) -> List[str]: ...
def validate(self, yaml_file_content: str) -> List[str]:
...


class CloudBuildValidationError(Exception):
Expand Down
1 change: 0 additions & 1 deletion tests/test_default_validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from cloudbuild_validator import validators
from cloudbuild_validator.validators import CloudBuildValidationError

Expand Down
8 changes: 2 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import List

import pytest

from cloudbuild_validator import validators
from cloudbuild_validator.core import CloudBuildValidator
from cloudbuild_validator.validators import Validator
Expand Down Expand Up @@ -185,11 +184,8 @@ def test_validate_valid_yaml_invalid_rules(

def test_invalid_yaml(valid_specifications_path, invalid_yaml_path):
validator = CloudBuildValidator(valid_specifications_path)
with pytest.raises(validators.CloudBuildValidationError) as e:
validator.validate(invalid_yaml_path)
import yamale

assert isinstance(e.__cause__, yamale.YamaleError)
errors = validator.validate(invalid_yaml_path)
assert len(errors) > 0


def test_multiple_documents_in_yaml(
Expand Down
Loading