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

Issue #507 - Fix invalid content validation check in base val.py classes #509

Merged
merged 2 commits into from
Jan 10, 2024
Merged
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
35 changes: 27 additions & 8 deletions ait/core/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,27 @@ def validate(self, ymldata=None, messages=None):

"""
content_val_list = []
schema_val = self.schema_val(messages)
try:
schema_val = self.schema_val(messages)
except yaml.YAMLError as e:
log.error(
"Unable to validate file due to YAML error. "
f"Verify that the YAML file is well formed.\n\nError: {e}"
)
return False
except jsonschema.SchemaError as e:
log.error(
"Unable to validate file due to error with schema file. "
f"Verify availability and validity of the schema file.\n\nError: {e}"
)
return False

# Loop through the list of all the tested yaml files
for yaml_file in self.yml_files_to_validate:
log.info(f"Validating: {yaml_file}")
content_val_list.append(self.content_val(yaml_file, messages=messages))

if all(content_val_list): # Test that all tested files returned True
content_val = True
else:
content_val = False

return schema_val and content_val
return schema_val and all(content_val_list)

def schema_val(self, messages=None):
"""Perform validation with processed YAML and Schema"""
Expand Down Expand Up @@ -520,8 +528,19 @@ def schema_val(self, messages=None):
return valid

def content_val(self, yaml_file, ymldata=None, messages=None):
"""Simple base content_val method - needed for unit tests"""
"""Simple base content_val method - needed for unit tests

The base content_val method doesn't check any useful elements of the
loaded file. Instead it just returns whether the file was successfully
loaded by the YAMLProcessor.

Child classes should overwrite this to implement checks for specific
content requirements that cannot be easily encoded in a schema file.
For examples, see :meth:`CmdValidator.content_val` or
:meth:`TlmValidator.content_val`
"""
self._ymlproc = YAMLProcessor(yaml_file, False)
return self._ymlproc.loaded


class CmdValidator(Validator):
Expand Down
Loading