aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/progmodes/python-tests.el
diff options
context:
space:
mode:
authorLiu Hui2024-02-21 12:40:06 +0800
committerBasil L. Contovounesios2024-02-28 15:25:56 +0100
commit8a2d013be37d8c3d3a25cfe1da505cd2e27dda5c (patch)
tree220856fb62319b3eb87c0cd03382fc81ee0eb88e /test/lisp/progmodes/python-tests.el
parent3412b64ac8851a0fa8e55c6319d2e710ae27a74c (diff)
downloademacs-8a2d013be37d8c3d3a25cfe1da505cd2e27dda5c.tar.gz
emacs-8a2d013be37d8c3d3a25cfe1da505cd2e27dda5c.zip
Fix Python shell completion test failures
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-buffer-with-shell): Set XDG_CACHE_HOME to a temporary directory. (python-tests--pythonstartup-file): New function. (python-shell-completion-at-point-jedi-completer) (python-shell-completion-at-point-ipython): Use Jedi as the native completion backend when possible. (bug#68559)
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
-rw-r--r--test/lisp/progmodes/python-tests.el87
1 files changed, 53 insertions, 34 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 6c6cd9eee2b..1ceee690cfb 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -55,21 +55,27 @@ BODY is code to be executed within the temp buffer. Point is
55always located at the beginning of buffer. Native completion is 55always located at the beginning of buffer. Native completion is
56turned off. Shell buffer will be killed on exit." 56turned off. Shell buffer will be killed on exit."
57 (declare (indent 1) (debug t)) 57 (declare (indent 1) (debug t))
58 `(with-temp-buffer 58 (let ((dir (make-symbol "dir")))
59 (let ((python-indent-guess-indent-offset nil) 59 `(with-temp-buffer
60 (python-shell-completion-native-enable nil)) 60 (let ((python-indent-guess-indent-offset nil)
61 (python-mode) 61 (python-shell-completion-native-enable nil))
62 (unwind-protect 62 (python-mode)
63 (progn 63 (unwind-protect
64 (run-python nil t) 64 ;; Prevent test failures when Jedi is used as a completion
65 (insert ,contents) 65 ;; backend, either directly or indirectly (e.g., via
66 (goto-char (point-min)) 66 ;; IPython). Jedi needs to store cache, but the
67 (python-tests-shell-wait-for-prompt) 67 ;; "/nonexistent" HOME directory is not writable.
68 ,@body) 68 (ert-with-temp-directory ,dir
69 (when (python-shell-get-buffer) 69 (with-environment-variables (("XDG_CACHE_HOME" ,dir))
70 (python-shell-with-shell-buffer 70 (run-python nil t)
71 (let (kill-buffer-hook kill-buffer-query-functions) 71 (insert ,contents)
72 (kill-buffer)))))))) 72 (goto-char (point-min))
73 (python-tests-shell-wait-for-prompt)
74 ,@body))
75 (when (python-shell-get-buffer)
76 (python-shell-with-shell-buffer
77 (let (kill-buffer-hook kill-buffer-query-functions)
78 (kill-buffer)))))))))
73 79
74(defmacro python-tests-with-temp-file (contents &rest body) 80(defmacro python-tests-with-temp-file (contents &rest body)
75 "Create a `python-mode' enabled file with CONTENTS. 81 "Create a `python-mode' enabled file with CONTENTS.
@@ -4860,17 +4866,28 @@ def foo():
4860 (should (string= "IGNORECASE" 4866 (should (string= "IGNORECASE"
4861 (buffer-substring (line-beginning-position) (point))))) 4867 (buffer-substring (line-beginning-position) (point)))))
4862 4868
4869(defun python-tests--pythonstartup-file ()
4870 "Return Jedi readline setup file if PYTHONSTARTUP is not set."
4871 (or (getenv "PYTHONSTARTUP")
4872 (with-temp-buffer
4873 (if (eql 0 (call-process python-tests-shell-interpreter
4874 nil t nil "-m" "jedi" "repl"))
4875 (string-trim (buffer-string))
4876 ""))))
4877
4863(ert-deftest python-shell-completion-at-point-jedi-completer () 4878(ert-deftest python-shell-completion-at-point-jedi-completer ()
4864 "Check if Python shell completion works when Jedi completer is used." 4879 "Check if Python shell completion works when Jedi completer is used."
4865 (skip-unless (executable-find python-tests-shell-interpreter)) 4880 (skip-unless (executable-find python-tests-shell-interpreter))
4866 (python-tests-with-temp-buffer-with-shell 4881 (with-environment-variables
4867 "" 4882 (("PYTHONSTARTUP" (python-tests--pythonstartup-file)))
4868 (python-shell-with-shell-buffer 4883 (python-tests-with-temp-buffer-with-shell
4869 (python-shell-completion-native-turn-on) 4884 ""
4870 (skip-unless (string= python-shell-readline-completer-delims "")) 4885 (python-shell-with-shell-buffer
4871 (python-tests--completion-module) 4886 (python-shell-completion-native-turn-on)
4872 (python-tests--completion-parameters) 4887 (skip-unless (string= python-shell-readline-completer-delims ""))
4873 (python-tests--completion-extra-context)))) 4888 (python-tests--completion-module)
4889 (python-tests--completion-parameters)
4890 (python-tests--completion-extra-context)))))
4874 4891
4875(ert-deftest python-shell-completion-at-point-ipython () 4892(ert-deftest python-shell-completion-at-point-ipython ()
4876 "Check if Python shell completion works for IPython." 4893 "Check if Python shell completion works for IPython."
@@ -4880,17 +4897,19 @@ def foo():
4880 (and 4897 (and
4881 (executable-find python-shell-interpreter) 4898 (executable-find python-shell-interpreter)
4882 (eql (call-process python-shell-interpreter nil nil nil "--version") 0))) 4899 (eql (call-process python-shell-interpreter nil nil nil "--version") 0)))
4883 (python-tests-with-temp-buffer-with-shell 4900 (with-environment-variables
4884 "" 4901 (("PYTHONSTARTUP" (python-tests--pythonstartup-file)))
4885 (python-shell-with-shell-buffer 4902 (python-tests-with-temp-buffer-with-shell
4886 (python-shell-completion-native-turn-off) 4903 ""
4887 (python-tests--completion-module) 4904 (python-shell-with-shell-buffer
4888 (python-tests--completion-parameters) 4905 (python-shell-completion-native-turn-off)
4889 (python-shell-completion-native-turn-on) 4906 (python-tests--completion-module)
4890 (skip-unless (string= python-shell-readline-completer-delims "")) 4907 (python-tests--completion-parameters)
4891 (python-tests--completion-module) 4908 (python-shell-completion-native-turn-on)
4892 (python-tests--completion-parameters) 4909 (skip-unless (string= python-shell-readline-completer-delims ""))
4893 (python-tests--completion-extra-context))))) 4910 (python-tests--completion-module)
4911 (python-tests--completion-parameters)
4912 (python-tests--completion-extra-context))))))
4894 4913
4895 4914
4896;;; PDB Track integration 4915;;; PDB Track integration