Skip to content

Commit 4e8a925

Browse files
committed
fixup
1 parent 542c3ec commit 4e8a925

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/zarr/abc/store_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __post_init__(self) -> None:
4747

4848
if not self.scheme and not self.adapter:
4949
raise ZEP8URLError("URL segment must have either scheme or adapter")
50-
if self.adapter and not re.match(r"^[a-zA-Z0-9][a-zA-Z0-9_-]*$", self.adapter):
50+
if self.adapter and not re.match(r"^[a-zA-Z][a-zA-Z0-9_+-]*$", self.adapter):
5151
raise ZEP8URLError(f"Invalid adapter name: {self.adapter}")
5252

5353

tests/test_store/test_zep8.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ async def test_url_segment_validation_errors() -> None:
873873
with pytest.raises(ZEP8URLError, match="Invalid adapter name"):
874874
URLSegment(adapter="invalid@name")
875875

876+
# Test invalid adapter name (starts with number)
877+
with pytest.raises(ZEP8URLError, match="Invalid adapter name"):
878+
URLSegment(adapter="1abc")
879+
876880

877881
async def test_memory_adapter_error_conditions() -> None:
878882
"""Test error conditions in MemoryAdapter."""
@@ -1073,7 +1077,17 @@ def test_url_segment_edge_cases() -> None:
10731077
"""Test URLSegment edge cases and validation."""
10741078

10751079
# Test adapter name validation with various valid names
1076-
valid_names = ["zip", "memory", "s3", "test123", "valid_name", "valid-name", "z", "Z", "1abc"]
1080+
valid_names = [
1081+
"zip",
1082+
"memory",
1083+
"s3",
1084+
"test123",
1085+
"valid_name",
1086+
"valid-name",
1087+
"z",
1088+
"Z",
1089+
"s3+http",
1090+
]
10771091
for name in valid_names:
10781092
segment = URLSegment(adapter=name)
10791093
assert segment.adapter == name
@@ -1950,14 +1964,14 @@ async def test_s3_adapter_error_conditions() -> None:
19501964
# Skip if s3fs is not available
19511965
pytest.importorskip("s3fs", reason="s3fs not available")
19521966

1953-
# Test invalid URL parsing
1967+
# Test unsupported URL format
19541968
segment = URLSegment(adapter="s3")
1955-
with pytest.raises(ValueError, match="Invalid S3 URL format"):
1956-
await S3Adapter.from_url_segment(segment, "s3://")
1969+
with pytest.raises(ValueError, match="Unsupported S3 URL format"):
1970+
await S3Adapter.from_url_segment(segment, "invalid://not-s3")
19571971

1958-
# Test empty bucket
1959-
with pytest.raises(ValueError, match="Invalid S3 URL format"):
1960-
await S3Adapter.from_url_segment(segment, "s3:///key")
1972+
# Test invalid protocol
1973+
with pytest.raises(ValueError, match="Unsupported S3 URL format"):
1974+
await S3Adapter.from_url_segment(segment, "gs://bucket/path")
19611975

19621976

19631977
async def test_s3_http_adapter_url_parsing() -> None:
@@ -1967,7 +1981,7 @@ async def test_s3_http_adapter_url_parsing() -> None:
19671981
# Skip if s3fs is not available
19681982
pytest.importorskip("s3fs", reason="s3fs not available")
19691983

1970-
# Test S3HttpAdapter
1984+
# Test S3HttpAdapter URL parsing (now that + is allowed in adapter names)
19711985
segment = URLSegment(adapter="s3+http")
19721986
# This should try to parse the custom endpoint
19731987
with contextlib.suppress(ImportError):
@@ -1980,8 +1994,9 @@ async def test_s3_http_adapter_url_parsing() -> None:
19801994
await S3HttpsAdapter.from_url_segment(segment, "s3+https://custom.endpoint.com/bucket/key")
19811995

19821996
# Test error condition - invalid custom endpoint URL
1983-
with pytest.raises(ValueError, match="Invalid S3 custom endpoint URL format"):
1984-
await S3HttpAdapter.from_url_segment(segment, "s3+http://")
1997+
http_segment = URLSegment(adapter="s3+http")
1998+
with pytest.raises(ValueError, match="Unsupported S3 URL format"):
1999+
await S3HttpAdapter.from_url_segment(http_segment, "invalid://not-s3-format")
19852000

19862001

19872002
async def test_gc_adapter_missing_coverage() -> None:

0 commit comments

Comments
 (0)