|
25 | 25 | def test_valid_url(): |
26 | 26 | uri = URI("http://example.com") |
27 | 27 | assert uri.is_remote_resource() |
| 28 | + assert uri.is_natively_checkable() |
| 29 | + assert uri.has_supported_rocrate_scheme() |
| 30 | + |
| 31 | + |
| 32 | +def test_uri_with_unknown_scheme_is_accepted_but_not_supported_as_rocrate_root(): |
| 33 | + # Schemes outside the natively-supported set are valid URIs (they may |
| 34 | + # appear as Data Entity identifiers, e.g. scp://, s3://) but they are |
| 35 | + # not accepted as RO-Crate root URIs. |
| 36 | + uri = URI("httpx:///example.com") |
| 37 | + assert uri.is_remote_resource() |
| 38 | + assert not uri.is_natively_checkable() |
| 39 | + assert not uri.has_supported_rocrate_scheme() |
28 | 40 |
|
29 | 41 |
|
30 | 42 | def test_invalid_url(): |
| 43 | + # A bare token without any scheme/path separator is not a valid URI. |
31 | 44 | with pytest.raises(ValueError): |
32 | | - URI("httpx:///example.com") |
| 45 | + URI("") |
| 46 | + |
| 47 | + |
| 48 | +def test_scp_uri_is_remote(): |
| 49 | + uri = URI("scp://transfer.example.org//data/A.0.0") |
| 50 | + assert uri.is_remote_resource() |
| 51 | + assert uri.is_known_remote_scheme() |
| 52 | + assert not uri.is_natively_checkable() |
| 53 | + |
| 54 | + |
| 55 | +def test_s3_uri_is_remote(): |
| 56 | + uri = URI("s3://bucket/key/path") |
| 57 | + assert uri.is_remote_resource() |
| 58 | + assert uri.is_known_remote_scheme() |
| 59 | + assert not uri.is_natively_checkable() |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.parametrize("uri_str,expected_scheme", [ |
| 63 | + # Scheme-only (no authority) absolute URIs are valid per RFC 3986 and |
| 64 | + # accepted by RO-Crate 1.1 § 4.2.2 as Data Entity `@id` values. |
| 65 | + ("urn:doi:10.5281/zenodo.1234", "urn"), |
| 66 | + ("doi:10.5281/zenodo.1234", "doi"), |
| 67 | + ("arcp://name,foo/bar", "arcp"), |
| 68 | +]) |
| 69 | +def test_scheme_only_absolute_uri_is_remote(uri_str, expected_scheme): |
| 70 | + uri = URI(uri_str) |
| 71 | + assert uri.scheme == expected_scheme |
| 72 | + assert uri.is_remote_resource() |
| 73 | + assert not uri.is_natively_checkable() |
33 | 74 |
|
34 | 75 |
|
35 | 76 | def test_url_with_query_params(): |
@@ -131,10 +172,12 @@ def test_rocrate_uri_remote_valid(): |
131 | 172 |
|
132 | 173 |
|
133 | 174 | def test_rocrate_uri_remote_invalid(): |
134 | | - |
135 | | - with pytest.raises(ValueError) as excinfo: |
136 | | - URI("httpx:///example.com") |
137 | | - assert str(excinfo.value) == "Invalid URI: httpx:///example.com" |
| 175 | + # An unknown scheme is a valid URI but cannot be used as an RO-Crate root. |
| 176 | + uri = URI("httpx:///example.com") |
| 177 | + assert not validate_rocrate_uri(uri, silent=True), \ |
| 178 | + f"The URI {uri} should not be accepted as an RO-Crate root" |
| 179 | + with pytest.raises(ROCrateInvalidURIError): |
| 180 | + validate_rocrate_uri(uri, silent=False) |
138 | 181 |
|
139 | 182 | # Test with an invalid remote URL |
140 | 183 | uri = URI("https:///example.com") |
|
0 commit comments