mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 09:31:39 -05:00
Add tests for ein:cell-to-json
This commit is contained in:
parent
173dc7f389
commit
0e086985ea
1 changed files with 85 additions and 0 deletions
|
@ -1,6 +1,11 @@
|
||||||
(eval-when-compile (require 'cl))
|
(eval-when-compile (require 'cl))
|
||||||
(require 'ert)
|
(require 'ert)
|
||||||
|
|
||||||
|
(when load-file-name
|
||||||
|
(add-to-list 'load-path
|
||||||
|
(concat (file-name-directory load-file-name) "mocker")))
|
||||||
|
(require 'mocker)
|
||||||
|
|
||||||
(require 'ein-cell)
|
(require 'ein-cell)
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,6 +76,86 @@
|
||||||
(should (ein:headingcell-p cell))
|
(should (ein:headingcell-p cell))
|
||||||
(should (equal (oref cell :input) input))))
|
(should (equal (oref cell :input) input))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ein:cell-to-json
|
||||||
|
|
||||||
|
(ert-deftest ein:cell-to-json-code ()
|
||||||
|
(let* ((input-prompt-number 111)
|
||||||
|
(output-prompt-number 222)
|
||||||
|
(input (ein:join-str "\n" '("first input" "second input")))
|
||||||
|
(output-0 (list :output_type "pyout"
|
||||||
|
:prompt_number output-prompt-number
|
||||||
|
:text (list "first output"
|
||||||
|
"second output")))
|
||||||
|
(data (eintest:cell-json-data-code
|
||||||
|
input-prompt-number input (list output-0)))
|
||||||
|
(cell (eintest:cell-from-json data))
|
||||||
|
(alist (mocker-let ((ein:cell-get-text
|
||||||
|
(cell)
|
||||||
|
((:input (list cell) :output input))))
|
||||||
|
(ein:cell-to-json cell))))
|
||||||
|
(should (equal (cdr (assq 'input alist)) "first input\nsecond input"))
|
||||||
|
(should (equal (cdr (assq 'cell_type alist)) "code"))
|
||||||
|
(should (equal (cdr (assq 'outputs alist)) `[,output-0]))
|
||||||
|
(should (equal (cdr (assq 'language alist)) "python"))
|
||||||
|
(should (equal (cdr (assq 'collapsed alist)) json-false))))
|
||||||
|
|
||||||
|
(ert-deftest ein:cell-to-json-text ()
|
||||||
|
(let* ((input (ein:join-str "\n" '("first input" "second input")))
|
||||||
|
(data (list :cell_type "text" :source input))
|
||||||
|
(cell (eintest:cell-from-json data))
|
||||||
|
(alist (mocker-let ((ein:cell-get-text
|
||||||
|
(cell)
|
||||||
|
((:input (list cell) :output input))))
|
||||||
|
(ein:cell-to-json cell))))
|
||||||
|
(should (equal (cdr (assq 'cell_type alist)) "text"))
|
||||||
|
(should (equal (cdr (assq 'source alist)) "first input\nsecond input"))))
|
||||||
|
|
||||||
|
(ert-deftest ein:cell-to-json-html ()
|
||||||
|
(let* ((input (ein:join-str "\n" '("first input" "second input")))
|
||||||
|
(data (list :cell_type "html" :source input))
|
||||||
|
(cell (eintest:cell-from-json data))
|
||||||
|
(alist (mocker-let ((ein:cell-get-text
|
||||||
|
(cell)
|
||||||
|
((:input (list cell) :output input))))
|
||||||
|
(ein:cell-to-json cell))))
|
||||||
|
(should (equal (cdr (assq 'cell_type alist)) "html"))
|
||||||
|
(should (equal (cdr (assq 'source alist)) "first input\nsecond input"))))
|
||||||
|
|
||||||
|
(ert-deftest ein:cell-to-json-markdown ()
|
||||||
|
(let* ((input (ein:join-str "\n" '("first input" "second input")))
|
||||||
|
(data (list :cell_type "markdown" :source input))
|
||||||
|
(cell (eintest:cell-from-json data))
|
||||||
|
(alist (mocker-let ((ein:cell-get-text
|
||||||
|
(cell)
|
||||||
|
((:input (list cell) :output input))))
|
||||||
|
(ein:cell-to-json cell))))
|
||||||
|
(should (equal (cdr (assq 'cell_type alist)) "markdown"))
|
||||||
|
(should (equal (cdr (assq 'source alist)) "first input\nsecond input"))))
|
||||||
|
|
||||||
|
(ert-deftest ein:cell-to-json-raw ()
|
||||||
|
(let* ((input (ein:join-str "\n" '("first input" "second input")))
|
||||||
|
(data (list :cell_type "raw" :source input))
|
||||||
|
(cell (eintest:cell-from-json data))
|
||||||
|
(alist (mocker-let ((ein:cell-get-text
|
||||||
|
(cell)
|
||||||
|
((:input (list cell) :output input))))
|
||||||
|
(ein:cell-to-json cell))))
|
||||||
|
(should (equal (cdr (assq 'cell_type alist)) "raw"))
|
||||||
|
(should (equal (cdr (assq 'source alist)) "first input\nsecond input"))))
|
||||||
|
|
||||||
|
(ert-deftest ein:cell-to-json-heading ()
|
||||||
|
(let* ((input (ein:join-str "\n" '("first input" "second input")))
|
||||||
|
(data (list :cell_type "heading" :source input))
|
||||||
|
(cell (eintest:cell-from-json data))
|
||||||
|
(alist (mocker-let ((ein:cell-get-text
|
||||||
|
(cell)
|
||||||
|
((:input (list cell) :output input))))
|
||||||
|
(ein:cell-to-json cell))))
|
||||||
|
(should (equal (cdr (assq 'cell_type alist)) "heading"))
|
||||||
|
(should (equal (cdr (assq 'source alist)) "first input\nsecond input"))
|
||||||
|
(should (equal (cdr (assq 'level alist)) 1))))
|
||||||
|
|
||||||
|
|
||||||
;;; ein:cell-convert/copy
|
;;; ein:cell-convert/copy
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue