Skip to content

Commit bf41df8

Browse files
Merge pull request #341 from NeurodataWithoutBorders/fix_images_pynwb_2_0_0
[Bug]: Correctly skip Images checks for PyNWB<2.1.0
2 parents d44b291 + 7c0589f commit bf41df8

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/nwbinspector/checks/images.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
"""Checks specific to the Images neurodata type."""
2-
from ..register_checks import register_check, Importance, InspectorMessage
3-
4-
try: # The Images neurodata type was unavailable prior to PyNWB v.2.1.0
5-
from pynwb.base import Images
6-
7-
HAVE_IMAGES = True
8-
except ImportError:
9-
HAVE_IMAGES = False
2+
from packaging.version import Version
103

114
from pynwb.image import IndexSeries
125

13-
if HAVE_IMAGES:
6+
from ..register_checks import register_check, Importance, InspectorMessage
7+
from ..utils import get_package_version
8+
9+
# The Images neurodata type was unavailable prior to PyNWB v.2.1.0
10+
if get_package_version(name="pynwb") >= Version("2.1.0"):
11+
from pynwb.base import Images
1412

1513
@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=Images)
1614
def check_order_of_images_unique(images: Images):

tests/unit_tests/test_images.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
import numpy as np
44
from pynwb import TimeSeries
55
from pynwb.image import GrayscaleImage, IndexSeries
6+
from packaging.version import Version
67

78
from nwbinspector import InspectorMessage, Importance
89
from nwbinspector.checks.images import (
910
check_order_of_images_unique,
1011
check_order_of_images_len,
1112
check_index_series_points_to_image,
1213
)
14+
from nwbinspector.utils import get_package_version
1315

14-
try:
15-
from pynwb.base import Images, ImageReferences
16-
17-
HAVE_IMAGES = True
18-
except ImportError:
19-
HAVE_IMAGES = False
16+
HAVE_IMAGES = get_package_version(name="pynwb") >= Version("2.1.0")
2017
skip_reason = "You must have PyNWB>=v2.1.0 to run these tests!"
18+
if HAVE_IMAGES:
19+
from pynwb.base import Images, ImageReferences
2120

2221

2322
@pytest.mark.skipif(not HAVE_IMAGES, reason=skip_reason)

0 commit comments

Comments
 (0)