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

Correct conditional to correct empty string catch. #393

Merged
merged 1 commit into from
May 7, 2022
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
45 changes: 26 additions & 19 deletions maestrowf/specification/yamlspecification.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _verify_variables(self):
logger.error(msg)
raise ValueError(msg)

if not value:
FrankD412 marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(value, str) and not value:
msg = (
"All variables must have a valid value. Empty strings "
"are not allowed."
Expand Down Expand Up @@ -276,9 +276,7 @@ def _verify_dependencies(self, keys_seen):
def verify_environment(self, schema):
"""Verify that the environment in a specification is valid."""
# validate environment against json schema
YAMLSpecification.validate_schema(
"env", self.environment, schema
)
YAMLSpecification.validate_schema("env", self.environment, schema)
# Verify the variables section of the specification.
keys_seen = self._verify_variables()
# Verify the sources section of the specification.
Expand Down Expand Up @@ -413,8 +411,9 @@ def validate_schema(parent_key, instance, schema):
re.search(r"'.+'", error.message).group(0).strip("'")
)
raise jsonschema.ValidationError(
"Unrecognized key '{0}' found in {1}."
.format(unrecognized, parent_key)
"Unrecognized key '{0}' found in {1}.".format(
unrecognized, parent_key
)
)

elif error.validator == "type":
Expand All @@ -425,8 +424,9 @@ def validate_schema(parent_key, instance, schema):
.strip("'")
)
raise jsonschema.ValidationError(
"In {0}, {1} must be of type '{2}', but found '{3}'."
.format(parent_key, path, expected_type, type(instance[path]).__name__)
f"In {parent_key}, {path} must be of type "
f"'{expected_type}', but found "
f"'{type(instance[path]).__name__}'."
)

elif error.validator == "required":
Expand All @@ -441,27 +441,34 @@ def validate_schema(parent_key, instance, schema):

elif error.validator == "uniqueItems":
raise jsonschema.ValidationError(
"Non-unique step names in {0}.run.depends."
.format(parent_key)
"Non-unique step names in {0}.run.depends.".format(
parent_key
)
)

elif error.validator == "minLength":
raise jsonschema.ValidationError(
"In {0}, empty string found as value for {1}."
.format(parent_key, path)
"In {0}, empty string found as value for {1}.".format(
parent_key, path
)
)

elif error.validator == "anyOf":
path = ".".join(list(error.path))
context_message = error.context[0].message
context_message = re.sub(r"'.+' ", "'{0}' ".format(
path
), context_message)
context_message = re.sub(
r"'.+' ", "'{0}' ".format(path), context_message
)
raise jsonschema.ValidationError(
("The value '{0}' in field {1} of {2} is not of type "
"'{3}' or does not conform to the format '$(VARNAME)'.")
.format(error.instance, path, parent_key,
error.validator_value[0]["type"])
(
"The value '{0}' in field {1} of {2} is not of type "
"'{3}' or does not conform to the format '$(VARNAME)'."
).format(
error.instance,
path,
parent_key,
error.validator_value[0]["type"],
)
)

else:
Expand Down