Repository: spark
Updated Branches:
  refs/heads/master de99c3d08 -> d30b7e669


[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 <[email protected]>

Closes #13636 from felixcheung/rendswith.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/d30b7e66
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/d30b7e66
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/d30b7e66

Branch: refs/heads/master
Commit: d30b7e6696e20f1014c7f26aadbc051da0fac578
Parents: de99c3d
Author: Felix Cheung <[email protected]>
Authored: Wed Jun 15 10:29:07 2016 -0700
Committer: Shivaram Venkataraman <[email protected]>
Committed: Wed Jun 15 10:29:07 2016 -0700

----------------------------------------------------------------------
 R/pkg/inst/tests/testthat/test_context.R | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/d30b7e66/R/pkg/inst/tests/testthat/test_context.R
----------------------------------------------------------------------
diff --git a/R/pkg/inst/tests/testthat/test_context.R 
b/R/pkg/inst/tests/testthat/test_context.R
index 1d56ced..126484c 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", {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to