From d30b7e6696e20f1014c7f26aadbc051da0fac578 Mon Sep 17 00:00:00 2001 From: Felix Cheung Date: Wed, 15 Jun 2016 10:29:07 -0700 Subject: [SPARK-15637][SPARK-15931][SPARKR] Fix R masked functions checks ## What changes were proposed in this pull request? Because of the fix in SPARK-15684, this exclusion is no longer necessary. ## How was this patch tested? unit tests shivaram Author: Felix Cheung Closes #13636 from felixcheung/rendswith. --- R/pkg/inst/tests/testthat/test_context.R | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'R/pkg/inst/tests') diff --git a/R/pkg/inst/tests/testthat/test_context.R b/R/pkg/inst/tests/testthat/test_context.R index 1d56ced399..126484c995 100644 --- a/R/pkg/inst/tests/testthat/test_context.R +++ b/R/pkg/inst/tests/testthat/test_context.R @@ -19,21 +19,26 @@ context("test functions in sparkR.R") test_that("Check masked functions", { # Check that we are not masking any new function from base, stats, testthat unexpectedly - masked <- conflicts(detail = TRUE)$`package:SparkR` - expect_true("describe" %in% masked) # only when with testthat.. - func <- lapply(masked, function(x) { capture.output(showMethods(x))[[1]] }) - funcSparkROrEmpty <- grepl("\\(package SparkR\\)$|^$", func) - maskedBySparkR <- masked[funcSparkROrEmpty] + # NOTE: We should avoid adding entries to *namesOfMaskedCompletely* as masked functions make it + # hard for users to use base R functions. Please check when in doubt. + namesOfMaskedCompletely <- c("cov", "filter", "sample") namesOfMasked <- c("describe", "cov", "filter", "lag", "na.omit", "predict", "sd", "var", "colnames", "colnames<-", "intersect", "rank", "rbind", "sample", "subset", "summary", "transform", "drop", "window", "as.data.frame") - namesOfMaskedCompletely <- c("cov", "filter", "sample") if (as.numeric(R.version$major) >= 3 && as.numeric(R.version$minor) >= 3) { namesOfMasked <- c("endsWith", "startsWith", namesOfMasked) - namesOfMaskedCompletely <- c("endsWith", "startsWith", namesOfMaskedCompletely) } + masked <- conflicts(detail = TRUE)$`package:SparkR` + expect_true("describe" %in% masked) # only when with testthat.. + func <- lapply(masked, function(x) { capture.output(showMethods(x))[[1]] }) + funcSparkROrEmpty <- grepl("\\(package SparkR\\)$|^$", func) + maskedBySparkR <- masked[funcSparkROrEmpty] expect_equal(length(maskedBySparkR), length(namesOfMasked)) - expect_equal(sort(maskedBySparkR), sort(namesOfMasked)) + # make the 2 lists the same length so expect_equal will print their content + l <- max(length(maskedBySparkR), length(namesOfMasked)) + length(maskedBySparkR) <- l + length(namesOfMasked) <- l + expect_equal(sort(maskedBySparkR, na.last = TRUE), sort(namesOfMasked, na.last = TRUE)) # above are those reported as masked when `library(SparkR)` # note that many of these methods are still callable without base:: or stats:: prefix # there should be a test for each of these, except followings, which are currently "broken" @@ -42,7 +47,11 @@ test_that("Check masked functions", { })) maskedCompletely <- masked[!funcHasAny] expect_equal(length(maskedCompletely), length(namesOfMaskedCompletely)) - expect_equal(sort(maskedCompletely), sort(namesOfMaskedCompletely)) + l <- max(length(maskedCompletely), length(namesOfMaskedCompletely)) + length(maskedCompletely) <- l + length(namesOfMaskedCompletely) <- l + expect_equal(sort(maskedCompletely, na.last = TRUE), + sort(namesOfMaskedCompletely, na.last = TRUE)) }) test_that("repeatedly starting and stopping SparkR", { -- cgit v1.2.3