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

Validation find unexpected elements #1178

Closed
Closed
Changes from 2 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
33 changes: 21 additions & 12 deletions src/pynwb/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@
from pynwb import validate, CORE_NAMESPACE, NWBHDF5IO
from pynwb.spec import NWBDatasetSpec, NWBGroupSpec, NWBNamespace

def _print_results(results, txt):

def _print_errors(validation_errors):
if validation_errors:
print(' - found the following errors:', file=sys.stderr)
for err in validation_errors:
print(str(err), file=sys.stderr)
if results:
print(' - found the following {}:'.format(txt), file=sys.stderr)
for x in results:
print(str(x), file=sys.stderr)
else:
print(' - no errors found.')
print(" - no {} found.".format(txt))


def _validate_helper(**kwargs):
errors = validate(**kwargs)
_print_errors(errors)
severity = kwargs.pop('severity')

return (errors is not None and len(errors) > 0)
issues = validate(**kwargs)

errors = list(filter(lambda issue: issue.severity >= severity, issues))
warnings = list(filter(lambda issue: issue.severity < severity, issues))

_print_results(errors, "errors")
_print_results(warnings, "warnings")

return errors is not None and len(errors) > 0


def main():
Expand All @@ -42,10 +49,12 @@ def main():

feature_parser = parser.add_mutually_exclusive_group(required=False)
feature_parser.add_argument("--cached-namespace", dest="cached_namespace", action='store_true',
help="Use the cached namespace (default).")
help="Use the cached namespace (default: %(default)s).", default=True)
rly marked this conversation as resolved.
Show resolved Hide resolved
feature_parser.add_argument('--no-cached-namespace', dest="cached_namespace", action='store_false',
help="Don't use the cached namespace.")
parser.set_defaults(cached_namespace=True)
feature_parser.add_argument('--severity', dest="severity", type=int,
help="Report anything with the given severity or higher as error (default: %(default)s).",
rly marked this conversation as resolved.
Show resolved Hide resolved
default=10, choices=range(0, 11))

args = parser.parse_args()
ret = 0
Expand Down Expand Up @@ -117,7 +126,7 @@ def main():
with NWBHDF5IO(path, mode='r', manager=manager) as io:
for ns in namespaces:
print("Validating {} against {} using namespace {}.".format(path, specloc, ns))
ret = ret or _validate_helper(io=io, namespace=ns)
ret = ret or _validate_helper(io=io, namespace=ns, severity=args.severity)

sys.exit(ret)

Expand Down