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

Test validate script and function directly and add test to CI #1326

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions src/pynwb/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ def main():
if args.cached_namespace:
catalog = NamespaceCatalog(NWBGroupSpec, NWBDatasetSpec, NWBNamespace)
ns_deps = NWBHDF5IO.load_namespaces(catalog, path)
s = set(ns_deps.keys()) # determine which namespaces are the most
for k in ns_deps: # specific (i.e. extensions) and validate
s -= ns_deps[k].keys() # against those
namespaces = list(sorted(s))
if args.ns:
if args.ns in ns_deps.keys():
namespaces = [args.ns]
else:
print("The namespace '{}' could not be found as only namespaces {} are cached.".format(
args.ns, list(ns_deps.keys())), file=sys.stderr)
sys.exit(1)
else:
s = set(ns_deps.keys()) # determine which namespaces are the most
for k in ns_deps: # specific (i.e. extensions) and validate
s -= ns_deps[k].keys() # against those
namespaces = list(sorted(s))
if len(namespaces) > 0:
tm = TypeMap(catalog)
manager = BuildManager(tm)
Expand Down Expand Up @@ -109,14 +117,14 @@ def main():
if args.ns in namespaces:
namespaces = [args.ns]
else:
print("The namespace {} could not be found in {} as only {} is present.".format(
print("The namespace '{}' could not be found in {} as only {} is present.".format(
args.ns, specloc, namespaces), file=sys.stderr)
ret = 1
continue

with NWBHDF5IO(path, mode='r', manager=manager) as io:
for ns in namespaces:
print("Validating {} against {} using namespace {}.".format(path, specloc, ns))
print("Validating {} against {} using namespace '{}'.".format(path, specloc, ns))
ret = ret or _validate_helper(io=io, namespace=ns)

sys.exit(ret)
Expand Down
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def main():
# Run unit tests for pynwb package
if flags['pynwb'] in args.suites:
run_test_suite("tests/unit", "pynwb unit tests", verbose=args.verbosity)
run_test_suite("tests/validation", "pynwb basic validate tests", verbose=args.verbosity)

# Run example tests
if flags['example'] in args.suites:
Expand Down
8 changes: 2 additions & 6 deletions tests/validation/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ def test_validate_file_no_cache_bad_ns(self):
capture_output=True)

stderr_regex = re.compile(
r".*UserWarning: No cached namespaces found in tests/back_compat/1\.0\.2_nwbfile\.nwb\s*"
r"warnings.warn\(msg\)\s*"
r"The file tests/back_compat/1\.0\.2_nwbfile\.nwb has no cached namespace information\. "
r"Falling back to pynwb namespace information\.\s*"
r"The namespace 'notfound' could not be found in pynwb namespace information\.\s*"
r"The namespace 'notfound' could not be found as only namespaces \[\] are cached\."
)
self.assertRegex(result.stderr.decode('utf-8'), stderr_regex)

Expand All @@ -63,7 +59,7 @@ def test_validate_file_cached_bad_ns(self):
capture_output=True)

stderr_regex = re.compile(
r"The namespace 'notfound' could not be found in cached namespace information\.\s*"
r"The namespace 'notfound' could not be found as only namespaces \['hdmf-common', 'core'\] are cached\."
)
self.assertRegex(result.stderr.decode('utf-8'), stderr_regex)

Expand Down