Skip to content

Commit

Permalink
adjust stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
lsteinmann committed Apr 13, 2021
1 parent 79007a1 commit 21770fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions R/fix_relations.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#' uidlist = NULL)
#' }
fix_relations <- function(resource, replace_uids = TRUE, uidlist = NULL) {
if (replace_uids == TRUE && !is.data.frame(uidlist)) {
stop("replace_uids = TRUE but no concordance of UIDs supplied")
}
if (length(resource$relations) > 0) {
relations <- resource$relations
if (replace_uids) {
if (length(uidlist) == 0) {
stop("Please provide a list of UIDs and identifiers (get_uid_list()")
}
relations <- lapply(relations,
function(x) replace_uid(x, uidlist = uidlist))
} else if (!replace_uids) {
Expand Down
14 changes: 4 additions & 10 deletions tests/testthat/test-fix_relations.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@ for (item in items) {
}


test_that("fails without uidlist for items with relations", {
if (length(test_resources[[item]]$relations) > 0) {
expect_error(fix_relations(test_resources[[item]],
replace_uids = TRUE),
"UID")
} else {
test <- fix_relations(test_resources[[item]],
replace_uids = TRUE)
expect_null(test$relations)
}
test_that("fails without uidlist", {
expect_error(fix_relations(test_resources[[item]],
replace_uids = TRUE),
"*.UID.*")
})

}
2 changes: 1 addition & 1 deletion tests/testthat/test-select_by_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ for (item in items) {
})


test_that("fails withour value", {
test_that("fails without value", {
expect_error(select_by(test_resources,
by = "type"))
})
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-simplify_idaifield_resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ uidlist <- get_uid_list(test_docs)
items <- sample(seq_along(test_resources), size = 5)

for (item in items) {
print(paste("-----------------------------------------------###### Nr.: ", item))

test_that("error when no identifier", {
expect_error(simplify_single_resource(test_docs[[item]]),
"valid")
Expand All @@ -19,7 +21,7 @@ for (item in items) {
test_that("pass without uidlist when replaceuid = F", {
test <- simplify_single_resource(test_resources[[item]],
replace_uids = FALSE,
uidlist = "meh")
uidlist = NULL)
expect_identical(class(test), "list")
})

Expand Down

0 comments on commit 21770fa

Please sign in to comment.