add org-export test

This commit is contained in:
dickmao 2019-08-10 18:00:03 -04:00
parent cfd7a9a117
commit 2ca536fdec
6 changed files with 83 additions and 31 deletions

View file

@ -148,3 +148,27 @@ Scenario: portless url with path, image, C-c ' lets you C-c C-c as well
And I ctrl-c-ctrl-c
And I dump buffer
And I wait for buffer to say "file:ein-image"
@export
Scenario: Test ob-exp captures code and results.
When I open temp file "ecukes.org"
And I call "org-mode"
And I type "<s"
And I press "TAB"
And I type "ein :results scalar :exports both"
And I press "C-n"
And I type "ratio = (1 + 5 ** 0.5) / 2"
And I press "RET"
And I type "ratio"
And I ctrl-c-ctrl-c
And I wait for buffer to say "1.618"
And I press "M->"
And I press "RET"
And I press "RET"
And I type "<s"
And I press "TAB"
And I type "ein :results scalar :exports both"
And I press "RET"
And I type "ratio"
And I dump buffer
And I call "org-latex-export-to-latex"

View file

@ -45,7 +45,6 @@
(defun ein:testing-after-scenario ()
(ein:testing-flush-queries)
(with-current-buffer (ein:notebooklist-get-buffer (car (ein:jupyter-server-conn-info)))
(if ein:%notebooklist%
(loop for notebook in (ein:notebook-opened-notebooks)
for path = (ein:$notebook-notebook-path notebook)
do (ein:notebook-kill-kernel-then-close-command notebook)
@ -54,7 +53,9 @@
do (sleep-for 0 1000)
finally do (when (ein:notebook-live-p notebook)
(ein:display-warning (format "cannot close %s" path))))
do (when (or (search "Untitled" path) (search "Renamed" path))
do (when (or (ob-ein-anonymous-p path)
(search "Untitled" path)
(search "Renamed" path))
(ein:notebooklist-delete-notebook path)
(loop repeat 16
with fullpath = (concat (file-name-as-directory ein:testing-jupyter-server-root) path)
@ -62,7 +63,7 @@
until (not extant)
do (sleep-for 0 1000)
finally do (when extant
(ein:display-warning (format "cannot del %s" path))))))))
(ein:display-warning (format "cannot del %s" path)))))))
(ein:aif (ein:notebook-opened-notebooks)
(loop for nb in it
for path = (ein:$notebook-notebook-path nb)

View file

@ -134,9 +134,10 @@
(ein:log 'verbose "ein:completions--prepare-oinfo: %s"
(plist-get content :traceback)))))
(error
(ein:log 'verbose "ein:completions--prepare-oinfo: [%s]"
(error-message-string err))
(let (eval-expression-print-length eval-expression-print-level)
(ein:log 'verbose "ein:completions--prepare-oinfo: [%s] %s"
(error-message-string err) output))
(prin1 output #'external-debugging-output))
(setf (gethash obj (ein:$kernel-oinfo-cache kernel)) :json-false))))
;;; Support for Eldoc

View file

@ -221,7 +221,7 @@ the log of the running jupyter server."
(list 'shutdown-server url-or-port)
(ein:url url-or-port "api/shutdown")
:type "POST"
:timeout 10 ;; content-query-timeout and query-timeout default nil
:timeout 3 ;; content-query-timeout and query-timeout default nil
:sync t))
;;;###autoload
@ -235,7 +235,7 @@ the log of the running jupyter server."
until (zerop (hash-table-count ein:query-running-process-table))
do (sleep-for 0 500))
(ein:shutdown-server url-or-port)
(loop repeat 10
(loop repeat 3
for proc = (ein:jupyter-server-process)
until (not proc)
do (sleep-for 0 1000)

View file

@ -162,11 +162,6 @@ Called from ewoc pretty printer via `ein:cell-pp'."
Create a cell if the buffer has none."
(slot-value (ein:shared-output-get-or-create) 'cell))
(defun ein:shared-output-get-kernel ()
(let ((cell (ein:shared-output-get-cell)))
(when (slot-boundp cell :kernel)
(slot-value cell 'kernel))))
;;;###autoload
(defun ein:shared-output-pop-to-buffer ()
"Open shared output buffer."

View file

@ -42,6 +42,11 @@
(defvar *ob-ein-sentinel* "[....]"
"Placeholder string replaced after async cell execution")
(defcustom ob-ein-timeout-seconds 600
"Maximum seconds to wait for block to finish (for synchronous operations)."
:type 'integer
:group 'ein)
(defcustom ob-ein-languages
'(("ein" . python)
("ein-python" . python)
@ -180,8 +185,33 @@ Based on ob-ipython--configure-kernel."
processed-params
result-params
name))))
(ob-ein--initiate-session session kernelspec callback))
*ob-ein-sentinel*)
(save-excursion
(cl-assert (not (stringp (org-babel-goto-named-src-block name))))
(org-babel-insert-result *ob-ein-sentinel* result-params))
(ob-ein--initiate-session session kernelspec callback)
(if (ein:eval-if-bound 'org-current-export-file)
(save-excursion
(loop with interval = 2000
with pending = t
repeat (/ (* ob-ein-timeout-seconds 1000) interval)
do (progn
(org-babel-goto-named-result name)
(forward-line 1)
(setq pending (re-search-forward
(regexp-quote *ob-ein-sentinel*)
(org-babel-result-end) t)))
until (not pending)
do (sleep-for 0 interval)
finally return
(if pending
(progn
(ein:log 'error "ob-ein--execute-body: %s timed out" name)
"")
(ob-ein--process-outputs
(ein:oref-safe (ein:shared-output-get-cell) 'outputs)
processed-params))))
(org-babel-remove-result)
*ob-ein-sentinel*)))
(defsubst ob-ein--execute-async-callback (buffer params result-params name)
"Callback of 1-arity (the shared output cell) to update org buffer when
@ -198,11 +228,11 @@ Based on ob-ipython--configure-kernel."
(org-babel-result-cond result-params*
raw (org-babel-import-elisp-from-file tmp-file '(16)))))
(info (org-babel-get-src-block-info 'light)))
(ein:log 'debug "ob-ein--execute-async-callback %s %s" name* result)
(ein:log 'debug "ob-ein--execute-async-callback %s \"%s\" %s" name* result buffer*)
(save-excursion
(save-restriction
(with-current-buffer buffer*
(when (not (stringp (org-babel-goto-named-src-block name*)))
(unless (stringp (org-babel-goto-named-src-block name*)) ;; stringp=error
(when info ;; kill #+RESULTS: (no-name)
(setf (nth 4 info) nil)
(org-babel-remove-result info))
@ -226,6 +256,7 @@ one at a time. Further, we do not order the queued up blocks!"
(ob-ein--execute-async-callback buffer params
result-params name)))
(setf (slot-value cell 'callback) callback))
;; still pending previous callback
(deferred:nextc (deferred:wait 1200) self)))))
(deferred:nextc it
(lambda (_x)