Skip to content

Commit

Permalink
added 1 second sleep after all test files, see if travis builds still…
Browse files Browse the repository at this point in the history
… fail
  • Loading branch information
sckott committed Nov 8, 2016
1 parent 681e1fb commit ecfea17
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 99 deletions.
2 changes: 2 additions & 0 deletions R/extract_pdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' res_xpdf$data
#' }
extract_xpdf <- function(path){
.Deprecated(new = "crm_extract", package = "rcrossref", msg = "Removed - see cr_cn()")

path <- path.expand(path)
system2("pdftotext", shQuote(path))
newpath <- sub("\\.pdf", ".txt", path)
Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test_as.tdmurl.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ context("testing as.tdmurl")

test_that("as.tdmurl returns correct class", {
skip_on_cran()

a <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.xml", "xml")
b <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.pdf", "pdf")

expect_is(a, "tdmurl")
expect_is(a[[1]], "character")

Expand All @@ -15,21 +15,21 @@ test_that("as.tdmurl returns correct class", {

test_that("as.tdmurl dimensions are correct", {
skip_on_cran()

a <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.xml", "xml")
b <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.pdf", "pdf")

expect_equal(length(a), 1)
expect_equal(length(b), 1)
expect_equal(length(b[[1]]), 1)
})

test_that("as.tdmurl gives back right values", {
skip_on_cran()

a <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.xml", "xml")
b <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.pdf", "pdf")

expect_equal(attr(a, "type"), "xml")
expect_equal(attr(b, "type"), "pdf")
})
Expand All @@ -39,8 +39,10 @@ test_that("as.tdmurl fails correctly", {

a <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.xml", "xml")
b <- as.tdmurl("http://downloads.hindawi.com/journals/bmri/2014/201717.pdf", "pdf")

expect_error(as.tdmurl(), 'no applicable method for')
expect_error(as.tdmurl("3434"), 'argument "type" is missing, with no default')
expect_error(as.tdmurl("http://stuff", "bbb"), "'arg' should be one of")
})

Sys.sleep(1)
8 changes: 5 additions & 3 deletions tests/testthat/test_cr_agency.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ context("testing cr_agency")

test_that("cr_ageny returns correct class", {
skip_on_cran()

expect_is(cr_agency(dois = '10.1038/jid.2009.428'), "list")
expect_is(cr_agency(dois = c('10.13039/100000001','10.13039/100000015')), "list")
})

test_that("cr_ageny returns correct length", {
skip_on_cran()

expect_equal(length(cr_agency(dois = c('10.13039/100000001','10.13039/100000015'))), 2)
})

test_that("cr_ageny fails correctly", {
skip_on_cran()

library('httr')
expect_error(cr_agency(dois = cr_r(3), config=timeout(0.01)))
})

Sys.sleep(1)
10 changes: 6 additions & 4 deletions tests/testthat/test_cr_citation_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ context("testing cr_citation_count")

test_that("cr_citation_count returns", {
skip_on_cran()

a <- cr_citation_count(doi="10.1371/journal.pone.0042793")
b <- cr_citation_count(doi="10.1016/j.fbr.2012.01.001")

# correct classes
expect_is(a, "numeric")
expect_is(b, "numeric")

# correct length
expect_equal(length(a), 1)
expect_equal(length(b), 1)
})

test_that("cr_citation_count fails correctly", {
skip_on_cran()

library('httr')
expect_error(cr_citation_count(doi="10.1371/journal.pone.0042793", config=timeout(0.001)))
expect_equal(cr_citation_count("10.1371/journal.pone.004"), NA)
})

Sys.sleep(1)
16 changes: 9 additions & 7 deletions tests/testthat/test_cr_cn.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ context("testing cr_cn")

test_that("cr_cn returns", {
skip_on_cran()

b <- cr_cn(dois = "10.1126/science.169.3946.635", format = "citeproc-json")
c <- cr_cn("10.1126/science.169.3946.635", "rdf-xml")
d <- cr_cn("10.1126/science.169.3946.635", "crossref-xml")
e <- cr_cn("10.1126/science.169.3946.635", "bibentry")
#f <- cr_cn(dois = "10.1126/science.169.3946.635", format = "text", style = "apa")
g <- cr_cn("10.5604/20831862.1134311", "crossref-tdm")
h <- cr_cn("10.3233/ISU-150780", "onix-xml")

# correct classes
expect_is(b, "list")
expect_is(c, "xml_document")
Expand All @@ -19,28 +19,28 @@ test_that("cr_cn returns", {
#expect_is(f, "character")
expect_is(g, "xml_document")
expect_is(h, "xml_document")

# correct values
expect_match(b$`container-title`, "Science")
expect_match(unclass(e)[[1]]$year, "1970")
})

test_that("cr_cn fails correctly", {
skip_on_cran()

library('httr')
expect_error(cr_cn(dois="10.1126/science.169.3946.635", config=timeout(0.01)))
})

test_that("DOIs with no agency found still work, at least some do", {
skip_on_cran()

# throws warning
expect_warning(
cr_cn("10.1890/0012-9615(1999)069[0569:EDILSA]2.0.CO;2"),
"agency not found - proceeding with 'crossref'"
)

# but it is successful
expect_is(
suppressWarnings(cr_cn("10.1890/0012-9615(1999)069[0569:EDILSA]2.0.CO;2")),
Expand All @@ -50,7 +50,7 @@ test_that("DOIs with no agency found still work, at least some do", {

test_that("cr_cn checks if doi agency supports format", {
skip_on_cran()

expect_error(
cr_cn(dois = "10.3233/ISU-150780", format = "crossref-tdm"),
"not supported by the DOI registration agency: 'medra'"
Expand All @@ -64,3 +64,5 @@ test_that("cr_cn checks if doi agency supports format", {
"not supported by the DOI registration agency: 'crossref'"
)
})

Sys.sleep(1)
10 changes: 6 additions & 4 deletions tests/testthat/test_cr_ft_links.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ context("testing cr_ft_links")

test_that("cr_ft_links returns correct class", {
skip_on_cran()

a <- cr_ft_links(doi = "10.5555/515151", "pdf")
out <- cr_works(filter = c(has_full_text = TRUE), limit = 50)
dois <- out$data$DOI
b <- cr_ft_links("10.7554/elife.06200", "pdf")
d <- cr_ft_links("10.3897/phytokeys.52.5250", "all")

expect_is(a, "tdmurl")
expect_is(a[[1]], "character")

Expand All @@ -27,7 +27,7 @@ test_that("cr_ft_links returns correct class", {
expect_equal(length(d[[1]]), 1)

# gives back right values

expect_equal(attr(a, "type"), "pdf")
expect_equal(attr(b, "type"), "pdf")
expect_equal(attr(d[[2]], "type"), "xml")
Expand All @@ -37,7 +37,9 @@ test_that("cr_ft_links returns correct class", {

test_that("cr_ft_links fails correctly", {
skip_on_cran()

expect_error(cr_ft_links(), 'argument "doi" is missing')
expect_null(suppressWarnings(cr_ft_links(doi = "3434")))
})

Sys.sleep(1)
12 changes: 7 additions & 5 deletions tests/testthat/test_cr_ft_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ context("cr_ft_text")

test_that("cr_ft_text works: pdf", {
skip_on_cran()

links <- cr_ft_links("10.1155/mbd.1994.183", "all")
pdf_read <- cr_ft_text(links, "pdf", read = FALSE, verbose = FALSE)
pdf <- cr_ft_text(links, "pdf", verbose = FALSE)

#expect_is(xml1, "xml_document")
expect_is(pdf_read, "character")
expect_is(pdf, "xpdf_char")

#expect_equal(length(xml1), 2)
expect_equal(length(pdf_read), 1)
expect_equal(length(pdf), 2)
Expand All @@ -34,10 +34,12 @@ test_that("cr_ft_text works: pdf", {

test_that("cr_ft_text fails correctly", {
skip_on_cran()

expect_error(cr_ft_text(), 'argument "url" is missing')
expect_error(cr_ft_text("3434"), "a character vector argument expected")

links <- cr_ft_links("10.1155/mbd.1994.183", "all")
expect_error(cr_ft_text(links, type = "adfasf"), "'arg' should be one of")
})

Sys.sleep(1)
12 changes: 7 additions & 5 deletions tests/testthat/test_cr_funders.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ context("testing cr_funders")

test_that("cr_funders returns", {
skip_on_cran()

a <- suppressWarnings(cr_funders(dois=c('10.13039/100000001','10.13039/100000015')))
b <- suppressWarnings(cr_funders(dois='10.13039/100000001', works=TRUE, limit=5))

# correct clases
expect_is(suppressWarnings(cr_funders(query="NSF", limit=1)), "list")
expect_is(a, "list")
expect_is(a[[1]]$data, "data.frame")
expect_is(a[[1]]$descendants, "character")

expect_is(b, "list")
expect_is(b$data, "tbl_df")

Expand All @@ -23,8 +23,10 @@ test_that("cr_funders returns", {

test_that("cr_funders fails correctly", {
skip_on_cran()

library('httr')
expect_warning(cr_funders(dois='10.13039/100000001afasfasdf'),
expect_warning(cr_funders(dois='10.13039/100000001afasfasdf'),
"Resource not found")
})

Sys.sleep(1)
16 changes: 9 additions & 7 deletions tests/testthat/test_cr_journals.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ context("testing cr_journals")

test_that("cr_journals returns correct class", {
skip_on_cran()

a <- cr_journals()
expect_is(a, "list")
expect_is(a$data, "tbl_df")
Expand All @@ -11,37 +11,39 @@ test_that("cr_journals returns correct class", {

test_that("cr_journals paging works correctly", {
skip_on_cran()

expect_equal(NROW(cr_journals(issn = '1803-2427', works = TRUE, limit=5)$data), 5)
})

test_that("cr_journals metadata works correctly", {
skip_on_cran()

expect_equal(cr_journals(query="peerj", limit=4)$meta$items_per_page, 4)
})

test_that("cr_journals fails correctly", {
skip_on_cran()

library('httr')
expect_error(cr_journals(query="peerj", limit=4, config=timeout(0.001)))
})


test_that("cr_journals warns correctly", {
skip_on_cran()
expect_warning(cr_journals(issn = c('blblbl', '1932-6203')),

expect_warning(cr_journals(issn = c('blblbl', '1932-6203')),
regexp = "Resource not found", all = TRUE)
expect_equal(NROW(suppressWarnings(cr_journals(issn = c('blblbl', '1932-6203')))), 1)
expect_is(suppressWarnings(cr_journals(issn = c('blblbl', '1932-6203'))), "tbl_df")
})

test_that("ISSNs that used to fail badly - should fail better now", {
skip_on_cran()

expect_warning(cr_journals("0413-6597"), "Resource not found")
expect_warning(cr_journals(c('1932-6203', '1803-2427', "0413-6597")), "Resource not found")
expect_equal(NROW(suppressMessages(suppressWarnings(cr_journals(c('1932-6203', '1803-2427', "0413-6597"))))), 2)
})

Sys.sleep(1)
10 changes: 6 additions & 4 deletions tests/testthat/test_cr_licenses.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ context("testing cr_licenses")

test_that("cr_licenses returns", {
skip_on_cran()

a <- cr_licenses()
b <- cr_licenses(query = 'elsevier')

# correct classes
expect_is(a, "list")
expect_is(a$meta, "data.frame")
expect_is(a$data, "data.frame")
expect_is(a$data$URL, "character")

expect_is(b, "list")
expect_is(b$meta, "data.frame")
expect_is(b$data, "data.frame")
Expand All @@ -27,9 +27,11 @@ test_that("cr_licenses returns", {

test_that("cr_licenses fails correctly", {
skip_on_cran()

library('httr')
expect_error(cr_licenses(config=timeout(0.01)))
expect_equal(NROW(cr_licenses(query = "adfaaf")$data), 0)
expect_error(cr_licenses(filter=''))
})

Sys.sleep(1)
Loading

0 comments on commit ecfea17

Please sign in to comment.