Skip to content

Commit

Permalink
Support attrs on empty store
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed May 7, 2024
1 parent 796018a commit b099b98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Attributes <- R6::R6Class("Attributes",
cached_aslist = NULL,

get_nosync = function() {

}
),
public = list(
Expand Down Expand Up @@ -44,7 +44,15 @@ Attributes <- R6::R6Class("Attributes",
self$synchronizer <- synchronizer
},
to_list = function() {
return(self$store$metadata_class$decode_metadata(self$store$get_item(self$key)))
attrs_list <- tryCatch({
return(self$store$metadata_class$decode_metadata(self$store$get_item(self$key)))
}, error = function(cond) {
if(is_key_error(cond)) {
return(obj_list())
}
stop(cond)
})
return(attrs_list)
},
refresh = function() {
# TODO
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-attrs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
library(pizzarr)

test_that("Can get attributes for empty store (without throwing a KeyError)", {
store <- MemoryStore$new()
g <- zarr_open_group(store)

expect_equal(g$get_attrs()$to_list(), obj_list())
})

0 comments on commit b099b98

Please sign in to comment.