From c4a256493898ddfdd1349e9b04102da80532a3b8 Mon Sep 17 00:00:00 2001 From: galaunay Date: Wed, 30 Jun 2021 22:10:07 +0200 Subject: [PATCH] Fine-tune github acion tests --- .github/workflows/test.yml | 2 +- elpy-rpc.el | 2 +- test/elpy-black-fix-code-test.el | 9 +---- test/elpy-open-and-indent-line-above-test.el | 29 +++++++-------- test/elpy-open-and-indent-line-below-test.el | 29 +++++++-------- test/elpy-yapf-fix-code-test.el | 6 +-- test/test-helper.el | 39 ++++++++++---------- 7 files changed, 52 insertions(+), 64 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 845f10545..65b1c16e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -69,7 +69,7 @@ jobs: - name: Run Emacs tests uses: nick-invision/retry@v2 with: - timeout_minutes: 5 + timeout_minutes: 10 max_attempts: 3 command: cask install ; PYTHONPATH="`pwd`" cask exec ert-runner --reporter ert+duration - name: Run Python tests diff --git a/elpy-rpc.el b/elpy-rpc.el index 06770a575..336612a54 100644 --- a/elpy-rpc.el +++ b/elpy-rpc.el @@ -418,7 +418,7 @@ binaries used to create the virtualenv." "-m" "pip" "install" "--upgrade" (elpy-rpc--get-package-list)) 0) - (message "Elpy failed to install some of the RPC dependencies, please use `elpy-config' to install them.\n%s" (buffer-substring)) + (message "Elpy failed to install some of the RPC dependencies, please use `elpy-config' to install them.\n%s" (buffer-string)) )) (message "Some of Elpy's functionnalities will not work, please use `elpy-config' to install the needed python dependencies."))) diff --git a/test/elpy-black-fix-code-test.el b/test/elpy-black-fix-code-test.el index d5114f186..cacc76dd8 100644 --- a/test/elpy-black-fix-code-test.el +++ b/test/elpy-black-fix-code-test.el @@ -2,14 +2,7 @@ (if (boundp '*elpy-black-fix-code--black-supported*) *elpy-black-fix-code--black-supported* (setq *elpy-black-fix-code--black-supported* - (not (string< (or (getenv "TRAVIS_PYTHON_VERSION") - (with-temp-buffer - (call-process elpy-rpc-python-command - nil '(t t) nil "--version") - (goto-char (point-min)) - (re-search-forward "\\([0-9.]+\\)" nil t) - (or (match-string 1) ""))) - "3.6"))))) + (not (string< (elpy-get-python-version) "3.6"))))) (when (elpy-black-fix-code--black-supported) (ert-deftest elpy-black-fix-code-should-retain-line-and-column () diff --git a/test/elpy-open-and-indent-line-above-test.el b/test/elpy-open-and-indent-line-above-test.el index 14c563136..d84671226 100644 --- a/test/elpy-open-and-indent-line-above-test.el +++ b/test/elpy-open-and-indent-line-above-test.el @@ -1,16 +1,13 @@ -;; This randomly breaks on Travis for some reason I have not yet -;; understood. - -;; (ert-deftest elpy-open-and-indent-line-below () -;; (elpy-testcase () -;; (elpy-enable) -;; (python-mode) -;; (insert-source -;; "def foo():" -;; " x = 5") -;; (goto-char (point-min)) -;; (re-search-forward "x") -;; (elpy-open-and-indent-line-above) -;; (should (equal (buffer-string) -;; "def foo():\n \n x = 5\n")) -;; (should (looking-at "\n x = 5")))) +(ert-deftest elpy-open-and-indent-line-below () + (elpy-testcase () + (elpy-enable) + (python-mode) + (insert-source + "def foo():" + " x = 5") + (goto-char (point-min)) + (re-search-forward "x") + (elpy-open-and-indent-line-above) + (should (equal (buffer-string) + "def foo():\n \n x = 5\n")) + (should (looking-at "\n x = 5")))) diff --git a/test/elpy-open-and-indent-line-below-test.el b/test/elpy-open-and-indent-line-below-test.el index 32001a0bf..dba3af38e 100644 --- a/test/elpy-open-and-indent-line-below-test.el +++ b/test/elpy-open-and-indent-line-below-test.el @@ -1,16 +1,13 @@ -;; This randomly breaks on Travis for some reason I have not yet -;; understood. - -;; (ert-deftest elpy-open-and-indent-line-below () -;; (elpy-testcase () -;; (elpy-enable) -;; (python-mode) -;; (insert "def foo():\n") -;; (goto-char 2) -;; (elpy-open-and-indent-line-below) -;; (should (or (equal (buffer-string) -;; "def foo():\n \n") -;; (equal (buffer-string) -;; "def foo():\n\n"))) -;; (should (equal (point) (- (point-max) -;; 1))))) +(ert-deftest elpy-open-and-indent-line-below () + (elpy-testcase () + (elpy-enable) + (python-mode) + (insert "def foo():\n") + (goto-char 2) + (elpy-open-and-indent-line-below) + (should (or (equal (buffer-string) + "def foo():\n \n") + (equal (buffer-string) + "def foo():\n\n"))) + (should (equal (point) (- (point-max) + 1))))) diff --git a/test/elpy-yapf-fix-code-test.el b/test/elpy-yapf-fix-code-test.el index ec89e8c66..c7f02ae6e 100644 --- a/test/elpy-yapf-fix-code-test.el +++ b/test/elpy-yapf-fix-code-test.el @@ -1,5 +1,5 @@ (ert-deftest elpy-yapf-fix-code-should-retain-line-and-column () - (let* ((pyversion (getenv "TRAVIS_PYTHON_VERSION")) + (let* ((pyversion (elpy-get-python-version)) (yapf-not-supported (or (string< pyversion "2.7") (and (not (string< pyversion "3.0")) (string< pyversion "3.4"))))) @@ -17,7 +17,7 @@ "y = 2_|_")))))) (ert-deftest elpy-yapf-fix-code-in-region-should-retain-line-and-column () - (let* ((pyversion (getenv "TRAVIS_PYTHON_VERSION")) + (let* ((pyversion (elpy-get-python-version)) (yapf-not-supported (or (string< pyversion "2.7") (and (not (string< pyversion "3.0")) (string< pyversion "3.4"))))) @@ -41,7 +41,7 @@ )))))) (ert-deftest elpy-yapf-fix-code-should-throw-error-for-invalid-code () - (let* ((pyversion (getenv "TRAVIS_PYTHON_VERSION")) + (let* ((pyversion (elpy-get-python-version)) (yapf-not-supported (or (string< pyversion "2.7") (and (not (string< pyversion "3.0")) (string< pyversion "3.4"))))) diff --git a/test/test-helper.el b/test/test-helper.el index 3de3c96a1..5d20717bd 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -20,26 +20,19 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Travis +;; CI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Travis is using virtualenvs to test specific version of python -;; we need to use it as the system environment -(advice-add 'elpy-rpc-get-virtualenv-path - :around (lambda (fun &rest args) - (if (and (getenv "TRAVIS") - (or (eq elpy-rpc-virtualenv-path 'global) ;; for backward compatibility - (eq elpy-rpc-virtualenv-path 'system))) - (expand-file-name - (concat - "~/virtualenv/" - "python" - (getenv "TRAVIS_PYTHON_VERSION"))) - (apply fun args)))) - -;; Travis regularly has some lag for some reason. -(setq elpy-rpc-timeout 10) -;; Print elpy configuration -(when (getenv "TRAVIS") +(when (getenv "GITHUB_RUN_ID") + ;; Make sure we use the proper python version to create the virtualenv + ;; This is necessary as multiple python binaries will be present on + ;; the virtual machine + (advice-add 'elpy-rpc--create-virtualenv + :around (lambda (orig-fun &rest args) + (let ((elpy-rpc-python-command (executable-find "python"))) + (apply orig-fun args)))) + ;; CI regularly has some lag for some reason. + (setq elpy-rpc-timeout 10) + ;; Print elpy configuration (elpy-config) (with-current-buffer "*Elpy Config*" (message (buffer-substring-no-properties (point-min) (point-max))))) @@ -61,6 +54,14 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test helper ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun elpy-get-python-version () + (with-temp-buffer + (call-process elpy-rpc-python-command + nil '(t t) nil "--version") + (goto-char (point-min)) + (re-search-forward "\\([0-9.]+\\)" nil t) + (or (match-string 1) ""))) + (defmacro mletf* (bindings &rest body) "Liket `cl-letf*', just with a slightly more concise function syntax.