Commit 6874b76c authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

kernels: Add test talking to ipykernel.

* tests/kernels.scm: New file.
* Makefile.am (SCM_TESTS): Add it.
* environment.scm <native-inputs>: Add JUPYTER, PYTHON-IPYTHON, and
PYTHON-IPYKERNEL.
parent 89d52b8f
......@@ -41,6 +41,7 @@ TEST_EXTENSIONS = .scm
SCM_TESTS = \
tests/magic.scm \
tests/hmac.scm \
tests/kernels.scm \
tests/environ.scm
TESTS = $(SCM_TESTS)
......
......@@ -79,7 +79,12 @@
(native-inputs
`(("autoconf" ,autoconf)
("automake" ,automake)
("pkg-config" ,pkg-config)))
("pkg-config" ,pkg-config)
;; For testing.
("jupyter" ,(specification->package "jupyter"))
("python-ipython" ,(specification->package "python-ipython"))
("python-ipykernel" ,(specification->package "python-ipykernel"))))
(inputs
`(("guix" ,guix)
("guile" ,guile-2.2)))
......
;;; Guix-kernel -- Guix kernel for Jupyter
;;; Copyright (C) 2019 Inria
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(define-module (tests kernels)
#:use-module (jupyter kernels)
#:use-module (jupyter messages)
#:use-module (simple-zmq)
#:use-module (json)
#:use-module (rnrs bytevectors)
#:use-module (srfi srfi-64))
(define %context
(zmq-create-context))
(define %kernel-uuid #vu8(1 2 3 4 5 6 7 8 9 0))
(define %kernel-key "secretkey")
(define %kernel #f)
(test-begin "kernels")
;; These tests require the "python3" kernel provided by ipykernel.
(unless (find-kernel-by-name "python3") (test-skip 1))
(test-assert "run-kernel python3"
(let ((kernel (run-kernel %context "python3" %kernel-uuid %kernel-key)))
(set! %kernel kernel)
(and (kernel? (pk 'kernel kernel))
(kill (kernel-pid kernel) 0))))
(unless %kernel (test-skip 1))
(test-assert "execute_request"
(let ((request (message (header "execute_request" "luser" "12345")
(scm->json-string
'((code . "40 + 2\n")
(silent . #f))))))
(send-message %kernel request
#:recipient %kernel-uuid)
(let ((reply (pk 'reply (read-message %kernel))))
(and (message? reply)
(bytevector=? (message-sender reply) %kernel-uuid)
(equal? (message-parent-header reply)
(message-header request))
(string=? (message-type reply) "execute_reply")
(let ((content (json-string->scm (message-content reply))))
(string=? (hash-ref content "status") "ok"))))))
(when %kernel
(close-kernel %kernel)
(kill (kernel-pid %kernel) 15))
(test-end "kernels")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment