Skip to content

Commit

Permalink
init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarty committed Apr 19, 2024
1 parent 486555a commit 643f5fc
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 8 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Imports:
stringr,
httr
Suggests:
geodata,
ggplot2,
knitr
geodata,
ggplot2,
knitr,
testthat (>= 3.0.0)
Config/testthat/edition: 3
10 changes: 5 additions & 5 deletions R/blackmarbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,11 @@ bm_raster <- function(roi_sf,
stop("interpol_na ignored. Interpolation only occurs when output_location_type = 'memory'")
}

if(class(roi_sf)[1] == "SpatVector") roi_sf <- roi_sf %>% st_as_sf()
if(!("sf" %in% class(roi_sf))){
stop("roi must be an sf object")
}

# Assign interpolation variables ---------------------------------------------
if(interpol_na == T){
if(!exists("method")) method <- "linear"
Expand Down Expand Up @@ -1126,11 +1131,6 @@ bm_raster_i <- function(roi_sf,
quiet,
temp_dir){

# Checks ---------------------------------------------------------------------
if(!("sf" %in% class(roi_sf))){
stop("roi must be an sf object")
}

# Black marble grid ----------------------------------------------------------
bm_tiles_sf <- read_sf("https://raw.githubusercontent.com/worldbank/blackmarbler/main/data/blackmarbletiles.geojson")

Expand Down
2 changes: 2 additions & 0 deletions readme_figures/build_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if(F){
pkgdown::build_site_github_pages()
#usethis::use_pkgdown_github_pages()

usethis::use_testthat(3)

usethis::use_pkgdown()
usethis::use_github_pages()
usethis::use_pkgdown_github_pages() #####
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(blackmarbler)

test_check("blackmarbler")
80 changes: 80 additions & 0 deletions tests/testthat/test-bm_raster.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
test_that("Query VNP46A1", {

# Define bearer token
bearer <- Sys.getenv("BEARER_NASA_TOKEN")

# sf polygon of Switzerland (covers 2 black marble tiles)
roi_sf <- geodata::gadm(country = "CHE", level = 0, path = tempdir())

# Daily data
r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A1",
date = "2021-10-03",
bearer = bearer)

expect_true(class(r) == "SpatRaster",
info = "r is not a SpatRaster object"
)

})

test_that("Query VNP46A2", {

# Define bearer token
bearer <- Sys.getenv("BEARER_NASA_TOKEN")

# sf polygon of Switzerland (covers 2 black marble tiles)
roi_sf <- geodata::gadm(country = "CHE", level = 0, path = tempdir())

# Daily data
r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A2",
date = "2021-10-03",
bearer = bearer)

expect_true(class(r) == "SpatRaster",
info = "r is not a SpatRaster object"
)

})

test_that("Query VNP46A3", {

# Define bearer token
bearer <- Sys.getenv("BEARER_NASA_TOKEN")

# sf polygon of Switzerland (covers 2 black marble tiles)
roi_sf <- geodata::gadm(country = "CHE", level = 0, path = tempdir())

# Daily data
r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A3",
date = "2021-10",
bearer = bearer)

expect_true(class(r) == "SpatRaster",
info = "r is not a SpatRaster object"
)

})

test_that("Query VNP46A4", {

# Define bearer token
bearer <- Sys.getenv("BEARER_NASA_TOKEN")

# sf polygon of Switzerland (covers 2 black marble tiles)
roi_sf <- geodata::gadm(country = "CHE", level = 0, path = tempdir())

# Daily data
r <- bm_raster(roi_sf = roi_sf,
product_id = "VNP46A3",
date = 2021,
bearer = bearer)

expect_true(class(r) == "SpatRaster",
info = "r is not a SpatRaster object"
)

})

0 comments on commit 643f5fc

Please sign in to comment.