diff --git a/RcppTskit/tests/testthat/test_TableCollection.R b/RcppTskit/tests/testthat/test_TableCollection.R index 595392f..42748e3 100644 --- a/RcppTskit/tests/testthat/test_TableCollection.R +++ b/RcppTskit/tests/testthat/test_TableCollection.R @@ -131,8 +131,7 @@ test_that("TableCollection and TreeSequence round-trip works", { tc <- ts$dump_tables() expect_true(is(tc, "TableCollection")) - expect_output(tc$print(), NA) # non-interactive mode - p <- tc$print() + tmp <- capture.output(p <- tc$print()) expect_equal( p, list( @@ -178,8 +177,9 @@ test_that("TableCollection and TreeSequence round-trip works", { ts2 <- tc$tree_sequence() expect_true(is(ts2, "TreeSequence")) - expect_output(ts$print(), NA) # non-interactive mode - expect_equal(ts$print(), ts2$print()) + tmp <- capture.output(ts_print <- ts$print()) + tmp <- capture.output(ts2_print <- ts2$print()) + expect_equal(ts_print, ts2_print) # Edge cases expect_error( diff --git a/RcppTskit/tests/testthat/test_get_tskit_py.R b/RcppTskit/tests/testthat/test_get_tskit_py.R index 4fdfea8..38750e0 100644 --- a/RcppTskit/tests/testthat/test_get_tskit_py.R +++ b/RcppTskit/tests/testthat/test_get_tskit_py.R @@ -1,4 +1,16 @@ +skip_if_offline_or_on_cran <- function() { + if (!(requireNamespace("covr", quietly = TRUE) && covr::in_covr())) { + # We need internet connection for get_tskit_py() + skip_if_offline() + + # The tests below take quite a bit of time since they pull in installation of + # Python modules, hence skipping on CRAN due to time limits on CRAN + skip_on_cran() + } +} + test_that("get_tskit_py() works", { + skip_if_offline_or_on_cran() # Testing that get_tskit_py() fails with a non-module object # Next two lines ensure that testthat is looking into the global environment # as is get_tskit_py() @@ -9,15 +21,6 @@ test_that("get_tskit_py() works", { regexp = "Object 'rubbish' exists in the global environment but is not a reticulate Python module" ) - if (!covr::in_covr()) { - # To get_tskit_py() we need internet connection - skip_if_offline() - - # The tests below take quite a bit of time since they pull in installation of - # Python modules, hence skipping on CRAN due to time limits on CRAN - skip_on_cran() - } - # Uncomment the below to explore test behaviour, but note that the removal # doesn't work when you try to run the tests multiple times in the same session! # Hence we are commenting this next line out. @@ -59,6 +62,7 @@ test_that("get_tskit_py() works", { }) test_that("check_tskit_py() validates reticulate Python module objects", { + skip_if_offline_or_on_cran() expect_message( expect_false(check_tskit_py(1)), "object must be a reticulate Python module object!" diff --git a/RcppTskit/tests/testthat/test_load_summary_and_dump.R b/RcppTskit/tests/testthat/test_load_summary_and_dump.R index 88cb9cd..9c77207 100644 --- a/RcppTskit/tests/testthat/test_load_summary_and_dump.R +++ b/RcppTskit/tests/testthat/test_load_summary_and_dump.R @@ -13,7 +13,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) expect_no_error(tc_load(ts_file, skip_tables = TRUE)) check_empty_tables <- function(ts) { - p <- ts$print() + tmp <- capture.output(p <- ts$print()) expect_true(all(p$tables$number == 0)) } ts <- ts_load(ts_file, skip_tables = TRUE) @@ -50,7 +50,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { ) expect_no_error(tc_load(ts_file, skip_tables = TRUE)) check_empty_tables <- function(tc) { - p <- tc$print() + tmp <- capture.output(p <- tc$print()) expect_true(all(p$tables$number == 0)) } tc <- tc_load(ts_file, skip_tables = TRUE) @@ -225,7 +225,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { regexp = "ts must be an object of externalptr class!" ) p_ptr <- ts_ptr_print(ts_ptr) - p <- ts$print() + tmp <- capture.output(p <- ts$print()) expect_equal( p, list( @@ -276,7 +276,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { regexp = "tc must be an object of externalptr class!" ) p_ptr <- tc_ptr_print(tc_ptr) - p <- tc$print() + tmp <- capture.output(p <- tc$print()) expect_equal( p, list( @@ -549,7 +549,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { expect_equal(m_ptr, m) p_ptr <- ts_ptr_print(ts_ptr) - p <- ts$print() + tmp <- capture.output(p <- ts$print()) expect_equal( p_ptr, list( @@ -630,7 +630,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", { expect_equal(m_ptr_tc, m_ptr_ts) p_ptr <- tc_ptr_print(tc_ptr) - p <- tc$print() + tmp <- capture.output(p <- tc$print()) expect_equal( p_ptr, list( diff --git a/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R b/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R index eea80fe..b54e54a 100644 --- a/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R +++ b/RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R @@ -1,6 +1,6 @@ skip_if_no_tskit_py <- function() { - if (!covr::in_covr()) { - # To get_tskit_py() we need internet connection + if (!(requireNamespace("covr", quietly = TRUE) && covr::in_covr())) { + # We need internet connection for get_tskit_py() skip_if_offline() } if (!reticulate::py_module_available("tskit")) { @@ -142,8 +142,9 @@ test_that("ts_r_to_py() and ts_py_to_r() work", { expect_equal(length(ts2_py$tables$mutations$metadata), m2$mutations) expect_true(is(ts2_r, "TreeSequence")) - expect_output(ts2_r$print(), NA) # non-interactive mode - expect_equal(ts2_r$print(), ts_ptr_print(ts_ptr2_r)) + tmp <- capture.output(ts2_r_print <- ts2_r$print()) + tmp <- capture.output(ts_ptr2_r_print <- ts_ptr_print(ts_ptr2_r)) + expect_equal(ts2_r_print, ts_ptr2_r_print) }) test_that("tc_r_to_py() and tc_py_to_r() work", { @@ -263,6 +264,7 @@ test_that("tc_r_to_py() and tc_py_to_r() work", { expect_equal(length(tc2_py$mutations$metadata), m2$mutations) expect_true(is(tc2_r, "TableCollection")) - expect_output(tc2_r$print(), NA) # non-interactive mode - expect_equal(tc2_r$print(), tc_ptr_print(tc_ptr2_r)) + tmp <- capture.output(tc2_r_print <- tc2_r$print()) + tmp <- capture.output(tc_ptr2_r <- tc_ptr_print(tc_ptr2_r)) + expect_equal(tc2_r_print, tc_ptr2_r) })