Repository navigation
Fix omerotools #157
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
Open
loicsauteur
wants to merge
17
commits into
imcf:devel
Choose a base branch
from
loicsauteur:fix-omerotools
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix omerotools #157
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
92dbdb0
Remove dead code from parse_url
loicsauteur 3a678d7
Update parse_url description
loicsauteur 7620399
Fix typos
loicsauteur 6e719a0
Add FileNotFoundError in upload_image_to_omero
loicsauteur 20855cb
Add test_omerotools.py with test_upload_image_to_omero
loicsauteur 1493079
Add extract_ids_from_string function
loicsauteur 2a452c7
Add parse_url_string function
loicsauteur da475ee
Refactor parse_url
loicsauteur a5f89ea
Add test for parse_url
loicsauteur c19082a
Use raw string for `pytest.raises` match
loicsauteur 08cfd8a
Lint / Fix formatting
loicsauteur b5c8960
Fix f-string call / make Python 2.7 compatible
loicsauteur 923f4cd
Fix regex 'pytest.raises' match parameters
loicsauteur 1edba08
Fix 'getDataset' from 'Long' not 'str'
loicsauteur 40e4d07
Add test script for parse_url to interactive-imageJ
loicsauteur 4b9f9e7
Fix raising FileNotFoundError conditionally for Python 2.7
loicsauteur eaa86ea
Add test script for upload_image_to_omero to interactive-imageJ
loicsauteur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/interactive-imagej/omerotools/parse_url/test_parse_url_01.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # @ String (label="OMERO HOST") host | ||
| # @ Integer (label="OMERO PORT", value=4064) port | ||
| # @ String (label="OMERO User") user | ||
| # @ String (label="OMERO Password", style="password") pwd | ||
| # @ String (label="Provide OMERO Project URL") url_project | ||
| # @ String (label="Provide OMERO 'Dataset A' URL") url_dataset | ||
| # @ String (label="Provide OMERO URL for ALL images in 'Dataset A'") url_images | ||
| # Examples | ||
| # url_project: https://omero.biozentrum.unibas.ch/webclient/?show=project-25155 | ||
| # url_dataset: https://omero.biozentrum.unibas.ch/webclient/?show=dataset-82170 | ||
| # url_images: https://omero.biozentrum.unibas.ch/webclient/?show=image-3454870|image-3454871|image-3454872|image-3454873|image-3454874 | ||
|
|
||
|
|
||
| from imcflibs.imagej import omerotools | ||
|
|
||
| # Parse the url_images to get the IDs | ||
| image_ids = [] | ||
| parts = url_images.split("|") | ||
| for part in parts: | ||
| if "image-" in part: | ||
| image_id = part.split("image-")[1].split("/")[0] | ||
| image_ids.append(image_id) | ||
| assert len(image_ids) > 0, "No image ids in image url!" | ||
|
|
||
| # Test | ||
| try: | ||
| user_client = omerotools.connect(host, port, user, pwd) | ||
|
|
||
| # Project URLs are not implemented | ||
| ids = None | ||
| try: | ||
| ids = omerotools.parse_url(user_client, url_project) | ||
| except NotImplementedError: | ||
| pass | ||
| assert ids is None | ||
|
|
||
| # Single Dataset | ||
| ids = omerotools.parse_url(user_client, url_dataset) | ||
| assert len(ids) == len(image_ids) | ||
|
|
||
| # Images url | ||
| ids = omerotools.parse_url(user_client, url_images) | ||
| assert len(ids) == len(image_ids) | ||
| for cur_id in ids: | ||
| cur_id = cur_id.getId() | ||
| assert str(cur_id) in image_ids | ||
|
|
||
| # Image IDs as comma-separated string | ||
| ids = omerotools.parse_url(user_client, ",".join(image_ids)) | ||
| assert len(ids) == len(image_ids) | ||
| for cur_id in ids: | ||
| cur_id = cur_id.getId() | ||
| assert str(cur_id) in image_ids | ||
| finally: | ||
| if user_client is not user_client: | ||
| user_client.disconnect() | ||
|
|
||
| print("Test completed!") |
19 changes: 19 additions & 0 deletions
19
tests/interactive-imagej/omerotools/upload_image_to_omero/test_upload_image_to_omero_01.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from imcflibs.imagej import omerotools | ||
|
|
||
|
|
||
| error_type = "FileNotFoundError" | ||
| try: | ||
| FileNotFoundError | ||
| except NameError: | ||
| FileNotFoundError = IOError | ||
| error_type = "IOError" | ||
|
|
||
| path = "/usr/fancy/path/pony-with-one-horn.tiff" | ||
|
|
||
| try: | ||
| # No client needed. Only testing the exception | ||
| omerotools.upload_image_to_omero(None, path, None) | ||
| except FileNotFoundError: | ||
| print("Got the expected {}".format(error_type)) | ||
|
|
||
| print("Test completed!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """Tests for the imcflibs.imagej.omerotools module.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from imcflibs.imagej.omerotools import ( | ||
| extract_ids_from_string, | ||
| parse_url, | ||
| parse_url_string, | ||
| upload_image_to_omero, | ||
| ) | ||
|
|
||
| # Enusre Python 2.7 and 3.x compability | ||
| try: | ||
| FileNotFoundError | ||
| except NameError: | ||
| FileNotFoundError = IOError | ||
|
|
||
|
|
||
| def test_upload_image_to_omero(): | ||
| """Test `upload_image_to_omero()`. | ||
|
|
||
| Tests only the case for non-existing files. | ||
| """ | ||
| path = "/usr/random/path/questionable/file.tiff" | ||
| with pytest.raises(FileNotFoundError, match=r"Could not find file"): | ||
| upload_image_to_omero(None, path, None) | ||
|
|
||
|
|
||
| def test_extract_ids_from_string(): | ||
| """Test `extract_ids_from_string()`.""" | ||
|
|
||
| url_proj = "webclient/?show=project-25406" | ||
| # Expect error with wrong omero_type | ||
| with pytest.raises(ValueError, match=r"Unknown OMERO type"): | ||
| extract_ids_from_string(url_proj, "unicorn") | ||
|
|
||
| assert len(extract_ids_from_string(url_proj, "Project")) == 1 | ||
| assert len(extract_ids_from_string(url_proj, "Project-")) == 1 | ||
| assert len(extract_ids_from_string(url_proj, "Dataset")) == 0 | ||
|
|
||
| url_dataset = "webclient/?show=dataset-82753" | ||
| assert len(extract_ids_from_string(url_dataset, "dataset")) == 1 | ||
|
|
||
| url_image = "webclient/?show=image-3598144" | ||
| assert len(extract_ids_from_string(url_image, "image")) == 1 | ||
|
|
||
| url_multi_image = ( | ||
| "webclient/?show=image-3598144|image-3598145|image-3598146|image-3598147" | ||
| ) | ||
| assert len(extract_ids_from_string(url_multi_image, "image-")) == 4 | ||
| assert len(extract_ids_from_string(url_multi_image, "Project")) == 0 | ||
|
|
||
| url_bad = "https://github.com/imcf/python-imcflibs" | ||
| assert len(extract_ids_from_string(url_bad, "image")) == 0 | ||
|
|
||
|
|
||
| def test_parse_url_string(): | ||
| """Test `parse_url_string()`.""" | ||
| url_proj = "webclient/?show=project-25406" | ||
| omero_ids, omero_type = parse_url_string(url_proj) | ||
| assert len(omero_ids) == 1 | ||
| assert omero_type == "project" | ||
| assert "25406" in omero_ids | ||
|
|
||
| url_dataset = "webclient/?show=dataset-82753" | ||
| omero_ids, omero_type = parse_url_string(url_dataset) | ||
| assert len(omero_ids) == 1 | ||
| assert omero_type == "dataset" | ||
| assert "82753" in omero_ids | ||
|
|
||
| url_image = "webclient/?show=image-3598144" | ||
| omero_ids, omero_type = parse_url_string(url_image) | ||
| assert len(omero_ids) == 1 | ||
| assert omero_type == "image" | ||
| assert "3598144" in omero_ids | ||
|
|
||
| url_multi_image = ( | ||
| "webclient/?show=image-3598144|image-3598145|image-3598146|image-3598147" | ||
| ) | ||
| omero_ids, omero_type = parse_url_string(url_multi_image) | ||
| assert len(omero_ids) == 4 | ||
| assert omero_type == "image" | ||
| assert "3598144" in omero_ids | ||
| assert "3598145" in omero_ids | ||
| assert "3598146" in omero_ids | ||
| assert "3598147" in omero_ids | ||
|
|
||
| url_bad = "https://github.com/imcf/python-imcflibs" | ||
| omero_ids, omero_type = parse_url_string(url_bad) | ||
| assert len(omero_ids) == 0 | ||
| assert omero_type == "" | ||
|
|
||
|
|
||
| def test_parse_url(): | ||
| """Test `parse_url()`. | ||
|
|
||
| Only tests the first part of the function | ||
| (NotImplementedError on Project-URLs). | ||
| Since the reset of the function depends on OMERO libraries. | ||
| """ | ||
| url_empty = "" | ||
| with pytest.raises(ValueError, match=r"No OMERO link or image ID prov"): | ||
| parse_url(None, url_empty) | ||
|
|
||
| url_proj = "webclient/?show=project-25406" | ||
| with pytest.raises( | ||
| NotImplementedError, | ||
| match=r"Getting Image IDs from Project", | ||
| ): | ||
| parse_url(None, url_proj) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.