Skip to content

Commit

Permalink
Add tests to cover changes from 1922e5b
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Nov 1, 2019
1 parent 1922e5b commit 361c212
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
58 changes: 31 additions & 27 deletions test/elpy-shell-echo-inputs-and-outputs-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
(elpy-mode)
(setq elpy-shell-echo-input nil)
(setq elpy-shell-echo-output nil)
(insert "def foo():
1+1
for i in range(10):
a = 2+2
4+3
b = a+i
")
(insert "def foo(d):\n"
" 1+1\n"
" for i in range(10):\n"
" a = 2+2\n"
" 4+3\n"
" b = a+i\n")

;; on "for i in range(10):"
(goto-char 30)
Expand All @@ -31,13 +30,13 @@
(elpy-mode)
(setq elpy-shell-echo-input t)
(setq elpy-shell-echo-output nil)
(insert "def foo():
1+1
for i in range(10):
a = 2+2
4+3
b = a+i
")
(insert "def foo(d):\n"
" 1+1\n"
" for i in range(10):\n"
" a = 2+2\n"
" 4+3\n"
" b = a+i\n"
"foo(d=14)")
;; on "for i in range(10):"
(goto-char 30)
(elpy-shell-kill t)
Expand All @@ -61,9 +60,7 @@
(elpy/wait-for-output "OK" 30)
(buffer-string))))
;; on "a = 2+2" and "4+3" lines
(set-mark 52)
(goto-char 72)
(activate-mark)
(elpy/mark-region 52 72)
(elpy-shell-kill t)
(elpy-shell-send-region-or-buffer)
(python-shell-send-string "print('OK')\n")
Expand All @@ -74,6 +71,16 @@
(should (string-match "...: 4\\+3"
(with-current-buffer "*Python*"
(buffer-string))))
;; on a portion of line "d=14"
(elpy/mark-region 93 97)
(elpy-shell-kill t)
(elpy-shell-send-region-or-buffer)
(python-shell-send-string "print('OK')\n")
(python-shell-send-string "print(d)\n")
(should (string-match ">>> 14"
(with-current-buffer "*Python*"
(elpy/wait-for-output "OK" 30)
(buffer-string))))
)))

(ert-deftest elpy-shell-should-echo-outputs ()
Expand All @@ -83,13 +90,12 @@
(elpy-mode)
(setq elpy-shell-echo-input nil)
(setq elpy-shell-echo-output t)
(insert "def foo():
1+1
for i in range(10):
a = 2+2
4+3
b = a+i
")
(insert "def foo(d):\n"
" 1+1\n"
" for i in range(10):\n"
" a = 2+2\n"
" 4+3\n"
" b = a+i")

;; on "1+1"
(goto-char 18)
Expand All @@ -108,9 +114,7 @@
(elpy/wait-for-output "OK" 30)
(buffer-string))))
;; on "a = 2+2" and "4+3" lines
(set-mark 52)
(goto-char 72)
(activate-mark)
(elpy/mark-region 52 72)
(elpy-shell-kill t)
(elpy-shell-send-region-or-buffer)
(python-shell-send-string "print('OK')\n")
Expand Down
16 changes: 16 additions & 0 deletions test/elpy-shell-send-region-or-buffer-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
(should (string-match "Only region sent" output))
(should (not (string-match "Whole buffer sent" output))))))

(ert-deftest elpy-shell-send-region-or-buffer-should-send-portion-of-line ()
(elpy-testcase ()
(python-mode)
(elpy-mode)
(insert "def foo(a, b):\n"
" return a[0] + b[0]\n"
"foo(a=[1, 2, 3], b=[1, 2])")
(elpy/mark-region 41 52)
(elpy-shell-send-region-or-buffer)
(python-shell-send-string "print(a)")
(python-shell-send-string "print('OK')")
(let ((output (with-current-buffer "*Python*"
(elpy/wait-for-output "OK")
(buffer-substring-no-properties (point-min) (point-max)))))
(should (string-match ">>> \\[1, 2, 3\\]" output)))))

(ert-deftest elpy-shell-send-region-or-buffer-should-display-but-not-select-buffer ()
(elpy-testcase ()
(python-mode)
Expand Down

0 comments on commit 361c212

Please sign in to comment.