Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@

Anything that calls NCBI goes through net() or skip_without_ncbi(), so a
bad day at NCBI skips instead of failing the build, while a real bug still
fails. See tests/testthat/helper-ncbi.R. -->
fails. See tests/testthat/helper-ncbi.R. A test file that calls NCBI also
starts with skip_on_cran(), so CRAN and r-universe run only the tests
that need no network. -->
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
httr (>= 0.5),
jsonlite (>= 0.9)
Suggests:
testthat,
testthat (>= 3.2.3),
knitr,
rmarkdown
URL: https://docs.ropensci.org/rentrez/, https://github.com/ropensci/rentrez/
Expand Down
13 changes: 5 additions & 8 deletions tests/test-all.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
library("testthat")

#All of the tests rely on the API existing and behaving as documented. However,
#the API occasionally falls over or stops working which lets to errors on CRAN.
#Because we use travis CI we will hear about any test failures as soon as they
#happen. So, let's skill all tests on CRAN:

if(identical(Sys.getenv("NOT_CRAN"), "true")){
test_check("rentrez")
}
#Most test files call the live NCBI API and start with skip_on_cran(), so CRAN
#and r-universe, which leave NOT_CRAN unset, run only the tests that need no
#network. devtools::check() and the r-lib GitHub Actions set NOT_CRAN=true and
#run the whole suite (#221).
test_check("rentrez")
1 change: 1 addition & 0 deletions tests/testthat/test_citmatch.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("Cite matching")
skip_on_cran()
test_that("Citation matching works",{
ex_cites <- c("proc natl acad sci u s a|1991|88|3248|mann bj|test1|",
"science|1987|235|182|palmenberg ac|test2|")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_docs.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# suite. Note, the final example of the README makes a lot calls to NCBI, so is
# not included here
context("documentation")
skip_on_cran()

test_that("The pubmed example in the docs works", {
hox_paper <- net(entrez_search(db="pubmed", term="10.1038/nature08789[doi]"))
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test_errors.r
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,10 @@ test_that("the parse gate turns away rettypes that are not XML", {
expect_false(rentrez:::is_xml_record(rt, ""))
}
})

# NCBI serves version 1.0 summaries only as XML, so entrez_summary() refuses a
# json request for one before it sends anything. No network.
test_that("version 1.0 summaries cannot be requested as json", {
expect_error(entrez_summary("pubmed", id = 1:10, version = "1.0", retmode = "json"),
"only available as xml")
})
1 change: 1 addition & 0 deletions tests/testthat/test_fetch.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("fetching records")
skip_on_cran()


pop_ids = c("307082412", "307075396", "307075338", "307075274")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_httr.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("httr option passing")
skip_on_cran()
#most config options don't produce capture-able output, so instead
# we will test if we raise an error when we us a non-existant proxy to
# connect to the internet
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_httr_post.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("POST (the HTTP verb)")
skip_on_cran()

#setup (guarded so transient NCBI problems skip rather than abort the file)
ncbi_ok <- tryCatch({
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_info.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("einfo functions")
skip_on_cran()

#setup (guarded so transient NCBI problems skip rather than abort the file)
ncbi_ok <- tryCatch({
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_link.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("elink")
skip_on_cran()

#setup (guarded so transient NCBI problems skip rather than abort the file)
message("(this may take some time, have to download many records)")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_link_byid.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ context("elink by_id")
# In by_id mode the result should always be a list (one elink per id), even for
# a single id, and the call should not emit a spurious "invalid id" warning.
test_that("by_id=TRUE returns a one-element list with no spurious warning", {
skip_on_cran()
#only the call is wrapped. A testthat failure is an error condition too, so
#an expectation inside this tryCatch would be reported as a skip instead.
seen <- NULL
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_net.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("Network")
skip_on_cran()
test_that("The NCBI is contactable from this comptuter /",{
response <- net(httr::GET("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"))
skip_if(response$status_code >= 400, "NCBI returned an error status")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_parse.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("result-parsers")
skip_on_cran()

#setup (guarded so transient NCBI problems skip rather than abort the file)
ncbi_ok <- tryCatch({
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_post.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("entrez_post")
skip_on_cran()

prot_ids = c(15718680,157427902)

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_query.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("query")
skip_on_cran()
test_that("Query building functions work", {

setup <- tryCatch({
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_search.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("search")
skip_on_cran()

#setup (guarded so transient NCBI problems skip rather than abort the file)
ncbi_ok <- tryCatch({
Expand Down
7 changes: 1 addition & 6 deletions tests/testthat/test_summary.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("fetching and parsing summary recs")
skip_on_cran()

fake_ids <- sample(1e5, 501)
pop_ids = c("307082412", "307075396", "307075338", "307075274")
Expand Down Expand Up @@ -66,12 +67,6 @@ test_that("JSON and XML objects are similar", {
})


test_that("Error whent tring to fetch 1.0 summaries as json", {
expect_error(
entrez_summary("pubmed", id = fake_ids[1:10], version="1.0", retmode="json")
)
})

test_that("We can print summary records", {
skip_without_ncbi(ncbi_ok)
expect_output(print(pop_summ_json), "List of 4 esummary records")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_webenv.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("WebEnv")
skip_on_cran()
test_that("Searches using WebEnv features work", {
#setup
web_env_search <- net(entrez_search(db="nuccore",
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_zz_reachable.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
context("live API reachable")
skip_on_cran()

# The rest of the suite skips its tests when NCBI is unavailable. That keeps a
# bad day at NCBI from failing the build, but it also means a run in which every
Expand Down
Loading