@@ -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
10341061def test_from_file (test_data_dir , tmpdir ):
0 commit comments