From 8569df1866ca4387048a3502bf03f71245e12b4a Mon Sep 17 00:00:00 2001 From: galaunay Date: Thu, 17 Oct 2019 22:56:58 +0200 Subject: [PATCH] Fix tests --- Cask | 4 ++-- elpy-rpc.el | 6 ++++-- test/elpy-rpc-get-virtualenv-path-test.el | 4 +--- test/elpy-rpc-reinstall-venv-test.el | 2 +- test/test-helper.el | 16 +++++++++++++++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cask b/Cask index 7fe635099..40a0c0a8a 100644 --- a/Cask +++ b/Cask @@ -4,9 +4,9 @@ (package "elpy" "1.31.0" "Emacs Python Development Environment") (depends-on "company" "0.9.10") -(depends-on "find-file-in-project" "5.7.4") +(depends-on "find-file-in-project" "5.7.7") (depends-on "highlight-indentation" "0.7.0") -(depends-on "pyvenv" "1.2") +(depends-on "pyvenv" "1.20") (depends-on "yasnippet" "0.13.0") (depends-on "s" "1.12.0") diff --git a/elpy-rpc.el b/elpy-rpc.el index 84873339a..fb619f0ce 100644 --- a/elpy-rpc.el +++ b/elpy-rpc.el @@ -260,8 +260,10 @@ During the execution of BODY the following variables are available: (file-name-directory current-environment-binaries))))) ;; No need to change of venv if they are the same - (same-venv (file-equal-p current-environment - (elpy-rpc-get-or-create-virtualenv))) + (same-venv (or (string= current-environment + (elpy-rpc-get-virtualenv-path)) + (file-equal-p current-environment + (elpy-rpc-get-virtualenv-path)))) current-environment-is-deactivated) (unless same-venv (pyvenv-activate (elpy-rpc-get-or-create-virtualenv)) diff --git a/test/elpy-rpc-get-virtualenv-path-test.el b/test/elpy-rpc-get-virtualenv-path-test.el index 092247ce0..e8e10322f 100644 --- a/test/elpy-rpc-get-virtualenv-path-test.el +++ b/test/elpy-rpc-get-virtualenv-path-test.el @@ -30,10 +30,8 @@ (elpy-testcase () (let ((elpy-rpc-virtualenv-path 'system) (old-venv pyvenv-virtual-env)) - (should-not (string-match "\\(travis/virtualenv\\|.virtualenvs\\)" - (elpy-rpc-get-virtualenv-path))) (pyvenv-workon "elpy-test-venv") - (should-not (string-match "\\(travis/virtualenv\\|.virtualenvs\\)" + (should-not (string-match "elpy-test-venv" (elpy-rpc-get-virtualenv-path))) (if old-venv (pyvenv-activate old-venv) diff --git a/test/elpy-rpc-reinstall-venv-test.el b/test/elpy-rpc-reinstall-venv-test.el index 6c9689ad1..b3e4c1e3c 100644 --- a/test/elpy-rpc-reinstall-venv-test.el +++ b/test/elpy-rpc-reinstall-venv-test.el @@ -44,4 +44,4 @@ (should-not (file-exists-p (concat (file-name-as-directory rpc-venv-path) "additional-file"))) - (should (string= messages "Are you sure you want to reinstall the virtualenv in '/home/glaunay/.virtualenvs/elpy-test-venv' (every manual modifications will be lost) ? `elpy-rpc-virtualenv-path' was set to '/home/glaunay/.virtualenvs/elpy-test-venv', but this virtualenv does not exist, create it ? Automatically install the RPC dependencies from PyPI (needed for completion, autoformatting and documentation) ? "))))))) + (should (= 0 (string-match "Are you sure you want to reinstall the virtualenv in '[^']*' (every manual modifications will be lost) \\? `elpy-rpc-virtualenv-path' was set to '[^']*', but this virtualenv does not exist, create it \\? Automatically install the RPC dependencies from PyPI (needed for completion, autoformatting and documentation) \\? " messages)))))))) diff --git a/test/test-helper.el b/test/test-helper.el index 9c13ced58..132788233 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -7,6 +7,20 @@ elpy-dir (getenv "PYTHONPATH"))) (add-to-list 'process-environment "ELPY_TEST=1")) +;; 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) + (eq elpy-rpc-virtualenv-path 'system))) + (expand-file-name + (concat + "~/virtualenv/" + "python" + (getenv "TRAVIS_PYTHON_VERSION"))) + (apply fun args)))) + (require 'elpy) ;; Travis regularly has some lag for some reason. (setq elpy-rpc-timeout 10) @@ -40,7 +54,7 @@ (mletf* ((y-or-n-p (&rest rest) t)) (elpy-config) (with-current-buffer "*Elpy Config*" - (print (buffer-string)))) + (message (buffer-substring-no-properties (point-min) (point-max))))) (defmacro with-temp-dir (name &rest body) "Create a temporary directory and bind the symbol NAME to the path.