|
| 1 | +import pytest |
| 2 | + |
| 3 | +from fsspec import AbstractFileSystem, filesystem, register_implementation, url_to_fs |
| 4 | +from fsspec.implementations.cached import ChainedFileSystem |
| 5 | + |
| 6 | + |
| 7 | +class MyChainedFS(ChainedFileSystem): |
| 8 | + protocol = "mychain" |
| 9 | + |
| 10 | + def __init__(self, target_protocol="", target_options=None, **kwargs): |
| 11 | + super().__init__(**kwargs) |
| 12 | + self.fs = filesystem(target_protocol, **target_options) |
| 13 | + |
| 14 | + |
| 15 | +class MyNonChainedFS(AbstractFileSystem): |
| 16 | + protocol = "mynonchain" |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture(scope="module") |
| 20 | +def register_fs(): |
| 21 | + register_implementation(MyChainedFS.protocol, MyChainedFS) |
| 22 | + register_implementation(MyNonChainedFS.protocol, MyNonChainedFS) |
| 23 | + yield |
| 24 | + |
| 25 | + |
| 26 | +def test_token_passthrough_to_chained(register_fs): |
| 27 | + # First, run a sanity check |
| 28 | + fs, rest = url_to_fs("mynonchain://path/to/file") |
| 29 | + assert isinstance(fs, MyNonChainedFS) |
| 30 | + assert fs.protocol == "mynonchain" |
| 31 | + assert rest == "path/to/file" |
| 32 | + |
| 33 | + # Now test that the chained FS works |
| 34 | + fs, rest = url_to_fs("mychain::mynonchain://path/to/file") |
| 35 | + assert isinstance(fs, MyChainedFS) |
| 36 | + assert fs.protocol == "mychain" |
| 37 | + assert rest == "path/to/file" |
| 38 | + assert isinstance(fs.fs, MyNonChainedFS) |
| 39 | + assert fs.fs.protocol == "mynonchain" |
0 commit comments