Skip to content

Commit

Permalink
Add test case for invalid last_updated_at
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Jan 5, 2025
1 parent 4385ef7 commit 28a45c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 14 additions & 10 deletions virtualizarr/tests/test_writers/test_icechunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@


@pytest.fixture(scope="function")
def icechunk_filestore(tmpdir) -> "IcechunkStore":
from icechunk import Repository, Storage
def icechunk_storage(tmpdir) -> "Storage":
from icechunk import Storage

return Storage.new_local_filesystem(str(tmpdir))

repo = Repository.create(storage=Storage.new_local_filesystem(str(tmpdir)))

@pytest.fixture(scope="function")
def icechunk_filestore(icechunk_storage: "Storage") -> "IcechunkStore":
from icechunk import Repository

repo = Repository.create(storage=icechunk_storage)
session = repo.writable_session("main")
return session.store

Expand Down Expand Up @@ -326,6 +333,10 @@ def test_checksum(
checksum_date = datetime.now(timezone.utc) + timedelta(seconds=1)
dataset_to_icechunk(vds, icechunk_filestore, last_updated_at=checksum_date)

# Fail if anything but None or a datetime is passed to last_updated_at
with pytest.raises(TypeError):
dataset_to_icechunk(vds, icechunk_filestore, last_updated_at="not a datetime")

root_group = group(store=icechunk_filestore)
pres_array = root_group["pres"]
assert isinstance(pres_array, Array)
Expand Down Expand Up @@ -391,13 +402,6 @@ def test_generate_chunk_key_append_axis_out_of_bounds():
generate_chunk_key(index, append_axis=append_axis, existing_num_chunks=1)


@pytest.fixture(scope="function")
def icechunk_storage(tmpdir) -> "Storage":
from icechunk import Storage

return Storage.new_local_filesystem(str(tmpdir))


def generate_chunk_manifest(
netcdf4_file: str,
shape: tuple[int, ...],
Expand Down
4 changes: 4 additions & 0 deletions virtualizarr/writers/icechunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def dataset_to_icechunk(

if not isinstance(store, IcechunkStore):
raise TypeError(f"expected type IcechunkStore, but got type {type(store)}")
elif not isinstance(last_updated_at, (type(None), datetime)):
raise TypeError(
f"expected type Optional[datetime], but got type {type(last_updated_at)}"
)

if store.read_only:
raise ValueError("supplied store is read-only")
Expand Down

0 comments on commit 28a45c5

Please sign in to comment.