test-ein-kernel.el 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (eval-when-compile (require 'cl))
  2. (require 'ert)
  3. (require 'ein-kernel)
  4. (require 'ein-testing-kernel)
  5. (defun eintest:kernel-new (port)
  6. (ein:kernel-new port "/kernels"
  7. (get-buffer-create "*eintest: dummy for kernel test*")))
  8. (ert-deftest ein:kernel-start-check-url ()
  9. (let* ((kernel (eintest:kernel-new 8888))
  10. (notebook-id "NOTEBOOK-ID")
  11. (desired-url "http://127.0.0.1:8888/kernels?notebook=NOTEBOOK-ID")
  12. (dummy-response (make-request-response))
  13. got-url)
  14. (flet ((request (url &rest ignore) (setq got-url url) dummy-response)
  15. (set-process-query-on-exit-flag (process flag)))
  16. (ein:kernel-start kernel notebook-id)
  17. (should (equal got-url desired-url)))))
  18. (ert-deftest ein:kernel-restart-check-url ()
  19. (let* ((kernel (eintest:kernel-new 8888))
  20. (kernel-id "KERNEL-ID")
  21. (desired-url "http://127.0.0.1:8888/kernels/KERNEL-ID/restart")
  22. (dummy-response (make-request-response))
  23. got-url)
  24. (flet ((request (url &rest ignore) (setq got-url url) dummy-response)
  25. (set-process-query-on-exit-flag (process flag))
  26. (ein:kernel-stop-channels (&rest ignore))
  27. (ein:websocket (&rest ignore) (make-ein:$websocket))
  28. (ein:events-trigger (&rest ignore)))
  29. (ein:kernel--kernel-started
  30. kernel :data (list :ws_url "ws://127.0.0.1:8888" :kernel_id kernel-id))
  31. (ein:kernel-restart kernel)
  32. (should (equal got-url desired-url)))))
  33. (ert-deftest ein:kernel-interrupt-check-url ()
  34. (let* ((kernel (eintest:kernel-new 8888))
  35. (kernel-id "KERNEL-ID")
  36. (desired-url "http://127.0.0.1:8888/kernels/KERNEL-ID/interrupt")
  37. (dummy-response (make-request-response))
  38. got-url)
  39. (flet ((request (url &rest ignore) (setq got-url url) dummy-response)
  40. (set-process-query-on-exit-flag (process flag))
  41. (ein:kernel-stop-channels (&rest ignore))
  42. (ein:websocket (&rest ignore) (make-ein:$websocket)))
  43. (ein:kernel--kernel-started
  44. kernel :data (list :ws_url "ws://127.0.0.1:8888" :kernel_id kernel-id))
  45. (ein:kernel-interrupt kernel)
  46. (should (equal got-url desired-url)))))
  47. (ert-deftest ein:kernel-kill-check-url ()
  48. (let* ((kernel (eintest:kernel-new 8888))
  49. (kernel-id "KERNEL-ID")
  50. (desired-url "http://127.0.0.1:8888/kernels/KERNEL-ID")
  51. (dummy-response (make-request-response))
  52. got-url)
  53. (flet ((request (url &rest ignore) (setq got-url url) dummy-response)
  54. (set-process-query-on-exit-flag (process flag))
  55. (ein:kernel-stop-channels (&rest ignore))
  56. (ein:websocket (&rest ignore) (make-ein:$websocket)))
  57. (ein:kernel--kernel-started
  58. kernel :data (list :ws_url "ws://127.0.0.1:8888" :kernel_id kernel-id))
  59. (ein:kernel-kill kernel)
  60. (should (equal got-url desired-url)))))
  61. ;;; Test `ein:kernel-construct-help-string'
  62. (ert-deftest ein:kernel-construct-help-string-when-found ()
  63. (ein:testing-kernel-construct-help-string-loop))
  64. (ert-deftest ein:kernel-construct-help-string-when-not-found ()
  65. (should (equal (ein:kernel-construct-help-string nil) nil)))
  66. ;; Included in `ein:kernel-construct-help-string-when-found', but test
  67. ;; it explicitly to be sure.