File: test_kernel.r

package info (click to toggle)
r-cran-irkernel 1.3.2%2Bgit20240429.124f234-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 400 kB
  • sloc: python: 242; javascript: 69; makefile: 26; sh: 15
file content (51 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
context('kernel')

get_desc <- function(result) {
    if (!is.na(result$desc)) result$desc
    else sub('_', ' ', result$id)
}

a_test_ran <- FALSE

result_to_test <- function(result) {
    a_test_ran <<- TRUE
    
    emit_result <- switch(result$type,
        success            = succeed,
        expected_failure   = succeed,
        failure            = fail,
        error              = stop,
        unexpected_success = fail,
        skip               = skip,
        stop('Unknown test result type: ', result$type))
    
    msg <- if (!is.na(result$msg)) result$msg else '<no description>'
    
    test_that(get_desc(result), emit_result(msg))
}

spec_add_status <- tryCatch(installspec(name = 'testir', displayname = 'testir'), error = function(e) 666L)
test_that('test kernel installed', {
    skip_on_cran()
    expect_equal(spec_add_status, 0L)
})

test_that('kernel tests pass', {
    skip(message = 'Run Python test separately on Debian')
    skip_on_cran()
    expect_true(file.exists('test_ir.py'), 'test_ir.py exists')
    
    Sys.setenv(PYTHONPATH = 'njr', PYTHONUNBUFFERED = '1')
    con <- pipe('python3 -W ignore::DeprecationWarning -m ndjson_testrunner test_ir', 'rt')
    on.exit(expect_equal(close(con), 0L))
    
    jsonlite::stream_in(con, result_to_test, pagesize = 1L, verbose = FALSE)
    
    expect_true(a_test_ran, 'at least one python test ran')
})

spec_rm_status <- system2('jupyter', c('kernelspec', 'remove', '-f', 'testir'))
test_that('test kernel removed', {
    skip_on_cran()
    expect_equal(spec_rm_status, 0)
})