aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/progmodes/python-tests.el
diff options
context:
space:
mode:
authorLiu Hui2024-01-18 12:00:00 +0800
committerEli Zaretskii2024-02-08 14:09:42 +0200
commit0b9c7148fd681c8ad63fd0eb3895db44403e9f8c (patch)
treed454370049b289722ba06e2777e6006fcf762917 /test/lisp/progmodes/python-tests.el
parentebf4ef2022a5f0a69cdd881eb41104e7b59d698e (diff)
downloademacs-0b9c7148fd681c8ad63fd0eb3895db44403e9f8c.tar.gz
emacs-0b9c7148fd681c8ad63fd0eb3895db44403e9f8c.zip
Respect the delimiter of completer in Python shell completion
* lisp/progmodes/python.el: (python-shell-completion-setup-code): Fix the completion code of IPython. Change the return value to JSON string and ... (python-shell-completion-get-completions): ... simplify parsing. (inferior-python-mode): Update docstring. (python-shell-readline-completer-delims): New variable indicating the word delimiters of readline completer. (python-shell-completion-native-setup): Set the completer delimiter. (python-shell-completion-native-get-completions): Convert output string to completions properly. (python-shell--get-multiline-input) (python-shell--extra-completion-context) (python-shell-completion-extra-context): New functions. (python-shell-completion-at-point): Send text beginning from the line start if the completion backend does not need word splitting. Remove the detection of import statement because it is not needed anymore. Create proper completion table based on completions returned from different backends. * test/lisp/progmodes/python-tests.el (python-tests--completion-module) (python-tests--completion-parameters) (python-tests--completion-extra-context): New helper functions. (python-shell-completion-at-point-jedi-completer) (python-shell-completion-at-point-ipython): New tests. (bug#68559)
Diffstat (limited to 'test/lisp/progmodes/python-tests.el')
-rw-r--r--test/lisp/progmodes/python-tests.el92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 59957ff0712..af6c199b5bd 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -4799,6 +4799,98 @@ def foo():
4799 (end-of-line 0) 4799 (end-of-line 0)
4800 (should-not (nth 2 (python-shell-completion-at-point)))))) 4800 (should-not (nth 2 (python-shell-completion-at-point))))))
4801 4801
4802(defun python-tests--completion-module ()
4803 "Check if modules can be completed in Python shell."
4804 (insert "import datet")
4805 (completion-at-point)
4806 (beginning-of-line)
4807 (should (looking-at-p "import datetime"))
4808 (kill-line)
4809 (insert "from datet")
4810 (completion-at-point)
4811 (beginning-of-line)
4812 (should (looking-at-p "from datetime"))
4813 (end-of-line)
4814 (insert " import timed")
4815 (completion-at-point)
4816 (beginning-of-line)
4817 (should (looking-at-p "from datetime import timedelta"))
4818 (kill-line))
4819
4820(defun python-tests--completion-parameters ()
4821 "Check if parameters can be completed in Python shell."
4822 (insert "import re")
4823 (comint-send-input)
4824 (python-tests-shell-wait-for-prompt)
4825 (insert "re.split('b', 'abc', maxs")
4826 (completion-at-point)
4827 (should (string= "re.split('b', 'abc', maxsplit="
4828 (buffer-substring (line-beginning-position) (point))))
4829 (insert "0, ")
4830 (should (python-shell-completion-at-point))
4831 ;; Test if cache is used.
4832 (cl-letf (((symbol-function 'python-shell-completion-get-completions)
4833 'ignore)
4834 ((symbol-function 'python-shell-completion-native-get-completions)
4835 'ignore))
4836 (insert "fla")
4837 (completion-at-point)
4838 (should (string= "re.split('b', 'abc', maxsplit=0, flags="
4839 (buffer-substring (line-beginning-position) (point)))))
4840 (beginning-of-line)
4841 (kill-line))
4842
4843(defun python-tests--completion-extra-context ()
4844 "Check if extra context is used for completion."
4845 (insert "re.split('b', 'abc',")
4846 (comint-send-input)
4847 (python-tests-shell-wait-for-prompt)
4848 (insert "maxs")
4849 (completion-at-point)
4850 (should (string= "maxsplit="
4851 (buffer-substring (line-beginning-position) (point))))
4852 (insert "0)")
4853 (comint-send-input)
4854 (python-tests-shell-wait-for-prompt)
4855 (insert "from re import (")
4856 (comint-send-input)
4857 (python-tests-shell-wait-for-prompt)
4858 (insert "IGN")
4859 (completion-at-point)
4860 (should (string= "IGNORECASE"
4861 (buffer-substring (line-beginning-position) (point)))))
4862
4863(ert-deftest python-shell-completion-at-point-jedi-completer ()
4864 "Check if Python shell completion works when Jedi completer is used."
4865 (skip-unless (executable-find python-tests-shell-interpreter))
4866 (python-tests-with-temp-buffer-with-shell
4867 ""
4868 (python-shell-with-shell-buffer
4869 (python-shell-completion-native-turn-on)
4870 (skip-unless (string= python-shell-readline-completer-delims ""))
4871 (python-tests--completion-module)
4872 (python-tests--completion-parameters)
4873 (python-tests--completion-extra-context))))
4874
4875(ert-deftest python-shell-completion-at-point-ipython ()
4876 "Check if Python shell completion works for IPython."
4877 (let ((python-shell-interpreter "ipython")
4878 (python-shell-interpreter-args "-i --simple-prompt"))
4879 (skip-unless
4880 (and
4881 (executable-find python-shell-interpreter)
4882 (eql (call-process python-shell-interpreter nil nil nil "--version") 0)))
4883 (python-tests-with-temp-buffer-with-shell
4884 ""
4885 (python-shell-with-shell-buffer
4886 (python-shell-completion-native-turn-off)
4887 (python-tests--completion-module)
4888 (python-tests--completion-parameters)
4889 (python-shell-completion-native-turn-on)
4890 (skip-unless (string= python-shell-readline-completer-delims ""))
4891 (python-tests--completion-module)
4892 (python-tests--completion-parameters)
4893 (python-tests--completion-extra-context)))))
4802 4894
4803 4895
4804;;; PDB Track integration 4896;;; PDB Track integration