Skip to content

Commit

Permalink
clean up after sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
dblodgett-usgs committed Dec 20, 2024
1 parent 26cb66a commit 9d25077
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
7 changes: 6 additions & 1 deletion tests/testthat/test-compat.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
library(pizzarr)

sample_dir <- tools::R_user_dir("pizzarr")
clean <- !dir.exists(sample_dir)

test_that("Can open Zarr group using convenience function", {

root <- pizzarr_sample(file.path("fixtures", "v2", "data.zarr"))
Expand Down Expand Up @@ -513,4 +516,6 @@ test_that("Can create 0-element 2D array", {
expect_equal(is.character(sel$data), TRUE)
expect_equal(length(sel$data), 0)
expect_equal(dim(sel$data), c(0, 0))
})
})

if(clean) unlink(sample_dir, recursive = TRUE)
5 changes: 5 additions & 0 deletions tests/testthat/test-get.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
library(pizzarr)

sample_dir <- tools::R_user_dir("pizzarr")
clean <- !dir.exists(sample_dir)

test_that("get_basic_selection_zd", {
# Reference: https://github.com/zarr-developers/zarr-python/blob/5dd4a0e6cdc04c6413e14f57f61d389972ea937c/zarr/tests/test_indexing.py#L70
a <- as_scalar(42)
Expand Down Expand Up @@ -270,3 +273,5 @@ test_that("Can read 2D string array", {
expected_arr <- t(array(data = c(row1, row2, row3, row4, row5), dim = c(10, 5)))
expect_equal(expected_arr, data)
})

if(clean) unlink(sample_dir, recursive = TRUE)
7 changes: 6 additions & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
library(pizzarr)

sample_dir <- tools::R_user_dir("pizzarr")
clean <- !dir.exists(sample_dir)

test_that("demo data", {

demo_data <- pizzarr_sample()
Expand Down Expand Up @@ -215,4 +218,6 @@ test_that("NaN in json", {
expect_equal(check, list(name = NULL))

expect_warning(try_fromJSON("borked", "test warning"), "test warning")
})
})

if(clean) unlink(sample_dir, recursive = TRUE)
5 changes: 5 additions & 0 deletions vignettes/basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ vignette: >
comment = "#>",
out.width = "100%"
)
sample_dir <- tools::R_user_dir("pizzarr")
clean <- !dir.exists(sample_dir)
```

## Load the package
Expand Down Expand Up @@ -123,3 +125,6 @@ class(a)
a$get_attrs()$to_list()
```
```{r, include=FALSE}
if(clean) unlink(sample_dir, recursive = TRUE)
```
6 changes: 6 additions & 0 deletions vignettes/parallel.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ vignette: >
out.width = "100%"
)
library(pizzarr)
sample_dir <- tools::R_user_dir("pizzarr")
clean <- !dir.exists(sample_dir)
```

By default, reads and writes are performed sequentially (i.e., not in parallel).
Expand Down Expand Up @@ -138,4 +140,8 @@ To re-enable, run:

```{r}
pbapply::pboptions(type = "timer")
```

```{r, include=FALSE}
if(clean) unlink(sample_dir, recursive = TRUE)
```

0 comments on commit 9d25077

Please sign in to comment.