emacs-ipython-notebook/tests/test-ein-notification.el

68 lines
3 KiB
EmacsLisp
Raw Normal View History

(eval-when-compile (require 'cl))
(require 'ert)
(require 'ein-notification)
2012-09-02 06:14:54 +02:00
(defun ein:testing-notification-tab-mock ()
(make-instance 'ein:notification-tab
:get-list (lambda () '(a b c))
:get-current (lambda () 'a)
:get-name #'ignore))
2012-09-02 06:18:34 +02:00
(ert-deftest ein:header-line-normal ()
(let* ((ein:%notification% (ein:notification "NotificationTest"))
(kernel (oref ein:%notification% :kernel)))
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
(should (equal (ein:header-line)
"IP[y]: [1] 2 3 "))))
(ert-deftest ein:header-line-kernel-status-busy ()
(let* ((ein:%notification% (ein:notification "NotificationTest"))
(kernel (oref ein:%notification% :kernel)))
2012-09-02 06:14:54 +02:00
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
(ein:notification-status-set kernel
'status_busy.Kernel)
2012-09-02 06:14:54 +02:00
(should (equal (ein:header-line)
"IP[y]: Kernel is busy... | [1] 2 3 "))))
(ert-deftest ein:header-line-notebook-status-busy ()
(let* ((ein:%notification% (ein:notification "NotificationTest"))
(notebook (oref ein:%notification% :notebook)))
2012-09-02 06:14:54 +02:00
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
(ein:notification-status-set notebook
'notebook_saved.Notebook)
2012-09-02 06:14:54 +02:00
(should (equal (ein:header-line)
"IP[y]: Notebook is saved | [1] 2 3 "))))
(ert-deftest ein:header-line-notebook-complex ()
(let* ((ein:%notification% (ein:notification "NotificationTest"))
(kernel (oref ein:%notification% :kernel))
(notebook (oref ein:%notification% :notebook)))
2012-09-02 06:14:54 +02:00
(oset ein:%notification% :tab (ein:testing-notification-tab-mock))
(ein:notification-status-set kernel
'status_dead.Kernel)
(ein:notification-status-set notebook
'notebook_saving.Notebook)
(should (equal
(ein:header-line)
2012-09-02 06:14:54 +02:00
(concat "IP[y]: Saving Notebook... | "
"Kernel is dead. Need restart. | "
"[1] 2 3 ")))))
(ert-deftest ein:notification-and-events ()
(let* ((notification (ein:notification "NotificationTest"))
(kernel (oref notification :kernel))
(notebook (oref notification :notebook))
(events (ein:events-new)))
(ein:notification-bind-events notification events)
(should (= (hash-table-count (oref events :callbacks)) 7))
(should (equal (oref kernel :status) nil))
(loop for et in (mapcar #'car (oref kernel :s2m))
do (ein:events-trigger events et)
do (should (equal (oref kernel :status) et))
do (should (equal (oref notebook :status) nil)))
(loop for et in (mapcar #'car (oref notebook :s2m))
do (ein:events-trigger events et)
do (should (equal (oref kernel :status) 'status_dead.Kernel))
do (should (equal (oref notebook :status) et)))))