Ensure a monadic value is returned from a call to jupyter-mlet*

This commit is contained in:
Nathaniel Nicandro 2023-01-29 17:49:22 -06:00
parent 6c55e5bae5
commit b07f9c5cfe
2 changed files with 27 additions and 14 deletions

View file

@ -1827,7 +1827,8 @@ the updated state."
(save-excursion (save-excursion
(goto-char (point-max)) (goto-char (point-max))
(jupyter-repl-update-cell-count (jupyter-repl-update-cell-count
(oref client execution-count)))))))) (oref client execution-count)))))
(jupyter-return-delayed nil))))
;;; `jupyter-repl-interaction-mode' ;;; `jupyter-repl-interaction-mode'

View file

@ -387,21 +387,24 @@
(jupyter-kernel-info-request)))) (jupyter-kernel-info-request))))
(should res) (should res)
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "kernel_info_reply"))))) (should (string= (jupyter-message-type res) "kernel_info_reply"))
(jupyter-return-delayed nil))))
(ert-info ("Comm info") (ert-info ("Comm info")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
(jupyter-comm-info-request)))) (jupyter-comm-info-request))))
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "comm_info_reply"))))) (should (string= (jupyter-message-type res) "comm_info_reply"))
(jupyter-return-delayed nil))))
(ert-info ("Execute") (ert-info ("Execute")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
(jupyter-execute-request :code "y = 1 + 2")))) (jupyter-execute-request :code "y = 1 + 2"))))
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "execute_reply"))))) (should (string= (jupyter-message-type res) "execute_reply"))
(jupyter-return-delayed nil))))
(ert-info ("Input") (ert-info ("Input")
(cl-letf (((symbol-function 'read-from-minibuffer) (cl-letf (((symbol-function 'read-from-minibuffer)
(lambda (_prompt &rest _args) "foo"))) (lambda (_prompt &rest _args) "foo")))
@ -413,7 +416,8 @@
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "execute_result")) (should (string= (jupyter-message-type res) "execute_result"))
(should (equal (jupyter-message-data res :text/plain) "'foo'"))))))) (should (equal (jupyter-message-data res :text/plain) "'foo'"))
(jupyter-return-delayed nil))))))
(ert-info ("Inspect") (ert-info ("Inspect")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
@ -423,7 +427,8 @@
:detail 0)))) :detail 0))))
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "inspect_reply"))))) (should (string= (jupyter-message-type res) "inspect_reply"))
(jupyter-return-delayed nil))))
(ert-info ("Complete") (ert-info ("Complete")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
@ -432,7 +437,8 @@
:pos 8)))) :pos 8))))
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "complete_reply"))))) (should (string= (jupyter-message-type res) "complete_reply"))
(jupyter-return-delayed nil))))
(ert-info ("History") (ert-info ("History")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
@ -440,7 +446,8 @@
:hist-access-type "tail" :n 2)))) :hist-access-type "tail" :n 2))))
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "history_reply"))))) (should (string= (jupyter-message-type res) "history_reply"))
(jupyter-return-delayed nil))))
(ert-info ("Is Complete") (ert-info ("Is Complete")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
@ -448,7 +455,8 @@
:code "for i in range(5):")))) :code "for i in range(5):"))))
(should-not (null res)) (should-not (null res))
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "is_complete_reply"))))) (should (string= (jupyter-message-type res) "is_complete_reply"))
(jupyter-return-delayed nil))))
(ert-info ("Shutdown") (ert-info ("Shutdown")
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((res (jupyter-reply (jupyter-mlet* ((res (jupyter-reply
@ -457,7 +465,7 @@
(should (json-plist-p res)) (should (json-plist-p res))
(should (string= (jupyter-message-type res) "shutdown_reply")) (should (string= (jupyter-message-type res) "shutdown_reply"))
;; TODO: Ensure we give the kernel process time to die off ;; TODO: Ensure we give the kernel process time to die off
))))) (jupyter-return-delayed nil))))))
(ert-deftest jupyter-message-lambda () (ert-deftest jupyter-message-lambda ()
:tags '(messages) :tags '(messages)
@ -865,7 +873,8 @@
req (jupyter-test-message req (jupyter-test-message
req "stream" (list :name "stdout" :text "foo")))) req "stream" (list :name "stdout" :text "foo"))))
(should-error (jupyter-kernel-info-request (should-error (jupyter-kernel-info-request
:handlers '(not "foo"))))))) :handlers '(not "foo")))
(jupyter-return-delayed nil)))))
(ert-deftest jupyter-eval () (ert-deftest jupyter-eval ()
:tags '(client) :tags '(client)
@ -921,7 +930,8 @@
(jupyter-mlet* ((req (jupyter-sent (jupyter-execute-request :code "1 + 1")))) (jupyter-mlet* ((req (jupyter-sent (jupyter-execute-request :code "1 + 1"))))
(should-not (jupyter-request-idle-p req)) (should-not (jupyter-request-idle-p req))
(jupyter-idle-sync req) (jupyter-idle-sync req)
(should (jupyter-request-idle-p req)))) (should (jupyter-request-idle-p req))
(jupyter-return-delayed nil)))
(jupyter-run-with-client client (jupyter-run-with-client client
(jupyter-mlet* ((req (jupyter-sent (jupyter-execute-request :code "1 + 1")))) (jupyter-mlet* ((req (jupyter-sent (jupyter-execute-request :code "1 + 1"))))
(should (null jupyter-test-idle-sync-hook)) (should (null jupyter-test-idle-sync-hook))
@ -930,7 +940,8 @@
(should-not (jupyter-request-idle-p req)) (should-not (jupyter-request-idle-p req))
(run-hooks 'jupyter-test-idle-sync-hook) (run-hooks 'jupyter-test-idle-sync-hook)
(should (jupyter-request-idle-p req)) (should (jupyter-request-idle-p req))
(should (null jupyter-test-idle-sync-hook)))))) (should (null jupyter-test-idle-sync-hook))
(jupyter-return-delayed nil)))))
;;; IOloop ;;; IOloop
@ -1104,7 +1115,8 @@
(jupyter-sent (jupyter-execute-request :code "1 + 1")))) (jupyter-sent (jupyter-execute-request :code "1 + 1"))))
(res (jupyter-result (res (jupyter-result
(jupyter-execute-request :code "1 + 1")))) (jupyter-execute-request :code "1 + 1"))))
(should (equal (jupyter-message-data res :text/plain) "2")))) (should (equal (jupyter-message-data res :text/plain) "2"))
(jupyter-return-delayed nil)))
(jupyter-shutdown-kernel client)))) (jupyter-shutdown-kernel client))))
;;; Completion ;;; Completion