From f674ba2a731c1370309d50614f81257ead1bedd0 Mon Sep 17 00:00:00 2001 From: Ethan White Date: Sat, 13 Jul 2024 10:58:59 -0400 Subject: [PATCH] Skip tests if deepforest not present instead of skipping on CRAN This lets tests run on CI and follows recommend practice: https://rstudio.github.io/reticulate/articles/package.html#checking-and-testing-on-cran --- tests/testthat/test-integration.R | 40 ++++++++++--------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/tests/testthat/test-integration.R b/tests/testthat/test-integration.R index a578e48..2a2f81f 100644 --- a/tests/testthat/test-integration.R +++ b/tests/testthat/test-integration.R @@ -2,47 +2,33 @@ library(testthat) context("integration tests for DeepForest in R") -test_that("deepforest model is installed", { - - # Python package not installed on CRAN - - skip_on_cran() +skip_if_no_deepforest <- function() { + deepforest_avail <- py_module_available("deepforest") + if (!deepforest) + skip("deepforest not available for testing") +} +test_that("deepforest model is installed", { + skip_if_no_deepforest() deepforest_available = reticulate::py_module_available("deepforest") expect_identical(deepforest_available, TRUE) }) test_that("deepforest model exists when loaded", { - - # Python package not installed on CRAN - - skip_on_cran() - + skip_if_no_deepforest() model = df_model() expect_type(model, "closure") - }) test_that("use_release model exists when loaded", { - - # Python package not installed on CRAN - - skip_on_cran() - + skip_if_no_deepforest() model = df_model() model$use_release() expect_type(model, "closure") - }) test_that("image prediction works", { - - # Python package not installed on CRAN - - skip_on_cran() - - expect - + skip_if_no_deepforest() model = df_model() model$use_release() image_path = get_data("OSBS_029.png") @@ -51,9 +37,7 @@ test_that("image prediction works", { }) test_that("training works", { - - skip_on_cran() - + skip_if_no_deepforest() model = df_model() model$use_release() annotations_file = get_data("testfile_deepforest.csv") @@ -65,4 +49,4 @@ test_that("training works", { model$create_trainer() model$trainer$fit(model) expect_type(model, "closure") -}) \ No newline at end of file +})