Skip to content

Commit

Permalink
tests: only test xml conversion if available
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- committed Aug 25, 2021
1 parent c4af827 commit c41bff5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ dependencies:
- pip
- jpype1>=1.0.1
- dynaconf>=3,!=3.1.0
- ome-types # [ sys.version_info >= (3,7) ]
- shapely
- qupath
- pytest>=6
- pytest-cov
- pip:
- "-e .[ome]" # [ PAQUO_DEVEL ]
- "-e ." # [ PAQUO_DEVEL ]
2 changes: 1 addition & 1 deletion paquo/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def to_ome_xml(self, prefix="paquo", fill_alpha=0.0) -> str:
from ome_types.model.map import M
from ome_types.model.shape import FillRule
except ImportError:
raise RuntimeError(f"{type(self).__name__}.to_ome_xml requires 'ome-types' python module")
raise RuntimeError(f"{type(self).__name__}.to_ome_xml requires 'ome-types' python module and python>=3.7")

from paquo.java import EllipseROI
from paquo.java import GeometryROI
Expand Down
15 changes: 12 additions & 3 deletions paquo/tests/test_readonly.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib.util
import shutil
import tempfile
from contextlib import contextmanager
Expand Down Expand Up @@ -84,9 +85,15 @@ def setattr(self, item, value):
self._if.discard(item)
setattr(self._i, item, value)

def callmethod(self, method, *args, **kwargs):
def callmethod(self, method, *args, ignore_exception=False, **kwargs):
self._if.discard(method)
return getattr(self._i, method)(*args, **kwargs)
try:
return getattr(self._i, method)(*args, **kwargs)
except BaseException as e:
if ignore_exception:
pass
else:
raise e

def unused_public_interface(self):
return self._if
Expand Down Expand Up @@ -190,6 +197,8 @@ def test_images_metadata_and_properties(readonly_project):

def test_hierarchy(readonly_project):

OME_NOT_INSTALLED = importlib.util.find_spec("ome_types") is None

with assert_no_modification(readonly_project) as qp:
image = qp.images[0]
hierarchy = image.hierarchy
Expand All @@ -204,7 +213,7 @@ def test_hierarchy(readonly_project):

# these do nothing
h.callmethod("to_geojson")
h.callmethod("to_ome_xml")
h.callmethod("to_ome_xml", ignore_exception=OME_NOT_INSTALLED)

# these are not allowed in readonly
with pytest.raises(IOError):
Expand Down

0 comments on commit c41bff5

Please sign in to comment.