Skip to content

Commit

Permalink
fix test warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Jan 4, 2025
1 parent d7efa5b commit 90bdae6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/gallery/domain/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,21 @@
# :py:class:`~pynwb.image.IndexSeries` that indexes into the
# :py:class:`~pynwb.base.Images`.

from scipy import misc
from scipy import datasets

from pynwb.base import ImageReferences
from pynwb.image import GrayscaleImage, Images, IndexSeries, RGBImage

gs_face = GrayscaleImage(
name="gs_face",
data=misc.face(gray=True),
data=datasets.face(gray=True),
description="Grayscale version of a raccoon.",
resolution=35.433071,
)

rgb_face = RGBImage(
name="rgb_face",
data=misc.face(),
data=datasets.face(),
resolution=70.0,
description="RGB version of a raccoon.",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/hdf5/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def test_append(self):
np.testing.assert_equal(nwb.acquisition['timeseries2'].data[:], ts2.data)
self.assertIs(nwb.processing['test_proc_mod']['LFP'].electrical_series['test_es'].electrodes,
nwb.acquisition['timeseries2'].electrodes)
errors = validate(io)
errors = validate(io=io)
self.assertEqual(len(errors), 0, errors)

def test_electrode_id_uniqueness(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/hdf5/test_modular_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def validate(self):
for fn in filenames:
if os.path.exists(fn):
with NWBHDF5IO(fn, mode='r') as io:
errors = pynwb_validate(io)
errors = pynwb_validate(io=io)
if errors:
for err in errors:
raise Exception(err)
Expand Down
32 changes: 23 additions & 9 deletions tests/validation/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def get_io(self, path):
def test_validate_io_no_cache(self):
"""Test that validating a file with no cached spec against the core namespace succeeds."""
with self.get_io('tests/back_compat/1.0.2_nwbfile.nwb') as io:
errors = validate(io)
errors = validate(io=io)
self.assertEqual(errors, [])

def test_validate_io_no_cache_bad_ns(self):
Expand All @@ -227,19 +227,19 @@ def test_validate_io_no_cache_bad_ns(self):
def test_validate_io_cached(self):
"""Test that validating a file with cached spec against its cached namespace succeeds."""
with self.get_io('tests/back_compat/1.1.2_nwbfile.nwb') as io:
errors = validate(io)
errors = validate(io=io)
self.assertEqual(errors, [])

def test_validate_io_cached_extension(self):
"""Test that validating a file with cached spec against its cached namespaces succeeds."""
with self.get_io('tests/back_compat/2.1.0_nwbfile_with_extension.nwb') as io:
errors = validate(io)
errors = validate(io=io)
self.assertEqual(errors, [])

def test_validate_io_cached_extension_pass_ns(self):
"""Test that validating a file with cached extension spec against the extension namespace succeeds."""
with self.get_io('tests/back_compat/2.1.0_nwbfile_with_extension.nwb') as io:
errors = validate(io, 'ndx-testextension')
errors = validate(io=io, namespace='ndx-testextension')
self.assertEqual(errors, [])

def test_validate_file_cached_extension(self):
Expand Down Expand Up @@ -281,17 +281,17 @@ def test_validate_io_cached_hdmf_common(self):

def test_validate_io_and_path_same(self):
"""Test that validating a file with an io object and a path return the same results."""
tests = [('tests/back_compat/1.0.2_nwbfile.nwb', None),
('tests/back_compat/1.1.2_nwbfile.nwb', None),
tests = [('tests/back_compat/1.1.2_nwbfile.nwb', None),
('tests/back_compat/1.1.2_nwbfile.nwb', 'core'),
('tests/back_compat/2.1.0_nwbfile_with_extension.nwb', None),
('tests/back_compat/2.1.0_nwbfile_with_extension.nwb', 'ndx-testextension'),]

tests_with_error = [('tests/back_compat/1.0.2_nwbfile.nwb', 'notfound'),
('tests/back_compat/1.1.2_nwbfile.nwb', 'notfound'),
tests_with_error = [('tests/back_compat/1.1.2_nwbfile.nwb', 'notfound'),
('tests/back_compat/1.1.2_nwbfile.nwb', 'hdmf-common'),
('tests/back_compat/2.1.0_nwbfile_with_extension.nwb', 'core'),]

tests_with_warning = [('tests/back_compat/1.0.2_nwbfile.nwb', None),]

# paths that cause no errors
for path, ns in tests:
with patch("sys.stdout", new=StringIO()) as fake_out:
Expand All @@ -307,7 +307,21 @@ def test_validate_io_and_path_same(self):
out_path = out_path.replace(f'{path} ', '')
self.assertEqual(results_io, results_path)
self.assertEqual(out_io, out_path)


#paths that return warnings
for path, ns in tests_with_warning:
with self.assertWarns(UserWarning) as w_io:
with self.get_io(path=path) as io:
results_io = validate(io=io, namespace=ns, verbose=True)
print(results_io)

with self.assertWarns(UserWarning) as w_path:
results_path = validate(path=path, namespace=ns, verbose=True)

# remove path from error messages since it will not be included in io outputs
out_path = str(w_path.warning).replace(f'{path} ', '')
self.assertEqual(str(w_io.warning), out_path)

# paths that return errors
for path, ns in tests_with_error:
with self.assertRaises(ValueError) as e_io:
Expand Down

0 comments on commit 90bdae6

Please sign in to comment.