| 1 |
context('kernel') |
| 2 |
|
| 3 |
get_desc <- function(result) { |
| 4 |
if (!is.na(result$desc)) result$desc |
| 5 |
else sub('_', ' ', result$id) |
| 6 |
} |
| 7 |
|
| 8 |
a_test_ran <- FALSE |
| 9 |
|
| 10 |
result_to_test <- function(result) { |
| 11 |
a_test_ran <<- TRUE |
| 12 |
|
| 13 |
emit_result <- switch(result$type, |
| 14 |
success = succeed, |
| 15 |
expected_failure = succeed, |
| 16 |
failure = fail, |
| 17 |
error = stop, |
| 18 |
unexpected_success = fail, |
| 19 |
skip = skip, |
| 20 |
stop('Unknown test result type: ', result$type)) |
| 21 |
|
| 22 |
msg <- if (!is.na(result$msg)) result$msg else '<no description>' |
| 23 |
|
| 24 |
test_that(get_desc(result), emit_result(msg)) |
| 25 |
} |
| 26 |
|
| 27 |
spec_add_status <- tryCatch(installspec(name = 'testir', displayname = 'testir'), error = function(e) 666L) |
| 28 |
test_that('test kernel installed', { |
| 29 |
skip_on_cran() |
| 30 |
expect_equal(spec_add_status, 0L) |
| 31 |
}) |
| 32 |
|
| 33 |
test_that('kernel tests pass', { |
| •34 |
skip(message = 'Run Python test separately on Debian') |
| 35 |
skip_on_cran() |
| 36 |
expect_true(file.exists('test_ir.py'), 'test_ir.py exists') |
| 37 |
|
| 38 |
Sys.setenv(PYTHONPATH = 'njr', PYTHONUNBUFFERED = '1') |
| 39 |
con <- pipe('python3 -W ignore::DeprecationWarning -m ndjson_testrunner test_ir', 'rt') |
| 40 |
on.exit(expect_equal(close(con), 0L)) |
| 41 |
|
| 42 |
jsonlite::stream_in(con, result_to_test, pagesize = 1L, verbose = FALSE) |
| 43 |
|
| 44 |
expect_true(a_test_ran, 'at least one python test ran') |
| 45 |
}) |
| 46 |
|
| 47 |
spec_rm_status <- system2('jupyter', c('kernelspec', 'remove', '-f', 'testir')) |
| 48 |
test_that('test kernel removed', { |
| 49 |
skip_on_cran() |
| 50 |
expect_equal(spec_rm_status, 0) |
| 51 |
}) |