Skip to content

Commit

Permalink
Fine-tune github acion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Jun 30, 2021
1 parent 26b4ace commit d974e00
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion elpy-rpc.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.")))

Expand Down
9 changes: 1 addition & 8 deletions test/elpy-black-fix-code-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
29 changes: 13 additions & 16 deletions test/elpy-open-and-indent-line-above-test.el
Original file line number Diff line number Diff line change
@@ -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"))))
29 changes: 13 additions & 16 deletions test/elpy-open-and-indent-line-below-test.el
Original file line number Diff line number Diff line change
@@ -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)))))
1 change: 1 addition & 0 deletions test/elpy-xref--apropos-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(insert "def foo(x, y):\n"
" return x + y\n"
"var1 = foo(5, 2)")
(save-buffer)
(let ((xref-items (elpy-xref--apropos "fo"))
(basefile (f-join project-root "test.py")))

Expand Down
1 change: 1 addition & 0 deletions test/elpy-xref--definitions-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(insert "def foo(x, y):\n"
" return x + y\n"
"var1 = foo(5, 2)")
(save-buffer)
(let* ((basefile (f-join project-root "test.py"))
(foo-defs (car (elpy-xref--definitions "1: foo")))
(summary (xref-item-summary foo-defs))
Expand Down
1 change: 1 addition & 0 deletions test/elpy-xref--get-completion-table-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(insert "def foo(x, y):\n"
" return x + y\n"
"var1 = foo(5, 2)")
(save-buffer)
(let ((identifiers (elpy-xref--get-completion-table)))
(should (equal identifiers
(list "3: foo" "3: var1" "2: y" "2: x" "1: y" "1: x" "1: foo")))))))
6 changes: 3 additions & 3 deletions test/elpy-yapf-fix-code-test.el
Original file line number Diff line number Diff line change
@@ -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")))))
Expand All @@ -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")))))
Expand All @@ -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")))))
Expand Down
39 changes: 20 additions & 19 deletions test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
Expand All @@ -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.
Expand Down

0 comments on commit d974e00

Please sign in to comment.