Skip to content

Commit f5d0d8f

Browse files
committed
test(uri): ✅ add tests for scheme classification and rocrate-root checks
1 parent 0196dc9 commit f5d0d8f

1 file changed

Lines changed: 48 additions & 5 deletions

File tree

tests/unit/test_uri.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,52 @@
2525
def test_valid_url():
2626
uri = URI("http://example.com")
2727
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()
2840

2941

3042
def test_invalid_url():
43+
# A bare token without any scheme/path separator is not a valid URI.
3144
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()
3374

3475

3576
def test_url_with_query_params():
@@ -131,10 +172,12 @@ def test_rocrate_uri_remote_valid():
131172

132173

133174
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)
138181

139182
# Test with an invalid remote URL
140183
uri = URI("https:///example.com")

0 commit comments

Comments
 (0)