-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add method checking function for testing (#78)
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' Check method arguments | ||
#' | ||
#' @param object Object to check | ||
#' @param prefix Prefix to use for method names | ||
#' @param verbose Print out additional information | ||
#' @keywords internal | ||
#' @noRd | ||
check_methods <- function(object, prefix, verbose = getOption("verbose")) { | ||
requireNamespace("testthat") | ||
|
||
for (method in object$methods()) { | ||
obj <- get0(method, object$def@refMethods, mode = "function") | ||
|
||
if (is.null(obj)) { | ||
next | ||
} | ||
|
||
exp <- get0(paste0(prefix, method), mode = "function") | ||
|
||
if (is.null(exp)) { | ||
if (verbose) { | ||
cat("Skipping method: ", method, "()\n", sep = "") | ||
} | ||
|
||
next | ||
} | ||
|
||
obj <- as.list(formals(obj)) | ||
|
||
if (identical(obj, list())) { | ||
# exp will be a named list, but will be empty | ||
obj <- structure(list(), names = character()) | ||
} | ||
|
||
exp <- as.list(formals(exp))[-1L] | ||
|
||
testthat::expect_identical( | ||
object = obj, | ||
expected = exp, | ||
info = paste0("method: ", method, "()"), | ||
ignore_srcref = TRUE | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters