forked from millejoh/emacs-ipython-notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-ein-kernel.el
72 lines (63 loc) · 3.45 KB
/
test-ein-kernel.el
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(eval-when-compile (require 'cl))
(require 'ert)
(require 'ein-kernel)
(require 'ein-testing-kernel)
(require 'ein-testing-notebook)
(defun eintest:kernel-new (port)
(ein:kernel-new port "" nil "/api/kernels"
(get-buffer-create "*eintest: dummy for kernel test*")))
(ert-deftest ein:kernel-restart-check-url ()
(lexical-let* ((notebook (ein:notebook-new ein:testing-notebook-dummy-url "" nil))
(kernel (eintest:kernel-new 8888))
(kernel-id "KERNEL-ID")
(desired-url "http://127.0.0.1:8888/api/sessions/KERNEL-ID")
(dummy-response (make-request-response))
got-url)
(setf (ein:$notebook-kernel notebook) kernel)
(cl-letf (((symbol-function 'request)
(lambda (url &rest ignore) (setq got-url url) dummy-response))
((symbol-function 'set-process-query-on-exit-flag) #'ignore)
((symbol-function 'ein:kernel-stop-channels) #'ignore)
((symbol-function 'ein:websocket) (lambda (&rest ignore) (make-ein:$websocket :ws nil :kernel kernel :closed-by-client nil)))
((symbol-function 'ein:events-trigger) #'ignore)
((symbol-function 'ein:get-notebook-or-error) (lambda () (ein:get-notebook))))
(ein:kernel-retrieve-session--success
kernel nil :data (list :ws_url "ws://127.0.0.1:8888" :id kernel-id))
(ein:kernel-restart-session (ein:$notebook-kernel notebook))
(should (equal got-url desired-url)))))
(ert-deftest ein:kernel-interrupt-check-url ()
(let* ((kernel (eintest:kernel-new 8888))
(kernel-id "KERNEL-ID")
(desired-url "http://127.0.0.1:8888/api/kernels/KERNEL-ID/interrupt")
(dummy-response (make-request-response))
got-url)
(flet ((request (url &rest ignore) (setq got-url url) dummy-response)
(set-process-query-on-exit-flag (process flag))
(ein:kernel-stop-channels (&rest ignore))
(ein:websocket (url kernel on-message on-close on-open) (make-ein:$websocket :ws nil :kernel kernel :closed-by-client nil))
(ein:websocket-open-p (websocket) t))
(ein:kernel-retrieve-session--success
kernel nil :data (list :ws_url "ws://127.0.0.1:8888" :id kernel-id))
(ein:kernel-interrupt kernel)
(should (equal got-url desired-url)))))
(ert-deftest ein:kernel-kill-check-url ()
(let* ((kernel (eintest:kernel-new 8888))
(kernel-id "KERNEL-ID")
(desired-url "http://127.0.0.1:8888/api/sessions/KERNEL-ID")
(dummy-response (make-request-response))
got-url)
(flet ((request (url &rest ignore) (setq got-url url) dummy-response)
(set-process-query-on-exit-flag (process flag))
(ein:kernel-stop-channels (&rest ignore))
(ein:websocket (url kernel on-message on-close on-open) (make-ein:$websocket :ws nil :kernel kernel :closed-by-client nil)))
(ein:kernel-retrieve-session--success
kernel nil :data (list :ws_url "ws://127.0.0.1:8888" :id kernel-id))
(ein:kernel-delete-session kernel))
(should (equal got-url desired-url))))
;;; Test `ein:kernel-construct-help-string'
(ert-deftest ein:kernel-construct-help-string-when-found ()
(ein:testing-kernel-construct-help-string-loop))
(ert-deftest ein:kernel-construct-help-string-when-not-found ()
(should (equal (ein:kernel-construct-help-string nil) nil)))
;; Included in `ein:kernel-construct-help-string-when-found', but test
;; it explicitly to be sure.