test-ein-notification.el 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (eval-when-compile (require 'cl))
  2. (require 'ert)
  3. (require 'ein-notification)
  4. (defun ein:testing-notification-tab-mock ()
  5. (make-instance 'ein:notification-tab
  6. :get-list (lambda () '(a b c))
  7. :get-current (lambda () 'a)
  8. :get-name #'ignore))
  9. (ert-deftest ein:header-line-normal ()
  10. (let* ((ein:%notification% (ein:notification "NotificationTest"))
  11. (kernel (oref ein:%notification% :kernel)))
  12. (oset ein:%notification% :tab (ein:testing-notification-tab-mock))
  13. (should (equal (ein:header-line)
  14. "IP[y]: /1\\ /2\\ /3\\ [+]"))))
  15. (ert-deftest ein:header-line-kernel-status-busy ()
  16. (let* ((ein:%notification% (ein:notification "NotificationTest"))
  17. (kernel (oref ein:%notification% :kernel)))
  18. (oset ein:%notification% :tab (ein:testing-notification-tab-mock))
  19. (ein:notification-status-set kernel
  20. 'status_busy.Kernel)
  21. (should (equal (ein:header-line)
  22. "IP[y]: Kernel is busy... | /1\\ /2\\ /3\\ [+]"))))
  23. (ert-deftest ein:header-line-notebook-status-busy ()
  24. (let* ((ein:%notification% (ein:notification "NotificationTest"))
  25. (notebook (oref ein:%notification% :notebook)))
  26. (oset ein:%notification% :tab (ein:testing-notification-tab-mock))
  27. (ein:notification-status-set notebook
  28. 'notebook_saved.Notebook)
  29. (should (equal (ein:header-line)
  30. "IP[y]: Notebook is saved | /1\\ /2\\ /3\\ [+]"))))
  31. (ert-deftest ein:header-line-notebook-complex ()
  32. (let* ((ein:%notification% (ein:notification "NotificationTest"))
  33. (kernel (oref ein:%notification% :kernel))
  34. (notebook (oref ein:%notification% :notebook)))
  35. (oset ein:%notification% :tab (ein:testing-notification-tab-mock))
  36. (ein:notification-status-set kernel
  37. 'status_dead.Kernel)
  38. (ein:notification-status-set notebook
  39. 'notebook_saving.Notebook)
  40. (should (equal
  41. (ein:header-line)
  42. (concat "IP[y]: Saving Notebook... | "
  43. "Kernel is dead. Need restart. | "
  44. "/1\\ /2\\ /3\\ [+]")))))
  45. (ert-deftest ein:notification-and-events ()
  46. (let* ((notification (ein:notification "NotificationTest"))
  47. (kernel (oref notification :kernel))
  48. (notebook (oref notification :notebook))
  49. (events (ein:events-new))
  50. (event-symbols
  51. '(notebook_saved.Notebook
  52. notebook_saving.Notebook
  53. notebook_save_failed.Notebook
  54. execution_count.Kernel
  55. status_restarting.Kernel
  56. status_idle.Kernel
  57. status_busy.Kernel
  58. status_dead.Kernel
  59. ))
  60. (callbacks (oref events :callbacks)))
  61. (ein:notification-bind-events notification events)
  62. (mapc (lambda (s) (should (gethash s callbacks))) event-symbols)
  63. (should (= (hash-table-count callbacks) (length event-symbols)))
  64. (should (equal (oref kernel :status) nil))
  65. (loop for et in (mapcar #'car (oref kernel :s2m))
  66. do (ein:events-trigger events et)
  67. do (should (equal (oref kernel :status) et))
  68. do (should (equal (oref notebook :status) nil)))
  69. (loop for et in (mapcar #'car (oref notebook :s2m))
  70. do (ein:events-trigger events et)
  71. do (should (equal (oref kernel :status) 'status_dead.Kernel))
  72. do (should (equal (oref notebook :status) et)))))