-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from UtrechtUniversity/develop
V1.1.0
- Loading branch information
Showing
25 changed files
with
1,226 additions
and
326 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,50 @@ | ||
from ibridges.path import IrodsPath | ||
import pytest | ||
from irods.exception import DataObjectDoesNotExist | ||
|
||
|
||
def test_path_open_error(session, collection): | ||
ipath = IrodsPath(session, "open_err_test.txt") | ||
ipath.remove() | ||
coll_ipath = IrodsPath(session, collection.path) | ||
|
||
# Reading data objects that do no exist should raise an error. | ||
with pytest.raises(DataObjectDoesNotExist): | ||
with ipath.open("r") as handle: | ||
handle.read() | ||
|
||
with pytest.raises(DataObjectDoesNotExist): | ||
with ipath.open("a") as handle: | ||
handle.write("abc") | ||
|
||
# We should not be able to open collections. | ||
with pytest.raises(ValueError): | ||
with coll_ipath.open("r") as handle: | ||
handle.read() | ||
|
||
with pytest.raises(ValueError): | ||
with coll_ipath.open("w") as handle: | ||
handle.read() | ||
|
||
ipath.remove() | ||
|
||
|
||
def test_path_open(session): | ||
ipath = IrodsPath(session, "open_test.txt") | ||
ipath.remove() | ||
|
||
test_str_1 = "This is a test." | ||
test_str_2 = "\nAnother test." | ||
|
||
with ipath.open("w") as handle: | ||
handle.write(test_str_1.encode("utf-8")) | ||
|
||
with ipath.open("r") as handle: | ||
cur_str = handle.read().decode("utf-8") | ||
assert cur_str == test_str_1 | ||
|
||
with ipath.open("a") as handle: | ||
handle.write(test_str_2.encode("utf-8")) | ||
|
||
with ipath.open("r") as handle: | ||
assert handle.read().decode("utf-8") == test_str_1 + test_str_2 |
This file contains 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,60 @@ | ||
from pytest import mark | ||
|
||
from ibridges import IrodsPath, search_data, upload | ||
from ibridges.search import MetaSearch | ||
|
||
|
||
def _found(search_res, path): | ||
for res in search_res: | ||
assert isinstance(res, IrodsPath) | ||
if str(res) == str(path): | ||
return True | ||
return False | ||
|
||
@mark.parametrize("item_name", ["collection", "dataobject"]) | ||
def test_find_path(session, item_name, request): | ||
item = request.getfixturevalue(item_name) | ||
ipath = IrodsPath(session, item.path) | ||
assert _found(search_data(session, path_pattern=item.name), item.path) | ||
assert _found(search_data(session, path_pattern=item.name[:4]+"%"), item.path) | ||
assert _found(search_data(session, ipath.parent, item.name), item.path) | ||
assert _found(search_data(session, ipath.parent.parent, item.name), item.path) | ||
assert _found(search_data(session, IrodsPath(session, "/"), item.name), item.path) | ||
pat = item.name[:4] + "%" | ||
assert _found(search_data(session, path_pattern=pat), item.path) | ||
pat = "%" + item.name[-3:] | ||
assert _found(search_data(session, path_pattern=pat), item.path) | ||
pat = f"{ipath.parent.name}/%{ipath.name[2:]}" | ||
assert _found(search_data(session, IrodsPath(session, "/"), path_pattern=pat), item.path) | ||
assert not _found(search_data(session, path_pattern="random_file"), item.path) | ||
|
||
|
||
def test_find_checksum(session, dataobject): | ||
ipath = IrodsPath(session, dataobject.path) | ||
checksum = ipath.checksum | ||
assert _found(search_data(session, IrodsPath(session, "/"), checksum=checksum), ipath) | ||
assert not _found(search_data(session, IrodsPath(session, "/"), checksum="sha2:a9s8d7hjas"), ipath) | ||
assert _found(search_data(session, IrodsPath(session, "/"), checksum=checksum[:15] + "%"), ipath) | ||
|
||
|
||
@mark.parametrize("metadata,is_found", [ | ||
(MetaSearch("Author", "Ben"), True), | ||
(MetaSearch(units="kg"), True), | ||
(MetaSearch(value="10"), True), | ||
(MetaSearch(key="Random"), False), | ||
(MetaSearch(key="Author", value="10"), False), | ||
(MetaSearch(key="Author", units="kg"), False), | ||
(MetaSearch(key="Mass", units=None), False), | ||
([MetaSearch(key="Author"), MetaSearch(value="10")], True), | ||
([MetaSearch("Author"), MetaSearch("Random")], False), | ||
]) | ||
@mark.parametrize("item_name", ["collection", "dataobject"]) | ||
def test_find_meta(session, item_name, request, metadata, is_found): | ||
item = request.getfixturevalue(item_name) | ||
ipath = IrodsPath(session, item.path) | ||
ipath.meta.clear() | ||
ipath.meta.add("Author", "Ben") | ||
ipath.meta.add("Mass", "10", "kg") | ||
|
||
res = _found(search_data(session, metadata=metadata), ipath) | ||
assert res == is_found |
This file contains 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
This file contains 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,29 @@ | ||
from copy import deepcopy | ||
|
||
from pytest import mark | ||
|
||
from ibridges import IrodsPath, Session, download, upload | ||
from ibridges.util import calc_checksum, checksums_equal | ||
|
||
|
||
@mark.parametrize( | ||
"check_type,checksum", [ | ||
# There seems some PRC issue with dynamically switching checksums | ||
# ("md5", "e313c75f6de6e7cea6c641a99adb18d9"), | ||
("sha2", "sha2:Ys0LhUZdm4jCp83Zy//9Jojs74BzKDrnYYPqqv0MqeU=")] | ||
) | ||
def test_calc_checksum(irods_env, config, check_type, checksum, testdata, tmp_path): | ||
ienv = deepcopy(irods_env) | ||
ienv["irods_default_hash_scheme"] = check_type.upper() | ||
with Session(irods_env=ienv, password=config["password"]) as session: | ||
ipath_coll = IrodsPath(session, "test_check") | ||
ipath_coll.remove() | ||
ipath_coll.create_collection(session, ipath_coll) | ||
upload(session, testdata / "bunny.rtf", ipath_coll) | ||
ipath = ipath_coll / "bunny.rtf" | ||
download(session, ipath, tmp_path) | ||
assert calc_checksum(ipath, checksum_type=check_type) == checksum | ||
assert calc_checksum(tmp_path / "bunny.rtf", checksum_type=check_type) == checksum | ||
assert checksums_equal(ipath, tmp_path / "bunny.rtf") | ||
ipath_coll.remove() | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
sphinx<8.0.0 | ||
sphinx<9.0.0 | ||
sphinx_inline_tabs | ||
sphinx-rtd-theme | ||
sphinxcontrib-napoleon | ||
|
This file contains 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 |
---|---|---|
|
@@ -55,6 +55,7 @@ Searching for data | |
:toctree: generated/ | ||
|
||
search_data | ||
MetaSearch | ||
|
||
|
||
Tickets | ||
|
Oops, something went wrong.