diff --git a/src/pynwb/validate.py b/src/pynwb/validate.py index 2e62eecfb..ccd228d9a 100644 --- a/src/pynwb/validate.py +++ b/src/pynwb/validate.py @@ -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) @@ -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) diff --git a/test.py b/test.py index e74fa1890..2fe9b6685 100755 --- a/test.py +++ b/test.py @@ -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: diff --git a/tests/validation/test_validate.py b/tests/validation/test_validate.py index cf946aa0d..588bc408e 100644 --- a/tests/validation/test_validate.py +++ b/tests/validation/test_validate.py @@ -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) @@ -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)