Skip to content

Commit

Permalink
Implement testthat infrastructure and apply to download_zenodo()
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdh committed Nov 20, 2023
1 parent 5b1b6c8 commit 4401c5b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ Suggests:
readxl,
remotes,
rmarkdown,
testthat (>= 3.0.0),
tidyverse,
tools,
units,
utils,
withr
VignetteBuilder: knitr
Config/testthat/edition: 3
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(n2khab)

test_check("n2khab")
54 changes: 54 additions & 0 deletions tests/testthat/_snaps/zenodo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# download_zenodo() works for a single-file record

Code
download_zenodo(doi = "10.5281/zenodo.3784149", path = zenodo_dir)
Message
Will download 1 file (total size: 32.5 KiB) from https://doi.org/10.5281/zenodo.3784149 (Distribution of the Natura 2000 habitat type 7220 (Cratoneurion) in Flanders and Brussels Capital Region, Belgium (version 2020); version: habitatsprings_2020v2)
Verifying file integrity...
habitatsprings.geojson was downloaded and its integrity verified (md5sum: 64c3db07d17274da047b3962aab28e80)

# download_zenodo() works for a GitHub code record

Code
download_zenodo(doi = "10.5281/zenodo.7335805", path = zenodo_dir)
Message
Will download 1 file (total size: 236.7 KiB) from https://doi.org/10.5281/zenodo.7335805 (R package n2khab: providing preprocessed reference data for Flemish Natura 2000 habitat analyses; version: 0.8.0)
Verifying file integrity...
n2khab-v0.8.0.zip was downloaded and its integrity verified (md5sum: 25fb33360d257c085bce567da8f6a2cb)

# download_zenodo() works for a multi-file record

Code
download_zenodo(doi = "10.5281/zenodo.4420858", path = zenodo_dir)
Message
Will download 4 files (total size: 534.5 KiB) from https://doi.org/10.5281/zenodo.4420858 (Redistribution of the Natura 2000 habitat map of Flanders, partim habitat type 3260 (version 1.7); version: habitatstreams_v1.7)
Verifying file integrity...
habitatstreams.dbf was downloaded and its integrity verified (md5sum: f66ddddacc9511133cc02d8c1960a917)
habitatstreams.shx was downloaded and its integrity verified (md5sum: e7725c8267ed671f3e5f09c5fcc68bff)
habitatstreams.shp was downloaded and its integrity verified (md5sum: 5c94b58c9dc7809c4eeeaf660aa3323c)
habitatstreams.prj was downloaded and its integrity verified (md5sum: f881f61a6c07741b58cb618d8bbb0b99)

# download_zenodo() can work sequentially for a multi-file record

Code
download_zenodo(doi = "10.5281/zenodo.4420858", path = zenodo_dir, parallel = FALSE)
Message
Will download 4 files (total size: 534.5 KiB) from https://doi.org/10.5281/zenodo.4420858 (Redistribution of the Natura 2000 habitat map of Flanders, partim habitat type 3260 (version 1.7); version: habitatstreams_v1.7)
Verifying file integrity...
habitatstreams.dbf was downloaded and its integrity verified (md5sum: f66ddddacc9511133cc02d8c1960a917)
habitatstreams.shx was downloaded and its integrity verified (md5sum: e7725c8267ed671f3e5f09c5fcc68bff)
habitatstreams.shp was downloaded and its integrity verified (md5sum: 5c94b58c9dc7809c4eeeaf660aa3323c)
habitatstreams.prj was downloaded and its integrity verified (md5sum: f881f61a6c07741b58cb618d8bbb0b99)

43 changes: 43 additions & 0 deletions tests/testthat/test-zenodo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
test_that("download_zenodo() works for a single-file record", {
zenodo_dir <- tempfile()
withr::local_file(zenodo_dir)
dir.create(zenodo_dir)
expect_snapshot(
download_zenodo(doi = "10.5281/zenodo.3784149", path = zenodo_dir)
)
})

test_that("download_zenodo() works for a GitHub code record", {
zenodo_dir <- tempfile()
withr::local_file(zenodo_dir)
dir.create(zenodo_dir)
expect_snapshot(
download_zenodo(doi = "10.5281/zenodo.7335805", path = zenodo_dir)
)
})

test_that("download_zenodo() works for a multi-file record", {
zenodo_dir <- tempfile()
withr::local_file(zenodo_dir)
dir.create(zenodo_dir)
expect_snapshot(
download_zenodo(
doi = "10.5281/zenodo.4420858",
path = zenodo_dir
)
)
})

test_that("download_zenodo() can work sequentially for a multi-file record", {
zenodo_dir <- tempfile()
withr::local_file(zenodo_dir)
dir.create(zenodo_dir)
expect_snapshot(
download_zenodo(
doi = "10.5281/zenodo.4420858",
path = zenodo_dir,
parallel = FALSE
)
)
})

0 comments on commit 4401c5b

Please sign in to comment.