unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70815: [PATCH] ; Enahnce python-tests.el to adapt different python interpreters
@ 2024-05-07  6:53 Lin Sun
  2024-05-11  9:05 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 49+ messages in thread
From: Lin Sun @ 2024-05-07  6:53 UTC (permalink / raw)
  To: 70815

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

Hi,
The python-tests.el will fail on finding interpreter "python" for
there is no "python"  on CentOS8, Ubuntu 20.04,  only "python3" exists
after installation.

And the patch will try to search python/python3/python2 as the python
testing interpreter; it also support a env var
"EMACS_PYTHON_INTERPRETER" to switch between different version of
python (eg: python3.6, python3.11, ...).

Please help review the  enhancement in "python-tests.el". Thanks.

[-- Attachment #2: 0001-Enahnce-python-tests.el-to-adapt-different-python-in.patch --]
[-- Type: text/x-patch, Size: 15880 bytes --]

From 49dfcecbbffaf15aa0414d15f22d8bcbf768ebb3 Mon Sep 17 00:00:00 2001
From: Lin Sun <sunlin7@hotmail.com>
Date: Fri, 3 May 2024 06:52:22 +0000
Subject: [PATCH] ; Enahnce python-tests.el to adapt different python
 interpreters

* test/lisp/progmodes/python-tests.el
  (python-tests-get-shell-interpreter): New function to get python
  interpreter for testing.
---
 test/lisp/progmodes/python-tests.el | 87 ++++++++++++++++-------------
 1 file changed, 48 insertions(+), 39 deletions(-)

diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index f50797953c3..6da149925ec 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -3718,7 +3718,16 @@ if x:
 \f
 ;;; Shell integration
 
-(defvar python-tests-shell-interpreter "python")
+(defvar python-tests-shell-interpreter nil)
+
+(defun python-tests-get-shell-interpreter (&optional refresh)
+  (if (and python-tests-shell-interpreter (null refresh))
+      python-tests-shell-interpreter
+    (setq python-tests-shell-interpreter
+          (or (when-let* ((interpreter (getenv "EMACS_PYTHON_INTERPRETER")))
+                (or (executable-find interpreter)
+                    (error "Not found EMACS_PYTHON_INTERPRETER: %s" interpreter)))
+              (cl-some #'executable-find '("python" "python3" "python2"))))))
 
 (ert-deftest python-shell-get-process-name-1 ()
   "Check process name calculation sans `buffer-file-name'."
@@ -3980,13 +3989,13 @@ if x:
 
 (ert-deftest python-shell-make-comint-1 ()
   "Check comint creation for global shell buffer."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   ;; The interpreter can get killed too quickly to allow it to clean
   ;; up the tempfiles that the default python-shell-setup-codes create,
   ;; so it leaves tempfiles behind, which is a minor irritation.
   (let* ((python-shell-setup-codes nil)
          (python-shell-interpreter
-          (executable-find python-tests-shell-interpreter))
+          (python-tests-get-shell-interpreter))
          (proc-name (python-shell-get-process-name nil))
          (shell-buffer
           (python-tests-with-temp-buffer
@@ -4004,10 +4013,10 @@ if x:
 
 (ert-deftest python-shell-make-comint-2 ()
   "Check comint creation for internal shell buffer."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((python-shell-setup-codes nil)
          (python-shell-interpreter
-          (executable-find python-tests-shell-interpreter))
+          (python-tests-get-shell-interpreter))
          (proc-name (python-shell-internal-get-process-name))
          (shell-buffer
           (python-tests-with-temp-buffer
@@ -4028,13 +4037,13 @@ if x:
 The command passed to `python-shell-make-comint' as argument must
 locally override global values set in `python-shell-interpreter'
 and `python-shell-interpreter-args' in the new shell buffer."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((python-shell-setup-codes nil)
          (python-shell-interpreter "interpreter")
          (python-shell-interpreter-args "--some-args")
          (proc-name (python-shell-get-process-name nil))
          (interpreter-override
-          (concat (executable-find python-tests-shell-interpreter) " " "-i"))
+          (concat (python-tests-get-shell-interpreter) " " "-i"))
          (shell-buffer
           (python-tests-with-temp-buffer
            "" (python-shell-make-comint interpreter-override proc-name nil)))
@@ -4047,17 +4056,17 @@ and `python-shell-interpreter-args' in the new shell buffer."
             (should (eq major-mode 'inferior-python-mode))
             (should (file-equal-p
                      python-shell-interpreter
-                     (executable-find python-tests-shell-interpreter)))
+                     (python-tests-get-shell-interpreter)))
             (should (string= python-shell-interpreter-args "-i"))))
       (kill-buffer shell-buffer))))
 
 (ert-deftest python-shell-make-comint-4 ()
   "Check shell calculated prompts regexps are set."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((process-environment process-environment)
          (python-shell-setup-codes nil)
          (python-shell-interpreter
-          (executable-find python-tests-shell-interpreter))
+          (python-tests-get-shell-interpreter))
          (python-shell-interpreter-args "-i")
          (python-shell--prompt-calculated-input-regexp nil)
          (python-shell--prompt-calculated-output-regexp nil)
@@ -4099,12 +4108,12 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-get-process-1 ()
   "Check dedicated shell process preference over global."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-file
       ""
     (let* ((python-shell-setup-codes nil)
            (python-shell-interpreter
-            (executable-find python-tests-shell-interpreter))
+            (python-tests-get-shell-interpreter))
            (global-proc-name (python-shell-get-process-name nil))
            (dedicated-proc-name (python-shell-get-process-name t))
            (global-shell-buffer
@@ -4132,12 +4141,12 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-internal-get-or-create-process-1 ()
   "Check internal shell process creation fallback."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-file
    ""
    (should (not (process-live-p (python-shell-internal-get-process-name))))
    (let* ((python-shell-interpreter
-           (executable-find python-tests-shell-interpreter))
+           (python-tests-get-shell-interpreter))
           (internal-process-name (python-shell-internal-get-process-name))
           (internal-process (python-shell-internal-get-or-create-process))
           (internal-shell-buffer (process-buffer internal-process)))
@@ -4155,7 +4164,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-detect-1 ()
   "Check prompt autodetection."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let ((process-environment process-environment))
     ;; Ensure no startup file is enabled
     (setenv "PYTHONSTARTUP" "")
@@ -4164,7 +4173,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-detect-2 ()
   "Check prompt autodetection with startup file.  Bug#17370."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((process-environment process-environment)
          (startup-code (concat "import sys\n"
                                "sys.ps1 = 'py> '\n"
@@ -4181,7 +4190,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-detect-3 ()
   "Check prompts are not autodetected when feature is disabled."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let ((process-environment process-environment)
         (python-shell-prompt-detect-enabled nil))
     ;; Ensure no startup file is enabled
@@ -4190,7 +4199,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-detect-4 ()
   "Check warning is shown when detection fails."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((process-environment process-environment)
          ;; Trigger failure by removing prompts in the startup file
          (startup-code (concat "import sys\n"
@@ -4211,7 +4220,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-detect-5 ()
   "Check disabled warnings are not shown when detection fails."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((process-environment process-environment)
          (startup-code (concat "import sys\n"
                                "sys.ps1 = ''\n"
@@ -4232,7 +4241,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-detect-6 ()
   "Warnings are not shown when detection is disabled."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((process-environment process-environment)
          (startup-code (concat "import sys\n"
                                "sys.ps1 = ''\n"
@@ -4396,7 +4405,7 @@ and `python-shell-interpreter-args' in the new shell buffer."
 
 (ert-deftest python-shell-prompt-set-calculated-regexps-6 ()
   "Check detected prompts are included `regexp-quote'd."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((python-shell-prompt-input-regexps '(""))
          (python-shell-prompt-output-regexps '(""))
          (python-shell-prompt-regexp "")
@@ -4779,7 +4788,7 @@ def foo():
     (should (python-shell-completion-native-interpreter-disabled-p))))
 
 (ert-deftest python-shell-completion-at-point-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    ""
    (python-shell-with-shell-buffer
@@ -4793,7 +4802,7 @@ def foo():
      (should-not (nth 2 (python-shell-completion-at-point))))))
 
 (ert-deftest python-shell-completion-at-point-native-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    ""
    (python-shell-completion-native-turn-on)
@@ -4872,14 +4881,14 @@ def foo():
   "Return Jedi readline setup file if PYTHONSTARTUP is not set."
   (or (getenv "PYTHONSTARTUP")
       (with-temp-buffer
-        (if (eql 0 (call-process python-tests-shell-interpreter
+        (if (eql 0 (call-process (python-tests-get-shell-interpreter)
                                  nil t nil "-m" "jedi" "repl"))
             (string-trim (buffer-string))
           ""))))
 
 (ert-deftest python-shell-completion-at-point-jedi-completer ()
   "Check if Python shell completion works when Jedi completer is used."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (with-environment-variables
       (("PYTHONSTARTUP" (python-tests--pythonstartup-file)))
     (python-tests-with-temp-buffer-with-shell
@@ -4924,7 +4933,7 @@ def foo():
 ;;; Symbol completion
 
 (ert-deftest python-completion-at-point-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -4942,7 +4951,7 @@ import abc
 
 (ert-deftest python-completion-at-point-2 ()
   "Should work regardless of the point in the Shell buffer."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -4960,7 +4969,7 @@ import abc
 
 (ert-deftest python-completion-at-point-pdb-1 ()
   "Should not complete PDB commands in Python buffer."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import pdb
@@ -4979,7 +4988,7 @@ print('Hello')
 
 (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))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import time
@@ -4995,7 +5004,7 @@ time.sleep(3)
      (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))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -5014,7 +5023,7 @@ import abc
 
 (ert-deftest python-completion-at-point-native-2 ()
   "Should work regardless of the point in the Shell buffer."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -5032,7 +5041,7 @@ import abc
      (should (completion-at-point)))))
 
 (ert-deftest python-completion-at-point-native-with-ffap-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -5050,7 +5059,7 @@ import abc
      (should (completion-at-point)))))
 
 (ert-deftest python-completion-at-point-native-with-eldoc-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -5077,7 +5086,7 @@ import abc
 ;;; FFAP
 
 (ert-deftest python-ffap-module-path-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -5089,7 +5098,7 @@ import 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))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import abc
@@ -5165,7 +5174,7 @@ some_symbol   some_other_symbol
                     "some_symbol"))))
 
 (ert-deftest python-eldoc--get-doc-at-point-1 ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import time
@@ -5178,7 +5187,7 @@ import time
 
 (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))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
    "
 import time
@@ -7396,7 +7405,7 @@ buffer with overlapping strings."
 ;; interpreter.
 (ert-deftest python-tests--run-python-selects-window ()
   "Test for bug#31398.  See also bug#44421 and bug#52380."
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (let* ((buffer (process-buffer (run-python nil nil 'show)))
          (window (get-buffer-window buffer)))
     ;; We look at `selected-window' rather than `current-buffer'
@@ -7467,7 +7476,7 @@ buffer with overlapping strings."
                        "W0611: Unused import a.b.c (unused-import)"))))))
 
 (ert-deftest python-test--shell-send-block ()
-  (skip-unless (executable-find python-tests-shell-interpreter))
+  (skip-unless (python-tests-get-shell-interpreter))
   (python-tests-with-temp-buffer-with-shell
     "print('current 0')
 for x in range(1,3):
-- 
2.20.5


^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2024-06-10 15:44 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-07  6:53 bug#70815: [PATCH] ; Enahnce python-tests.el to adapt different python interpreters Lin Sun
2024-05-11  9:05 ` Eli Zaretskii
2024-05-11 13:37   ` kobarity
2024-05-11 14:27     ` Lin Sun
2024-05-12  2:06       ` kobarity
2024-05-18 22:20 ` Stefan Kangas
2024-05-19  5:54   ` Eli Zaretskii
2024-05-20  0:08     ` Lin Sun
2024-05-20 15:52       ` kobarity
2024-05-20 17:51         ` Lin Sun
2024-05-21 14:04           ` kobarity
2024-05-21 15:34             ` Lin Sun
2024-05-22 14:38               ` kobarity
2024-05-23 13:09                 ` Eli Zaretskii
2024-05-26 10:52 ` Mattias Engdegård
2024-05-26 12:05   ` kobarity
2024-05-26 12:21     ` Mattias Engdegård
2024-05-26 12:36       ` kobarity
2024-05-26 13:23         ` Mattias Engdegård
2024-05-26 14:15           ` kobarity
2024-05-26 15:00             ` kobarity
2024-05-26 15:24               ` Mattias Engdegård
2024-05-27 12:33                 ` kobarity
2024-05-27 12:45                   ` Eli Zaretskii
2024-05-28 12:30                   ` Mattias Engdegård
2024-05-28 15:17                     ` kobarity
2024-05-28 16:09                       ` Mattias Engdegård
2024-05-29 14:56                         ` kobarity
2024-05-30 10:09                           ` Mattias Engdegård
2024-06-02 13:20                             ` kobarity
2024-06-03 14:02                               ` Mattias Engdegård
2024-06-03 14:34                                 ` kobarity
2024-06-03 16:24                                   ` kobarity
2024-06-04 14:29                                     ` kobarity
2024-06-05 10:25                                       ` Mattias Engdegård
2024-06-05 11:52                                         ` kobarity
2024-06-08 15:34                                           ` kobarity
2024-06-09 13:58                                             ` Mattias Engdegård
2024-06-10 14:57                                               ` kobarity
2024-06-10 15:44                                                 ` Mattias Engdegård
2024-05-26 15:56             ` Eli Zaretskii
2024-05-26 23:06               ` Stefan Kangas
2024-05-27 11:18                 ` Eli Zaretskii
2024-05-27 12:20                   ` Mattias Engdegård
2024-05-27 12:43                     ` Eli Zaretskii
2024-05-26 15:52           ` Eli Zaretskii
2024-05-27 10:24             ` Mattias Engdegård
2024-05-27 11:19               ` Lin Sun
2024-05-26 15:36   ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).