Skip to content

Commit ba531a6

Browse files
committed
split long tests into smaller ones
1 parent fc61747 commit ba531a6

2 files changed

Lines changed: 48 additions & 14 deletions

File tree

test/test_read.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -960,14 +960,30 @@ def test_from_uri(tmpdir, source_base):
960960
assert rcrate.preview.id == "ro-crate-preview.html"
961961
assert rcrate.get(test_fn)
962962
assert rcrate.get(remote_f_uri)
963+
964+
965+
@pytest.mark.parametrize("source_base", [
966+
"https://raw.githubusercontent.com/ResearchObject/ro-crate-py/master/test/",
967+
f"file:///{THIS_DIR}/" # extra slash needed on some windows systems
968+
])
969+
def test_from_uri_fetch_remote(tmpdir, source_base):
970+
source = f"{source_base}test-data/read_crate/ro-crate-metadata.json"
971+
base_uri = f"{source_base}test-data/read_crate/"
972+
# this is an absolute URI in the metadata, note it's outside the crate
973+
remote_f_uri = ("https://raw.githubusercontent.com/ResearchObject/"
974+
"ro-crate-py/master/test/test-data/sample_file.txt")
975+
test_fn = "test_file_galaxy.txt"
976+
crate = ROCrate(source)
977+
remote_f = crate.get(remote_f_uri)
978+
test_f = crate.get(test_fn)
963979
# now set some fetch_remote to True
964980
crate.preview.fetch_remote = True
965981
test_f.fetch_remote = True
966982
remote_f.fetch_remote = True
967983
assert remote_f.id == remote_f_uri
968984
# remote_f.id is the full URI. Check that the destination path is
969985
# the output dir / remote_f.id minus the root dataset id.
970-
shutil.rmtree(out_path)
986+
out_path = tmpdir / "out_crate"
971987
crate.write(out_path)
972988
assert (out_path / "sample_file.txt").is_file()
973989
# check that localPath overrides the default destination
@@ -1015,20 +1031,31 @@ def test_from_uri_detached(tmpdir, source_base):
10151031
rcrate = ROCrate(out_path)
10161032
assert rcrate.get(f"{base_uri}sample_file.txt")
10171033
assert rcrate.get(f"{base_uri}test_file_galaxy.txt")
1034+
license = rcrate.get("http://spdx.org/licenses/CC0-1.0")
1035+
assert set(rcrate.contextual_entities) == {license}
1036+
1037+
1038+
@pytest.mark.parametrize("source_base", [
1039+
"https://raw.githubusercontent.com/ResearchObject/ro-crate-py/master/test/",
1040+
f"file:///{THIS_DIR}/" # extra slash needed on some windows systems
1041+
])
1042+
def test_from_uri_detached_fetch_remote(tmpdir, source_base):
1043+
source = f"{source_base}test-data/detached-ro-crate-metadata.json"
1044+
base_uri = ("https://raw.githubusercontent.com/ResearchObject/ro-crate-py/"
1045+
"master/test/test-data/")
1046+
crate = ROCrate(source)
1047+
test_file_galaxy = crate.get(f"{base_uri}test_file_galaxy.txt")
10181048
# now set fetch_remote to True
10191049
test_file_galaxy.fetch_remote = True
1020-
shutil.rmtree(out_path)
1050+
assert test_file_galaxy.get("localPath") == "test-data/test_file_galaxy.txt"
1051+
out_path = tmpdir / "out_crate"
10211052
crate.write(out_path)
10221053
assert (out_path / "test-data" / "test_file_galaxy.txt").is_file()
10231054
rcrate = ROCrate(out_path)
1024-
rsample_file = rcrate.get(f"{base_uri}sample_file.txt")
1025-
assert rsample_file
10261055
rtest_file_galaxy = rcrate.get(f"{base_uri}test_file_galaxy.txt")
10271056
assert rtest_file_galaxy
10281057
assert rtest_file_galaxy.get("contentUrl") == f"{base_uri}test_file_galaxy.txt"
10291058
assert rtest_file_galaxy.get("localPath") == "test-data/test_file_galaxy.txt"
1030-
license = rcrate.get("http://spdx.org/licenses/CC0-1.0")
1031-
assert set(rcrate.contextual_entities) == {license}
10321059

10331060

10341061
def test_from_file(test_data_dir, tmpdir):

test/test_write.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,20 @@ def test_detached_creation(tmpdir, to_zip):
806806
assert rcrate.root_dataset.id == base_uri
807807
assert rcrate.metadata.id == "ro-crate-metadata.json"
808808
assert rcrate.metadata["about"] is rcrate.root_dataset
809-
rd1 = rcrate.get(f"{base_uri}d1")
810-
assert rd1
811-
rf1 = rcrate.get(f"{base_uri}f1")
812-
assert rf1
809+
assert rcrate.get(f"{base_uri}d1")
810+
assert rcrate.get(f"{base_uri}f1")
813811
rp = rcrate.get(orcid)
814812
assert rp["name"] == name
815813

814+
815+
def test_detached_creation_write_detached(tmpdir):
816+
base_uri = "http://example.com/crate/"
817+
orcid = "https://orcid.org/0000-0002-1825-0097"
818+
name = "Josiah Carberry"
819+
crate = ROCrate(root_dataset_id=base_uri)
820+
crate.add_dataset(f"{base_uri}d1")
821+
crate.add_file(f"{base_uri}f1")
822+
crate.add(Person(crate, orcid, properties={"name": name}))
816823
detached_md_path = tmpdir / "example-ro-crate-metadata.json"
817824
crate.write_detached(detached_md_path)
818825
assert detached_md_path.is_file()
@@ -822,13 +829,13 @@ def test_detached_creation(tmpdir, to_zip):
822829
assert rcrate.root_dataset.id == base_uri
823830
assert rcrate.metadata.id == "ro-crate-metadata.json"
824831
assert rcrate.metadata["about"] is rcrate.root_dataset
825-
rd1 = rcrate.get(f"{base_uri}d1")
826-
assert rd1
827-
rf1 = rcrate.get(f"{base_uri}f1")
828-
assert rf1
832+
assert rcrate.get(f"{base_uri}d1")
833+
assert rcrate.get(f"{base_uri}f1")
829834
rp = rcrate.get(orcid)
830835
assert rp["name"] == name
831836

837+
838+
def test_detached_creation_exceptions():
832839
with pytest.raises(ValueError):
833840
ROCrate(root_dataset_id="foo/bar")
834841
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)