Skip to content

Commit

Permalink
expected dataverse info
Browse files Browse the repository at this point in the history
ref #44
  • Loading branch information
wibeasley committed Dec 30, 2020
1 parent 16ada7e commit 09713ab
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
22 changes: 22 additions & 0 deletions inst/expected-dataverse-root.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
id: 1
alias: demo
name: Demo Dataverse
dataverseContacts:
displayOrder: 0
contactEmail: [email protected]
permissionRoot: yes
description: "<span><span><span><h3>This Dataverse is for demo purposes only.</h3></span></span></span>\r\n\r\nTo
archive and publish to the Harvard repository, visit <a href=\"https://dataverse.harvard.edu\"
title=\"Harvard Dataverse\" target=\"_blank\">dataverse.harvard.edu</a>. To learn
about and publish to other repositories, visit The Dataverse Project at <a href=\"https://dataverse.org\"
title=\"The Dataverse Project\" target=\"_blank\">dataverse.org</a>."
dataverseType: UNCATEGORIZED
creationDate: '2015-04-16T17:46:00Z'
theme:
id: 1
logo: HarvardShield_RGB.png
tagline: This Dataverse is for demo purposes only. To deposit actual datasets please
visit dataverse.harvard.edu.
linkColor: '000000'
textColor: a51c30
backgroundColor: F5F5F5
12 changes: 12 additions & 0 deletions inst/expected-dataverse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
id: 396355
alias: dataverse-client-r
name: dataverse-client-r
affiliation: IQSS
dataverseContacts:
displayOrder: 0
contactEmail: [email protected]
permissionRoot: yes
description: Dataverse for testing [dataverse-client-r](https://github.com/IQSS/dataverse-client-r)
dataverseType: RESEARCHERS
ownerId: 1
creationDate: '2020-01-02T04:18:06Z'
8 changes: 7 additions & 1 deletion tests/testthat/manual/seed/seed-yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ dv <- get_dataverse("dataverse-client-r")
contents <- dataverse_contents(dv)
ds_1 <- dataset_files(contents[[1]])

get_dataverse(":root") %>%
yaml::write_yaml("inst/expected-dataverse-root.yml")

dv %>%
yaml::write_yaml("inst/expected-dataverse.yml")

ds_1 %>%
rlang::set_names(c("roster", "image")) %>%
rlang::set_names(c("roster", "image")) %>% # Manually add friendly names to each file
yaml::write_yaml("inst/dataset-basketball/expected-metadata.yml")

# retrieve-from-file ------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/tests-get_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test_that("download tab from DOI and filename", {
contents <- dataverse_contents(dv)
actual <- get_dataset(contents[[1]])
files <- actual$files
expected_dv <- retrieve_info_dataverse("expected-dataverse.yml")

expect_length(actual , 16L)
expect_equal(actual$id , 182158L)
Expand Down
28 changes: 15 additions & 13 deletions tests/testthat/tests-get_dataverse.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# See https://demo.dataverse.org/dataverse/dataverse-client-r

test_that("dataverse root", {
expected <- retrieve_info_dataverse("expected-dataverse-root.yml")
actual <- get_dataverse(
dataverse = ":root"
)
expect_equal(actual$id, 1L)
expect_equal(actual$alias, "demo")
expect_equal(actual$name, "Demo Dataverse")
expect_s3_class(actual$dataverseContacts, "data.frame")
expect_match(actual$description, "^.+This Dataverse is for demo purposes only\\..+$")
expect_equal(actual$creationDate, "2015-04-16T17:46:00Z") # Notice this is a string
expect_equal(actual$id , expected$id)
expect_equal(actual$alias , expected$alias)
expect_equal(actual$name , expected$name)
expect_equal(actual$description , expected$description)
expect_equal(actual$creationDate , expected$creationDate) # Notice this is a string
expect_s3_class(actual$dataverseContacts , "data.frame")
})

test_that("dataverse for 'dataverse-client-r'", {
expected <- retrieve_info_dataverse("expected-dataverse.yml")
actual <- get_dataverse(
dataverse = "dataverse-client-r"
)
expect_equal(actual$id, 396355)
expect_equal(actual$alias, "dataverse-client-r")
expect_equal(actual$name, "dataverse-client-r")
expect_equal(actual$affiliation, "IQSS")
expect_s3_class(actual$dataverseContacts, "data.frame")
expect_match(actual$description, "^Dataverse for testing.+$")
expect_equal(actual$creationDate, "2020-01-02T04:18:06Z") # Notice this is a string

expect_equal(actual$id , expected$id)
expect_equal(actual$alias , expected$alias)
expect_equal(actual$name , expected$name)
expect_equal(actual$description , expected$description)
expect_equal(actual$creationDate , expected$creationDate) # Notice this is a string
expect_s3_class(actual$dataverseContacts , "data.frame")
})
11 changes: 10 additions & 1 deletion tests/testthat/utils-manifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ retrieve_file_expected <- function (subdataverse, file_name) {
stop(
"The testing file `",
file_name,
"` in the (sub)datavserse `",
"` in the (sub)dataverse `",
subdataverse,
"` is not found. Please verify that the manifest is synced with the collection of test files. "
)
Expand All @@ -34,6 +34,15 @@ retrieve_file_expected <- function (subdataverse, file_name) {
}
# retrieve_file_expected("rosters", "roster-bulls-1996.csv")

retrieve_info_dataverse <- function (path) {
yaml::read_yaml(system.file(path, package = "dataverse"))
}
# retrieve_info_dataverse("expected-dataverse.yml")

retrieve_info_dataset <- function (path) {
yaml::read_yaml(system.file(path, package = "dataverse"))
}
# retrieve_info_dataset("dataset-basketball/expected-metadata.yml")

# compare_data_frame <- function (d_actual, d_expected) {
#
Expand Down

0 comments on commit 09713ab

Please sign in to comment.