|
| 1 | +zs <- file.path("extdata", "blobs.zarr") |
| 2 | +zs <- system.file(zs, package="spatialdataR") |
| 3 | +sd <- readSpatialData(zs) |
| 4 | + |
| 5 | +test_that("path,image", { |
| 6 | + x <- path(image(sd)) |
| 7 | + expect_length(x, 1) |
| 8 | + expect_is(x, "character") |
| 9 | + expect_true(file.info(x)$isdir) |
| 10 | + |
| 11 | + x <- path(SpatialDataImage()) |
| 12 | + expect_length(x, 1) |
| 13 | + expect_true(is.na(x)) |
| 14 | + expect_is(x, "character") |
| 15 | +}) |
| 16 | + |
| 17 | +test_that("path,label", { |
| 18 | + x <- path(label(sd)) |
| 19 | + expect_length(x, 1) |
| 20 | + expect_is(x, "character") |
| 21 | + expect_true(file.info(x)$isdir) |
| 22 | + |
| 23 | + x <- path(SpatialDataLabel()) |
| 24 | + expect_length(x, 1) |
| 25 | + expect_true(is.na(x)) |
| 26 | + expect_is(x, "character") |
| 27 | +}) |
| 28 | + |
| 29 | +test_that("path,shape", { |
| 30 | + x <- path(shape(sd)) |
| 31 | + expect_length(x, 1) |
| 32 | + expect_is(x, "character") |
| 33 | + expect_true(file.info(x)$isdir) |
| 34 | + expect_true(endsWith(x, ".parquet")) |
| 35 | + |
| 36 | + x <- path(SpatialDataShape()) |
| 37 | + expect_length(x, 1) |
| 38 | + expect_true(is.na(x)) |
| 39 | + expect_is(x, "character") |
| 40 | +}) |
| 41 | + |
| 42 | +test_that("path,point", { |
| 43 | + x <- path(point(sd)) |
| 44 | + expect_length(x, 1) |
| 45 | + expect_is(x, "character") |
| 46 | + expect_true(file.info(x)$isdir) |
| 47 | + expect_true(endsWith(x, ".parquet")) |
| 48 | + |
| 49 | + x <- path(SpatialDataPoint()) |
| 50 | + expect_length(x, 1) |
| 51 | + expect_true(is.na(x)) |
| 52 | + expect_is(x, "character") |
| 53 | +}) |
| 54 | + |
| 55 | +test_that("path,table", { |
| 56 | + x <- path(table(sd)) |
| 57 | + expect_length(x, 1) |
| 58 | + expect_is(x, "character") |
| 59 | + expect_true(file.info(x)$isdir) |
| 60 | + |
| 61 | + x <- path(SpatialDataPoint()) |
| 62 | + expect_length(x, 1) |
| 63 | + expect_true(is.na(x)) |
| 64 | + expect_is(x, "character") |
| 65 | +}) |
| 66 | + |
| 67 | +test_that("path,sdata", { |
| 68 | + ls <- rownames(sd) |
| 69 | + es <- unlist(colnames(sd)) |
| 70 | + ne <- length(es) |
| 71 | + |
| 72 | + x <- path(sd, simplify=TRUE) |
| 73 | + expect_is(x, "data.frame") |
| 74 | + expect_equal(ncol(x), 3) |
| 75 | + expect_equal(nrow(x), ne) |
| 76 | + for (. in seq_along(x)) |
| 77 | + expect_is(x[[.]], "character") |
| 78 | + expect_all_true(x[[1]] %in% ls) |
| 79 | + expect_all_true(x[[2]] %in% es) |
| 80 | + expect_all_true(file.exists(x[[3]])) |
| 81 | + |
| 82 | + y <- sd |
| 83 | + label(y, 2) <- SpatialDataLabel() |
| 84 | + y <- path(y, simplify=TRUE) |
| 85 | + i <- y[[1]] == "labels" & y[[2]] == labelNames(sd)[2] |
| 86 | + expect_identical(i, is.na(y[[3]])) |
| 87 | + y[[3]][i] <- x[[3]][i] |
| 88 | + expect_identical(x, y) |
| 89 | + |
| 90 | + x <- path(sd, simplify=FALSE) |
| 91 | + expect_is(x, "list") |
| 92 | + expect_length(unlist(x), ne) |
| 93 | + expect_equal(names(x), ls) |
| 94 | + for (l in names(x)) { |
| 95 | + expect_length(x[[l]], length(sd[[l]])) |
| 96 | + expect_equal(names(x[[l]]), names(sd[[l]])) |
| 97 | + for (e in names(x[[l]])) { |
| 98 | + y <- x[[l]][[e]] |
| 99 | + expect_length(y, 1) |
| 100 | + expect_is(y, "character") |
| 101 | + expect_true(file.exists(y)) |
| 102 | + expect_equal(y, path(sd[[l]][[e]])) |
| 103 | + } |
| 104 | + } |
| 105 | +}) |
0 commit comments