Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup #136

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion tests/testthat/tests-dataset_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ test_that("check versions format", {
ds_index <- which(sapply(contents, function(x) x$identifier) == "FK2/HXJVJU")
actual <- dataset_versions(contents[[ds_index]])

expect_length(actual[[1]], 17L)
mtmorgan marked this conversation as resolved.
Show resolved Hide resolved
expected_names <- c(
"citationDate", "createTime", "datasetId", "datasetPersistentId",
"fileAccessRequest", "files", "id", "lastUpdateTime", "latestVersionPublishingState",
"license", "metadataBlocks", "publicationDate", "releaseTime",
"storageIdentifier", "UNF", "versionMinorNumber", "versionNumber",
"versionState")
expect_setequal(names(actual[[1]]), expected_names)
expect_s3_class(actual[[2]], "dataverse_dataset_version")
})
12 changes: 9 additions & 3 deletions tests/testthat/tests-get_dataframe-dataframe-basketball.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ test_that("roster-by-name", {
actual <-
get_dataframe_by_name(
filename = expected_ds$roster$label , # A value like "roster-bulls-1996.tab",
dataset = dirname(expected_ds$roster$dataFile$persistentId)#, # A value like "doi:10.70122/FK2/HXJVJU",
dataset = dirname(expected_ds$roster$dataFile$persistentId),#, # A value like "doi:10.70122/FK2/HXJVJU",
# quieten readr::read_tsv during test
.f = function(...) readr::read_tsv(..., show_col_types = FALSE)
)

expect_equal(actual, expected_file)
Expand All @@ -24,7 +26,9 @@ test_that("roster-by-doi", {

actual <-
get_dataframe_by_doi(
filedoi = expected_ds$roster$dataFile$persistentId # A value like "doi:10.70122/FK2/HXJVJU/SA3Z2V",
filedoi = expected_ds$roster$dataFile$persistentId, # A value like "doi:10.70122/FK2/HXJVJU/SA3Z2V",
# quieten readr::read_tsv during test
.f = function(...) readr::read_tsv(..., show_col_types = FALSE)
)

expect_equal(actual, expected_file)
Expand All @@ -38,7 +42,9 @@ test_that("roster-by-id", {

actual <-
get_dataframe_by_id(
fileid = expected_ds$roster$dataFile$id # A value like 1734005
fileid = expected_ds$roster$dataFile$id, # A value like 1734005
# quieten readr::read_tsv during test
.f = function(...) readr::read_tsv(..., show_col_types = FALSE)
)

expect_equal(actual, expected_file)
Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/tests-get_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ test_that("download tab from DOI and filename", {
actual <- get_dataset(contents[[ds_index]])
files <- actual$files
expected_dv <- retrieve_info_dataverse("expected-dataverse.yml")
expected_names <- c(
"citationDate", "createTime", "datasetId",
"datasetPersistentId", "fileAccessRequest", "files", "id",
"lastUpdateTime", "latestVersionPublishingState", "license",
"metadataBlocks", "publicationDate", "releaseTime",
"storageIdentifier", "UNF", "versionMinorNumber",
"versionNumber", "versionState")

expect_length(actual , 17L)
expect_setequal(names(actual) , expected_names)
expect_equal(actual$id , 182158L)
expect_equal(actual$datasetId , 1734004L)
expect_equal(actual$datasetPersistentId , "doi:10.70122/FK2/HXJVJU")
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/tests-search.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
test_that("simple search query", {
testthat::skip_on_cran()
expect_true(is.data.frame(dataverse_search("Gary King", key = "", server = "dataverse.harvard.edu")))
expect_true(is.data.frame(dataverse_search("Gary King", key = "", server = "dataverse.harvard.edu", verbose = FALSE)))
})

test_that("named argument search", {
testthat::skip_on_cran()
expect_true(is.data.frame(dataverse_search(author = "Gary King", title = "Ecological Inference", key = "", server = "dataverse.harvard.edu")))
expect_true(is.data.frame(dataverse_search(author = "Gary King", title = "Ecological Inference", key = "", server = "dataverse.harvard.edu", verbose = FALSE)))
})

test_that("simple search w/type argument", {
testthat::skip_on_cran()
expect_true(is.data.frame(dataverse_search(author = "Gary King", type = "dataset", key = "", server = "dataverse.harvard.edu")))
expect_true(is.data.frame(dataverse_search(author = "Gary King", type = "dataset", key = "", server = "dataverse.harvard.edu", verbose = FALSE)))
})

test_that("date range search using fq", {
testthat::skip_on_cran()
expect_true(is.data.frame(dataverse_search("*", fq = "dateSort:[2018-01-01T00:00:00Z+TO+2019-01-01T00:00:00Z]", type = "dataset", key = "", server = "dataverse.harvard.edu")))
expect_true(is.data.frame(dataverse_search("*", fq = "dateSort:[2018-01-01T00:00:00Z+TO+2019-01-01T00:00:00Z]", type = "dataset", key = "", server = "dataverse.harvard.edu", verbose = FALSE)))
})

test_that("publication year using fq", {
testthat::skip_on_cran()
expect_true(is.data.frame(dataverse_search("*", fq = "publicationDate:2018", type = "dataset", key = "", server = "dataverse.harvard.edu")))
expect_true(is.data.frame(dataverse_search("*", fq = "publicationDate:2018", type = "dataset", key = "", server = "dataverse.harvard.edu", verbose = FALSE)))
})

test_that("filter dataverses by subject using fq", {
testthat::skip_on_cran()
expect_true(is.data.frame(dataverse_search("*", fq = "subject_ss:Social+Sciences", type = "dataverse", key = "", server = "dataverse.harvard.edu")))
expect_true(is.data.frame(dataverse_search("*", fq = "subject_ss:Social+Sciences", type = "dataverse", key = "", server = "dataverse.harvard.edu", verbose = FALSE)))
})

test_that("empty fq search", {
testthat::skip_on_cran()
expect_length(dataverse_search("*", fq = "dateSort:[2019-02-01T00:00:00Z+TO+2019-01-01T00:00:00Z]", type = "dataset", key = "", server = "dataverse.harvard.edu"), 0)
expect_length(dataverse_search("*", fq = "dateSort:[2019-02-01T00:00:00Z+TO+2019-01-01T00:00:00Z]", type = "dataset", key = "", server = "dataverse.harvard.edu", verbose = FALSE), 0)
})