From cc48edb73b49b6b6e5ca9fc4b78c95cbc9e6d9be Mon Sep 17 00:00:00 2001 From: AleKoure Date: Tue, 5 Dec 2023 17:50:57 +0000 Subject: [PATCH 1/2] fix: multiclass assertion with has_class --- R/utils.R | 2 +- tests/testthat/test-utils.R | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 720a272..4321a7d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -166,7 +166,7 @@ has_class <- function(..., class){ check_this <- list(...) parent <- parent.frame() given_classes <- lapply(check_this, function(name) class(parent$.top_env[[name]])) - all(given_classes %in% class) + all(unlist(given_classes) %in% class) } diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 9fd8f1e..d2f5aad 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -66,4 +66,7 @@ test_that("has_class works with verify", { wt_var <- "wt" expect_equal(verify(mtcars, has_class(mpg_var, class = "numeric")), mtcars) expect_equal(mtcars %>% verify(has_class(mpg_var, wt_var, class = "numeric")), mtcars) + + time_df = data.frame(time_var = Sys.time()) + expect_equal(time_df %>% verify(has_class("time_var", class = c("POSIXct", "POSIXt"))), time_df) }) From 7e175ee7a42029e681cad13d64708a7f9df48cc2 Mon Sep 17 00:00:00 2001 From: Alexandros Kouretsis Date: Wed, 6 Dec 2023 14:49:51 +0200 Subject: [PATCH 2/2] Update test-utils.R --- tests/testthat/test-utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index d2f5aad..cfcaf6f 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -67,6 +67,6 @@ test_that("has_class works with verify", { expect_equal(verify(mtcars, has_class(mpg_var, class = "numeric")), mtcars) expect_equal(mtcars %>% verify(has_class(mpg_var, wt_var, class = "numeric")), mtcars) - time_df = data.frame(time_var = Sys.time()) + time_df <- data.frame(time_var = Sys.time()) expect_equal(time_df %>% verify(has_class("time_var", class = c("POSIXct", "POSIXt"))), time_df) })