Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions RcppTskit/tests/testthat/test_TableCollection.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 13 additions & 9 deletions RcppTskit/tests/testthat/test_get_tskit_py.R
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -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!"
Expand Down
12 changes: 6 additions & 6 deletions RcppTskit/tests/testthat/test_load_summary_and_dump.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 8 additions & 6 deletions RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R
Original file line number Diff line number Diff line change
@@ -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")) {
Expand Down Expand Up @@ -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", {
Expand Down Expand Up @@ -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)
})
Loading