Skip to content

Commit 096845c

Browse files
committed
fix+test: register check types
1 parent 9e423f5 commit 096845c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

obstore/python/obstore/fsspec.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ def register(protocol: str | Iterable[str], *, asynchronous: bool = False) -> No
493493
- This avoids modifying the original AsyncFsspecStore class.
494494
495495
"""
496+
if not protocol:
497+
raise ValueError(
498+
"Protocol must be a non-empty string or list",
499+
)
496500
if isinstance(protocol, str):
497501
_register(protocol, asynchronous=asynchronous)
498502
return
@@ -502,6 +506,14 @@ def register(protocol: str | Iterable[str], *, asynchronous: bool = False) -> No
502506

503507

504508
def _register(protocol: str, *, asynchronous: bool) -> None:
509+
if not protocol:
510+
raise ValueError(
511+
"Protocol must be a non-empty string",
512+
)
513+
if not isinstance(protocol, str):
514+
err_msg = f"Protocol must be a string, got {type(protocol).__name__}"
515+
raise TypeError(err_msg)
516+
505517
fsspec.register_implementation(
506518
protocol,
507519
type(

tests/test_fsspec.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,28 @@ def test_register_invalid_types():
6969
"""Test that register rejects invalid input types."""
7070
with pytest.raises(
7171
TypeError,
72-
match="Protocol must be a string or a list of strings",
72+
match="'int' object is not iterable",
7373
):
74-
register(123) # Not a string or list
74+
register(123)
7575

76-
with pytest.raises(TypeError, match="All protocols in the list must be strings"):
76+
with pytest.raises(TypeError, match="Protocol must be a string, got int"):
7777
register(["test", 42]) # List contains a non-string
7878

7979
with pytest.raises(
8080
ValueError,
81-
match="Protocol names in the list must be non-empty strings",
81+
match="Protocol must be a non-empty string",
8282
):
8383
register(["test1", ""]) # List contains a non-string
8484

8585
with pytest.raises(
86-
TypeError,
87-
match="Protocol must be a string or a list of strings",
86+
ValueError,
87+
match="Protocol must be a non-empty string or list",
8888
):
8989
register(None) # None is invalid
9090

9191
with pytest.raises(
9292
ValueError,
93-
match="Protocol must be a non-empty string or a list of non-empty strings",
93+
match="Protocol must be a non-empty string or list",
9494
):
9595
register([]) # Empty list is invalid
9696

0 commit comments

Comments
 (0)