`python-shell-send-buffer' from time to time so context in
inferior Python process is updated properly."
(let ((process (python-shell-get-process)))
- (when process
+ (when (and process
+ (python-shell-with-shell-buffer
+ (python-util-comint-end-of-output-p)))
(python-shell-completion-at-point process))))
(define-obsolete-function-alias
(defun python-ffap-module-path (module)
"Function for `ffap-alist' to return path for MODULE."
(when-let ((process (python-shell-get-process))
+ (ready (python-shell-with-shell-buffer
+ (python-util-comint-end-of-output-p)))
(module-file
(python-shell-send-string-no-output
(format "%s\nprint(__FFAP_get_module_path(%s))"
returns will be used. If not FORCE-PROCESS is passed what
`python-shell-get-process' returns is used."
(let ((process (or force-process (python-shell-get-process))))
- (when process
+ (when (and process
+ (python-shell-with-shell-buffer
+ (python-util-comint-end-of-output-p)))
(let* ((input (or force-input
(python-eldoc--get-symbol-at-point)))
(docstring
comint-last-prompt)
(t nil)))
+(defun python-util-comint-end-of-output-p ()
+ "Return non-nil if the last prompt matches input prompt."
+ (when-let ((prompt (python-util-comint-last-prompt)))
+ (python-shell-comint-end-of-output-p
+ (buffer-substring-no-properties
+ (car prompt) (cdr prompt)))))
+
(defun python-util-forward-comment (&optional direction)
"Python mode specific version of `forward-comment'.
Optional argument DIRECTION defines the direction to move to."
(defun python-tests-shell-wait-for-prompt ()
"Wait for the prompt in the shell buffer."
(python-shell-with-shell-buffer
- (while (not (if-let ((prompt (python-util-comint-last-prompt)))
- (python-shell-comint-end-of-output-p
- (buffer-substring-no-properties
- (car prompt) (cdr prompt)))))
+ (while (not (python-util-comint-end-of-output-p))
(sit-for 0.1))))
(defmacro python-tests-with-temp-buffer-with-shell (contents &rest body)
(insert "u")
(should-not (nth 2 (python-completion-at-point))))))
+(ert-deftest python-completion-at-point-while-running-1 ()
+ "Should not try to complete when a program is running in the Shell buffer."
+ (skip-unless (executable-find python-tests-shell-interpreter))
+ (python-tests-with-temp-buffer-with-shell
+ "
+import time
+
+time.sleep(3)
+"
+ (let ((inhibit-message t))
+ (python-shell-send-buffer)
+ (goto-char (point-max))
+ (insert "time.")
+ (should-not (with-timeout (1 t) (completion-at-point))))))
+
(ert-deftest python-completion-at-point-native-1 ()
(skip-unless (executable-find python-tests-shell-interpreter))
(python-tests-with-temp-buffer-with-shell
\f
;;; FFAP
+(ert-deftest python-ffap-module-path-1 ()
+ (skip-unless (executable-find python-tests-shell-interpreter))
+ (python-tests-with-temp-buffer-with-shell
+ "
+import abc
+"
+ (let ((inhibit-message t))
+ (python-shell-send-buffer)
+ (python-tests-shell-wait-for-prompt)
+ (should (file-exists-p (python-ffap-module-path "abc"))))))
+
+(ert-deftest python-ffap-module-path-while-running-1 ()
+ "Should not get module path when a program is running in the Shell buffer."
+ (skip-unless (executable-find python-tests-shell-interpreter))
+ (python-tests-with-temp-buffer-with-shell
+ "
+import abc
+import time
+
+time.sleep(3)
+"
+ (let ((inhibit-message t))
+ (python-shell-send-buffer)
+ (should-not (with-timeout (1 t) (python-ffap-module-path "abc"))))))
+
\f
;;; Code check
(should (string= (python-eldoc--get-symbol-at-point)
"some_symbol"))))
+(ert-deftest python-eldoc--get-doc-at-point-1 ()
+ (skip-unless (executable-find python-tests-shell-interpreter))
+ (python-tests-with-temp-buffer-with-shell
+ "
+import time
+"
+ (let ((inhibit-message t))
+ (python-shell-send-buffer)
+ (python-tests-shell-wait-for-prompt)
+ (python-tests-look-at "time")
+ (should (python-eldoc--get-doc-at-point)))))
+
+(ert-deftest python-eldoc--get-doc-at-point-while-running-1 ()
+ "Should not get documentation when a program is running in the Shell buffer."
+ (skip-unless (executable-find python-tests-shell-interpreter))
+ (python-tests-with-temp-buffer-with-shell
+ "
+import time
+
+time.sleep(3)
+"
+ (let ((inhibit-message t))
+ (python-shell-send-buffer)
+ (python-tests-look-at "time")
+ (should-not (with-timeout (1 t) (python-eldoc--get-doc-at-point))))))
+
\f
;;; Imenu