|
25 | 25 | dandiset_identifier_regex,
|
26 | 26 | dandiset_metadata_file,
|
27 | 27 | )
|
28 |
| -from ..dandiapi import DandiAPIClient, RemoteAsset, RemoteZarrAsset, Version |
| 28 | +from ..dandiapi import ( |
| 29 | + DandiAPIClient, |
| 30 | + RemoteAsset, |
| 31 | + RemoteBlobAsset, |
| 32 | + RemoteZarrAsset, |
| 33 | + Version, |
| 34 | +) |
29 | 35 | from ..download import download
|
30 | 36 | from ..exceptions import NotFoundError, SchemaVersionError
|
31 | 37 | from ..files import GenericAsset, dandi_file
|
@@ -745,3 +751,21 @@ def test_rename_type_mismatch(text_dandiset: SampleDandiset, dest: str) -> None:
|
745 | 751 | assert asset1a.get_raw_metadata()["path"] == "file.txt"
|
746 | 752 | with pytest.raises(NotFoundError):
|
747 | 753 | text_dandiset.dandiset.get_asset_by_path(dest)
|
| 754 | + |
| 755 | + |
| 756 | +def test_asset_as_readable_open(new_dandiset: SampleDandiset, tmp_path: Path) -> None: |
| 757 | + p = tmp_path / "foo.txt" |
| 758 | + # Write bytes so that the LF doesn't get converted on Windows: |
| 759 | + p.write_bytes(b"This is test text.\n") |
| 760 | + d = new_dandiset.dandiset |
| 761 | + d.upload_raw_asset(p, {"path": "foo.txt"}) |
| 762 | + (asset,) = d.get_assets() |
| 763 | + assert isinstance(asset, RemoteBlobAsset) |
| 764 | + # The purpose of this test is to check that RemoteReadableAsset.open() |
| 765 | + # returns a filehandle that can immediately be used, so don't use a `with` |
| 766 | + # block here, as that opens fsspec file objects. |
| 767 | + fp = asset.as_readable().open() |
| 768 | + try: |
| 769 | + assert fp.read() == b"This is test text.\n" |
| 770 | + finally: |
| 771 | + fp.close() |
0 commit comments