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

filter out warnings when validating against namespaces in tests #1961

Merged
merged 6 commits into from
Sep 9, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements and minor changes
- Added support for numpy 2.0. @mavaylon1 [#1956](https://github.com/NeurodataWithoutBorders/pynwb/pull/1956)
- Make `get_cached_namespaces_to_validate` a public function @stephprince [#1961](https://github.com/NeurodataWithoutBorders/pynwb/pull/1961)

### Documentation and tutorial enhancements
- Added pre-release pull request instructions to release process documentation @stephprince [#1928](https://github.com/NeurodataWithoutBorders/pynwb/pull/1928)
Expand Down
26 changes: 15 additions & 11 deletions src/pynwb/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
return validator.validate(builder)


def _get_cached_namespaces_to_validate(
def get_cached_namespaces_to_validate(
path: str, driver: Optional[str] = None, aws_region: Optional[str] = None,
) -> Tuple[List[str], BuildManager, Dict[str, str]]:
"""
Expand All @@ -39,14 +39,18 @@
-------
The following example illustrates how we can use this function to validate against namespaces
cached in a file. This is useful, e.g., when a file was created using an extension
>>> from pynwb import validate
>>> from pynwb.validate import _get_cached_namespaces_to_validate
>>> path = "my_nwb_file.nwb"
>>> validate_namespaces, manager, cached_namespaces = _get_cached_namespaces_to_validate(path)
>>> with NWBHDF5IO(path, "r", manager=manager) as reader:
>>> errors = []
>>> for ns in validate_namespaces:
>>> errors += validate(io=reader, namespace=ns)

.. code-block:: python

from pynwb import validate
from pynwb.validate import get_cached_namespaces_to_validate
path = "my_nwb_file.nwb"
validate_namespaces, manager, cached_namespaces = get_cached_namespaces_to_validate(path)
with NWBHDF5IO(path, "r", manager=manager) as reader:
errors = []
for ns in validate_namespaces:
errors += validate(io=reader, namespace=ns)

:param path: Path for the NWB file
:return: Tuple with:
- List of strings with the most specific namespace(s) to use for validation.
Expand Down Expand Up @@ -149,7 +153,7 @@
io_kwargs = dict(path=path, mode="r", driver=driver)

if use_cached_namespaces:
cached_namespaces, manager, namespace_dependencies = _get_cached_namespaces_to_validate(
cached_namespaces, manager, namespace_dependencies = get_cached_namespaces_to_validate(
path=path, driver=driver
)
io_kwargs.update(manager=manager)
Expand Down Expand Up @@ -231,7 +235,7 @@

if args.list_namespaces:
for path in args.paths:
cached_namespaces, _, _ = _get_cached_namespaces_to_validate(path=path)
cached_namespaces, _, _ = get_cached_namespaces_to_validate(path=path)

Check warning on line 238 in src/pynwb/validate.py

View check run for this annotation

Codecov / codecov/patch

src/pynwb/validate.py#L238

Added line #L238 was not covered by tests
print("\n".join(cached_namespaces))
else:
validation_errors, validation_status = validate(
Expand Down
13 changes: 2 additions & 11 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def validate_nwbs():
examples_nwbs = glob.glob('*.nwb')

import pynwb
from pynwb.validate import get_cached_namespaces_to_validate

for nwb in examples_nwbs:
try:
Expand All @@ -171,17 +172,7 @@ def validate_nwbs():
for err in errors:
print("Error: %s" % err)

def get_namespaces(nwbfile):
comp = run(["python", "-m", "pynwb.validate",
"--list-namespaces", nwbfile],
stdout=PIPE, stderr=STDOUT, universal_newlines=True, timeout=30)

if comp.returncode != 0:
return []

return comp.stdout.split()

namespaces = get_namespaces(nwb)
namespaces, _, _ = get_cached_namespaces_to_validate(nwb)

if len(namespaces) == 0:
FAILURES += 1
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/ros3/test_ros3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pynwb import NWBHDF5IO
from pynwb import validate
from pynwb.validate import _get_cached_namespaces_to_validate
from pynwb.validate import get_cached_namespaces_to_validate
from pynwb.testing import TestCase
import urllib.request
import h5py
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_dandi_get_cached_namespaces(self):
)
}
}
found_namespaces, _, found_namespace_dependencies = _get_cached_namespaces_to_validate(
found_namespaces, _, found_namespace_dependencies = get_cached_namespaces_to_validate(
path=self.s3_test_path, driver="ros3"
)

Expand Down
Loading