Skip to content

Commit 366fdac

Browse files
Merge pull request #71 from HighlanderLab:issues_69_and_70
Fixing edge cases in tests
2 parents 068f727 + edff082 commit 366fdac

4 files changed

Lines changed: 31 additions & 25 deletions

File tree

RcppTskit/tests/testthat/test_TableCollection.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ test_that("TableCollection and TreeSequence round-trip works", {
131131

132132
tc <- ts$dump_tables()
133133
expect_true(is(tc, "TableCollection"))
134-
expect_output(tc$print(), NA) # non-interactive mode
135-
p <- tc$print()
134+
tmp <- capture.output(p <- tc$print())
136135
expect_equal(
137136
p,
138137
list(
@@ -178,8 +177,9 @@ test_that("TableCollection and TreeSequence round-trip works", {
178177

179178
ts2 <- tc$tree_sequence()
180179
expect_true(is(ts2, "TreeSequence"))
181-
expect_output(ts$print(), NA) # non-interactive mode
182-
expect_equal(ts$print(), ts2$print())
180+
tmp <- capture.output(ts_print <- ts$print())
181+
tmp <- capture.output(ts2_print <- ts2$print())
182+
expect_equal(ts_print, ts2_print)
183183

184184
# Edge cases
185185
expect_error(

RcppTskit/tests/testthat/test_get_tskit_py.R

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
skip_if_offline_or_on_cran <- function() {
2+
if (!(requireNamespace("covr", quietly = TRUE) && covr::in_covr())) {
3+
# We need internet connection for get_tskit_py()
4+
skip_if_offline()
5+
6+
# The tests below take quite a bit of time since they pull in installation of
7+
# Python modules, hence skipping on CRAN due to time limits on CRAN
8+
skip_on_cran()
9+
}
10+
}
11+
112
test_that("get_tskit_py() works", {
13+
skip_if_offline_or_on_cran()
214
# Testing that get_tskit_py() fails with a non-module object
315
# Next two lines ensure that testthat is looking into the global environment
416
# as is get_tskit_py()
@@ -9,15 +21,6 @@ test_that("get_tskit_py() works", {
921
regexp = "Object 'rubbish' exists in the global environment but is not a reticulate Python module"
1022
)
1123

12-
if (!covr::in_covr()) {
13-
# To get_tskit_py() we need internet connection
14-
skip_if_offline()
15-
16-
# The tests below take quite a bit of time since they pull in installation of
17-
# Python modules, hence skipping on CRAN due to time limits on CRAN
18-
skip_on_cran()
19-
}
20-
2124
# Uncomment the below to explore test behaviour, but note that the removal
2225
# doesn't work when you try to run the tests multiple times in the same session!
2326
# Hence we are commenting this next line out.
@@ -59,6 +62,7 @@ test_that("get_tskit_py() works", {
5962
})
6063

6164
test_that("check_tskit_py() validates reticulate Python module objects", {
65+
skip_if_offline_or_on_cran()
6266
expect_message(
6367
expect_false(check_tskit_py(1)),
6468
"object must be a reticulate Python module object!"

RcppTskit/tests/testthat/test_load_summary_and_dump.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", {
1313
)
1414
expect_no_error(tc_load(ts_file, skip_tables = TRUE))
1515
check_empty_tables <- function(ts) {
16-
p <- ts$print()
16+
tmp <- capture.output(p <- ts$print())
1717
expect_true(all(p$tables$number == 0))
1818
}
1919
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", {
5050
)
5151
expect_no_error(tc_load(ts_file, skip_tables = TRUE))
5252
check_empty_tables <- function(tc) {
53-
p <- tc$print()
53+
tmp <- capture.output(p <- tc$print())
5454
expect_true(all(p$tables$number == 0))
5555
}
5656
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", {
225225
regexp = "ts must be an object of externalptr class!"
226226
)
227227
p_ptr <- ts_ptr_print(ts_ptr)
228-
p <- ts$print()
228+
tmp <- capture.output(p <- ts$print())
229229
expect_equal(
230230
p,
231231
list(
@@ -276,7 +276,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", {
276276
regexp = "tc must be an object of externalptr class!"
277277
)
278278
p_ptr <- tc_ptr_print(tc_ptr)
279-
p <- tc$print()
279+
tmp <- capture.output(p <- tc$print())
280280
expect_equal(
281281
p,
282282
list(
@@ -549,7 +549,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", {
549549
expect_equal(m_ptr, m)
550550

551551
p_ptr <- ts_ptr_print(ts_ptr)
552-
p <- ts$print()
552+
tmp <- capture.output(p <- ts$print())
553553
expect_equal(
554554
p_ptr,
555555
list(
@@ -630,7 +630,7 @@ test_that("ts/tc_load(), ts/tc_summary*(), and ts/tc_dump(x) work", {
630630
expect_equal(m_ptr_tc, m_ptr_ts)
631631

632632
p_ptr <- tc_ptr_print(tc_ptr)
633-
p <- tc$print()
633+
tmp <- capture.output(p <- tc$print())
634634
expect_equal(
635635
p_ptr,
636636
list(

RcppTskit/tests/testthat/test_r_to_py_and_py_to_r.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
skip_if_no_tskit_py <- function() {
2-
if (!covr::in_covr()) {
3-
# To get_tskit_py() we need internet connection
2+
if (!(requireNamespace("covr", quietly = TRUE) && covr::in_covr())) {
3+
# We need internet connection for get_tskit_py()
44
skip_if_offline()
55
}
66
if (!reticulate::py_module_available("tskit")) {
@@ -142,8 +142,9 @@ test_that("ts_r_to_py() and ts_py_to_r() work", {
142142
expect_equal(length(ts2_py$tables$mutations$metadata), m2$mutations)
143143

144144
expect_true(is(ts2_r, "TreeSequence"))
145-
expect_output(ts2_r$print(), NA) # non-interactive mode
146-
expect_equal(ts2_r$print(), ts_ptr_print(ts_ptr2_r))
145+
tmp <- capture.output(ts2_r_print <- ts2_r$print())
146+
tmp <- capture.output(ts_ptr2_r_print <- ts_ptr_print(ts_ptr2_r))
147+
expect_equal(ts2_r_print, ts_ptr2_r_print)
147148
})
148149

149150
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", {
263264
expect_equal(length(tc2_py$mutations$metadata), m2$mutations)
264265

265266
expect_true(is(tc2_r, "TableCollection"))
266-
expect_output(tc2_r$print(), NA) # non-interactive mode
267-
expect_equal(tc2_r$print(), tc_ptr_print(tc_ptr2_r))
267+
tmp <- capture.output(tc2_r_print <- tc2_r$print())
268+
tmp <- capture.output(tc_ptr2_r <- tc_ptr_print(tc_ptr2_r))
269+
expect_equal(tc2_r_print, tc_ptr2_r)
268270
})

0 commit comments

Comments
 (0)