Skip to content

Commit

Permalink
moved monthly check to test-file_download
Browse files Browse the repository at this point in the history
also moved the download calls to inside expectations so they are skipped on cran

#29
  • Loading branch information
rabutler-usbr committed Jan 2, 2020
1 parent 458eed4 commit cddf871
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
77 changes: 46 additions & 31 deletions tests/testthat/test-files_download.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# TODO: need to also skip all the downloads (get_prism_*) calls on CRAN.

dl_folder <- file.path(tempdir(), "prism")
setup({
Expand All @@ -13,17 +12,18 @@ cat("****************************************\n")
#teardown(unlink(dl_folder, recursive = TRUE))

# Normals ---------------
get_prism_normals("tmean", resolution = "4km", annual = TRUE)
get_prism_normals("tmax", resolution = "4km", mon = 1)
get_prism_normals("tmin", resolution = "4km", mon = 2)
get_prism_normals("tdmean", resolution = "4km", mon = 6)
get_prism_normals("vpdmin", resolution = "4km", mon = 12)
get_prism_normals("vpdmax", resolution = "4km", mon = 9)
get_prism_normals("ppt", resolution = "800m", mon = 11)

test_that("normals download", {
skip_on_cran()
#skip("skip normals")

get_prism_normals("tmean", resolution = "4km", annual = TRUE)
get_prism_normals("tmax", resolution = "4km", mon = 1)
get_prism_normals("tmin", resolution = "4km", mon = 2)
get_prism_normals("tdmean", resolution = "4km", mon = 6)
get_prism_normals("vpdmin", resolution = "4km", mon = 12)
get_prism_normals("vpdmax", resolution = "4km", mon = 9)
get_prism_normals("ppt", resolution = "800m", mon = 11)

expect_true(file.exists(
file.path(dl_folder, "PRISM_tmean_30yr_normal_4kmM2_annual_bil.zip")
))
Expand Down Expand Up @@ -75,18 +75,19 @@ test_that("normals download", {
})

# annual -----------------------
get_prism_annual("tmean", years = 2010)
get_prism_annual("tmax", years = 2011)
get_prism_annual("tmin", years = 2012)
get_prism_annual("tdmean", years = 1944)
get_prism_annual("vpdmin", years = 1982)
get_prism_annual("vpdmax", years = 1933)
get_prism_annual("ppt", years = 1999)


test_that("annuals download", {
skip_on_cran()
#skip("skip annual")

get_prism_annual("tmean", years = 2010)
get_prism_annual("tmax", years = 2011)
get_prism_annual("tmin", years = 2012)
get_prism_annual("tdmean", years = 1944)
get_prism_annual("vpdmin", years = 1982)
get_prism_annual("vpdmax", years = 1933)
get_prism_annual("ppt", years = 1999)

expect_true(file.exists(
file.path(dl_folder, "PRISM_tmean_stable_4kmM3_2010_bil.zip")
))
Expand Down Expand Up @@ -138,17 +139,19 @@ test_that("annuals download", {
})

# monthly ----------------------
get_prism_monthlys("tmean", years = 2010, mon = 1)
get_prism_monthlys("tmax", years = 1983, mon = 12)
get_prism_monthlys("tmin", years = 2015, mon = 9)
get_prism_monthlys("tdmean", years = 2000, mon = 3)
get_prism_monthlys("vpdmin", years = 2002, mon = 6)
get_prism_monthlys("vpdmax", years = 1970, mon = 1)
get_prism_monthlys("ppt", years = 1925, mon = 3)

test_that("monthlys download", {
skip_on_cran()
#skip("skip monthly")

get_prism_monthlys("tmean", years = 2010, mon = 1)
get_prism_monthlys("tmax", years = 1983, mon = 12)
get_prism_monthlys("tmin", years = 2015, mon = 9)
get_prism_monthlys("tdmean", years = 2000, mon = 3)
get_prism_monthlys("vpdmin", years = 2002, mon = 6)
get_prism_monthlys("vpdmax", years = 1970, mon = 1)
get_prism_monthlys("ppt", years = 1925, mon = 3)

expect_true(file.exists(
file.path(dl_folder, "PRISM_tmean_stable_4kmM3_201001_bil.zip")
))
Expand Down Expand Up @@ -197,20 +200,32 @@ test_that("monthlys download", {
expect_true(dir.exists(
file.path(dl_folder, "PRISM_ppt_stable_4kmM2_192503_bil")
))

# three consecutive --------------
# Download three months to make sure that the middle month is downloaded.
get_prism_monthlys(type = "tmean", mon = 2:4, year = 2014, keepZip = FALSE)
for (i in 2:4) {
expect_true(dir.exists(file.path(
dl_folder,
paste0("PRISM_tmean_stable_4kmM3_2014", prism:::mon_to_string(i), "_bil")
)))
}
})

# daily ------------------------
get_prism_dailys("tmean", dates = "1981-01-01")
get_prism_dailys("tmax", dates = "1985-02-20")
get_prism_dailys("tmin", dates = "1991-06-01")
get_prism_dailys("tdmean", dates = "1997-09-27")
get_prism_dailys("vpdmax", dates = "2006-12-31")
get_prism_dailys("vpdmin", dates = "2012-01-01")
get_prism_dailys("ppt", dates = "2015-11-05")

test_that("daily download", {
skip_on_cran()
#skip("skip daily")

get_prism_dailys("tmean", dates = "1981-01-01")
get_prism_dailys("tmax", dates = "1985-02-20")
get_prism_dailys("tmin", dates = "1991-06-01")
get_prism_dailys("tdmean", dates = "1997-09-27")
get_prism_dailys("vpdmax", dates = "2006-12-31")
get_prism_dailys("vpdmin", dates = "2012-01-01")
get_prism_dailys("ppt", dates = "2015-11-05")

expect_true(file.exists(
file.path(dl_folder, "PRISM_tmean_stable_4kmD2_19810101_bil.zip")
))
Expand Down
5 changes: 0 additions & 5 deletions tests/testthat/testdownloads.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
dates = NULL, keepZip = FALSE)

})
test_that("Monthly stable download", {
skip_on_cran()
# # Download three months to make sure that the middle month is downloaded.
get_prism_monthlys(type = "tmean", mon= 2:4, year = 2014, keepZip = FALSE)

})

test_that("Normals download properly", {
skip_on_cran()
Expand Down

0 comments on commit cddf871

Please sign in to comment.