diff options
| author | kobarity | 2022-10-10 22:24:17 +0900 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-10-11 02:29:42 +0200 |
| commit | b0585441a321a144f2bbdc269b3cfc6c14bab7cf (patch) | |
| tree | f5ca93b995d817a6c3a90f22d7de399f67470198 /test/lisp/progmodes/python-tests.el | |
| parent | 36ab1644964ae5a933bd9808536f60d4ae64c99f (diff) | |
| download | emacs-b0585441a321a144f2bbdc269b3cfc6c14bab7cf.tar.gz emacs-b0585441a321a144f2bbdc269b3cfc6c14bab7cf.zip | |
Fix Python completion failure under certain conditions
* lisp/progmodes/python.el (python-shell-send-string-no-output):
Save and restore `comint-last-prompt-overlay' or `comint-last-prompt'.
* test/lisp/progmodes/python-tests.el (python-tests-shell-wait-for-prompt):
New helper function.
(python-tests-with-temp-buffer-with-shell): New helper macro.
(python-shell-completion-1, python-shell-completion-native-1)
(python-shell-completion-native-with-ffap-1)
(python-shell-completion-native-with-eldoc-1): New tests (bug#58389).
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
| -rw-r--r-- | test/lisp/progmodes/python-tests.el | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index fdaedb5fd7a..60ff9bb613a 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el | |||
| @@ -43,6 +43,37 @@ always located at the beginning of buffer." | |||
| 43 | (goto-char (point-min)) | 43 | (goto-char (point-min)) |
| 44 | ,@body))) | 44 | ,@body))) |
| 45 | 45 | ||
| 46 | (defun python-tests-shell-wait-for-prompt () | ||
| 47 | "Wait for the prompt in the shell buffer." | ||
| 48 | (python-shell-with-shell-buffer | ||
| 49 | (while (not (if-let ((prompt (python-util-comint-last-prompt))) | ||
| 50 | (python-shell-comint-end-of-output-p | ||
| 51 | (buffer-substring-no-properties | ||
| 52 | (car prompt) (cdr prompt))))) | ||
| 53 | (sit-for 0.1)))) | ||
| 54 | |||
| 55 | (defmacro python-tests-with-temp-buffer-with-shell (contents &rest body) | ||
| 56 | "Create a `python-mode' enabled temp buffer with CONTENTS and `run-python'. | ||
| 57 | BODY is code to be executed within the temp buffer. Point is | ||
| 58 | always located at the beginning of buffer. Native completion is | ||
| 59 | turned off. Shell buffer will be killed on exit." | ||
| 60 | (declare (indent 1) (debug t)) | ||
| 61 | `(with-temp-buffer | ||
| 62 | (let ((python-indent-guess-indent-offset nil) | ||
| 63 | (python-shell-completion-native-enable nil)) | ||
| 64 | (python-mode) | ||
| 65 | (unwind-protect | ||
| 66 | (progn | ||
| 67 | (run-python nil t) | ||
| 68 | (insert ,contents) | ||
| 69 | (goto-char (point-min)) | ||
| 70 | (python-tests-shell-wait-for-prompt) | ||
| 71 | ,@body) | ||
| 72 | (when (python-shell-get-buffer) | ||
| 73 | (python-shell-with-shell-buffer | ||
| 74 | (let (kill-buffer-hook kill-buffer-query-functions) | ||
| 75 | (kill-buffer)))))))) | ||
| 76 | |||
| 46 | (defmacro python-tests-with-temp-file (contents &rest body) | 77 | (defmacro python-tests-with-temp-file (contents &rest body) |
| 47 | "Create a `python-mode' enabled file with CONTENTS. | 78 | "Create a `python-mode' enabled file with CONTENTS. |
| 48 | BODY is code to be executed within the temp buffer. Point is | 79 | BODY is code to be executed within the temp buffer. Point is |
| @@ -4365,6 +4396,68 @@ def foo(): | |||
| 4365 | (python-shell-interpreter "/some/path/to/bin/pypy")) | 4396 | (python-shell-interpreter "/some/path/to/bin/pypy")) |
| 4366 | (should (python-shell-completion-native-interpreter-disabled-p)))) | 4397 | (should (python-shell-completion-native-interpreter-disabled-p)))) |
| 4367 | 4398 | ||
| 4399 | (ert-deftest python-shell-completion-1 () | ||
| 4400 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4401 | (python-tests-with-temp-buffer-with-shell | ||
| 4402 | " | ||
| 4403 | import abc | ||
| 4404 | " | ||
| 4405 | (let ((inhibit-message t)) | ||
| 4406 | (python-shell-send-buffer) | ||
| 4407 | (python-tests-shell-wait-for-prompt) | ||
| 4408 | (goto-char (point-max)) | ||
| 4409 | (insert "abc.") | ||
| 4410 | (should (completion-at-point)) | ||
| 4411 | (insert "A") | ||
| 4412 | (should (completion-at-point))))) | ||
| 4413 | |||
| 4414 | (ert-deftest python-shell-completion-native-1 () | ||
| 4415 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4416 | (python-tests-with-temp-buffer-with-shell | ||
| 4417 | " | ||
| 4418 | import abc | ||
| 4419 | " | ||
| 4420 | (let ((inhibit-message t)) | ||
| 4421 | (python-shell-completion-native-turn-on) | ||
| 4422 | (python-shell-send-buffer) | ||
| 4423 | (python-tests-shell-wait-for-prompt) | ||
| 4424 | (goto-char (point-max)) | ||
| 4425 | (insert "abc.") | ||
| 4426 | (should (completion-at-point)) | ||
| 4427 | (insert "A") | ||
| 4428 | (should (completion-at-point))))) | ||
| 4429 | |||
| 4430 | (ert-deftest python-shell-completion-native-with-ffap-1 () | ||
| 4431 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4432 | (python-tests-with-temp-buffer-with-shell | ||
| 4433 | " | ||
| 4434 | import abc | ||
| 4435 | " | ||
| 4436 | (let ((inhibit-message t)) | ||
| 4437 | (python-shell-completion-native-turn-on) | ||
| 4438 | (python-shell-send-buffer) | ||
| 4439 | (python-tests-shell-wait-for-prompt) | ||
| 4440 | (goto-char (point-max)) | ||
| 4441 | (insert "abc.") | ||
| 4442 | ;; This is called when FFAP is enabled and a find-file function is called. | ||
| 4443 | (python-ffap-module-path "abc.") | ||
| 4444 | (should (completion-at-point))))) | ||
| 4445 | |||
| 4446 | (ert-deftest python-shell-completion-native-with-eldoc-1 () | ||
| 4447 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 4448 | (python-tests-with-temp-buffer-with-shell | ||
| 4449 | " | ||
| 4450 | import abc | ||
| 4451 | " | ||
| 4452 | (let ((inhibit-message t)) | ||
| 4453 | (python-shell-completion-native-turn-on) | ||
| 4454 | (python-shell-send-buffer) | ||
| 4455 | (python-tests-shell-wait-for-prompt) | ||
| 4456 | (goto-char (point-max)) | ||
| 4457 | (insert "abc.") | ||
| 4458 | ;; This is called by idle-timer when ElDoc is enabled. | ||
| 4459 | (python-eldoc-function) | ||
| 4460 | (should (completion-at-point))))) | ||
| 4368 | 4461 | ||
| 4369 | 4462 | ||
| 4370 | 4463 | ||