;;; python-tests.el --- Test suite for python.el
-;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
always located at the beginning of buffer."
(declare (indent 1) (debug t))
`(with-temp-buffer
- (python-mode)
- (insert ,contents)
- (goto-char (point-min))
- ,@body))
+ (let ((python-indent-guess-indent-offset nil))
+ (python-mode)
+ (insert ,contents)
+ (goto-char (point-min))
+ ,@body)))
(defmacro python-tests-with-temp-file (contents &rest body)
"Create a `python-mode' enabled file with CONTENTS.
(declare (indent 1) (debug t))
;; temp-file never actually used for anything?
`(let* ((temp-file (make-temp-file "python-tests" nil ".py"))
- (buffer (find-file-noselect temp-file)))
+ (buffer (find-file-noselect temp-file))
+ (python-indent-guess-indent-offset nil))
(unwind-protect
(with-current-buffer buffer
(python-mode)
(should (eq (car (python-indent-context)) :inside-paren))
(should (= (python-indent-calculate-indentation) 11))))
+(ert-deftest python-indent-inside-paren-7 ()
+ "Test for Bug#21762."
+ (python-tests-with-temp-buffer
+ "import re as myre\nvar = [\n"
+ (goto-char (point-max))
+ ;; This signals an error if the test fails
+ (should (eq (car (python-indent-context)) :inside-paren-newline-start))))
+
(ert-deftest python-indent-after-block-1 ()
"The most simple after-block case that shouldn't fail."
(python-tests-with-temp-buffer
(python-shell-interpreter-args "-B"))
(should (string=
(format "%s %s"
- python-shell-interpreter
+ (shell-quote-argument python-shell-interpreter)
python-shell-interpreter-args)
(python-shell-calculate-command)))))
(let ((process-environment '("PYTHONPATH=/path0"))
(python-shell-extra-pythonpaths '("/path1" "/path2")))
(should (string= (python-shell-calculate-pythonpath)
- "/path1:/path2:/path0"))))
+ (concat "/path1" path-separator
+ "/path2" path-separator "/path0")))))
(ert-deftest python-shell-calculate-pythonpath-2 ()
"Test existing paths are moved to front."
- (let ((process-environment '("PYTHONPATH=/path0:/path1"))
+ (let ((process-environment
+ (list (concat "PYTHONPATH=/path0" path-separator "/path1")))
(python-shell-extra-pythonpaths '("/path1" "/path2")))
(should (string= (python-shell-calculate-pythonpath)
- "/path1:/path2:/path0"))))
+ (concat "/path1" path-separator
+ "/path2" path-separator "/path0")))))
(ert-deftest python-shell-calculate-process-environment-1 ()
"Test `python-shell-process-environment' modification."
(original-pythonpath (setenv "PYTHONPATH" "/path0"))
(python-shell-extra-pythonpaths '("/path1" "/path2"))
(process-environment (python-shell-calculate-process-environment)))
- (should (equal (getenv "PYTHONPATH") "/path1:/path2:/path0"))))
+ (should (equal (getenv "PYTHONPATH")
+ (concat "/path1" path-separator
+ "/path2" path-separator "/path0")))))
(ert-deftest python-shell-calculate-process-environment-3 ()
"Test `python-shell-virtualenv-root' modification."
(let* ((exec-path '("/path0"))
(python-shell-virtualenv-root "/env")
(new-exec-path (python-shell-calculate-exec-path)))
- (should (equal new-exec-path '("/env/bin" "/path0")))))
+ (should (equal new-exec-path
+ (list (expand-file-name "/env/bin") "/path0")))))
(ert-deftest python-shell-calculate-exec-path-3 ()
"Test complete `python-shell-virtualenv-root' modification."
(python-shell-exec-path '("/path1" "/path2"))
(python-shell-virtualenv-root "/env")
(new-exec-path (python-shell-calculate-exec-path)))
- (should (equal new-exec-path '("/env/bin" "/path1" "/path2" "/path0")))))
+ (should (equal new-exec-path
+ (list (expand-file-name "/env/bin")
+ "/path1" "/path2" "/path0")))))
(ert-deftest python-shell-calculate-exec-path-4 ()
"Test complete `python-shell-virtualenv-root' with remote."
(python-shell-exec-path '("/path1" "/path2"))
(python-shell-virtualenv-root "/env")
(new-exec-path (python-shell-calculate-exec-path)))
- (should (equal new-exec-path '("/env/bin" "/path1" "/path2" "/path0")))))
+ (should (equal new-exec-path
+ (list (expand-file-name "/env/bin")
+ "/path1" "/path2" "/path0")))))
(ert-deftest python-shell-calculate-exec-path-5 ()
"Test no side-effects on `exec-path'."
(original-exec-path exec-path)
(python-shell-virtualenv-root "/env"))
(python-shell-with-environment
- (should (equal exec-path '("/env/bin" "/path1" "/path2" "/path0")))
+ (should (equal exec-path
+ (list (expand-file-name "/env/bin")
+ "/path1" "/path2" "/path0")))
(should (not (getenv "PYTHONHOME")))
(should (string= (getenv "VIRTUAL_ENV") "/env")))
(should (equal exec-path original-exec-path))))
(python-shell-virtualenv-root "/env"))
(python-shell-with-environment
(should (equal (python-shell-calculate-exec-path)
- '("/env/bin" "/path1" "/path2" "/remote1" "/remote2")))
+ (list (expand-file-name "/env/bin")
+ "/path1" "/path2" "/remote1" "/remote2")))
(let ((process-environment (python-shell-calculate-process-environment)))
(should (not (getenv "PYTHONHOME")))
(should (string= (getenv "VIRTUAL_ENV") "/env"))
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-input-regexps'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-input-regexps'")))))
(ert-deftest python-shell-prompt-validate-regexps-2 ()
"Check `python-shell-prompt-output-regexps' are validated."
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-output-regexps'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-output-regexps'")))))
(ert-deftest python-shell-prompt-validate-regexps-3 ()
"Check `python-shell-prompt-regexp' is validated."
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-regexp'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-regexp'")))))
(ert-deftest python-shell-prompt-validate-regexps-4 ()
"Check `python-shell-prompt-block-regexp' is validated."
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-block-regexp'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-block-regexp'")))))
(ert-deftest python-shell-prompt-validate-regexps-5 ()
"Check `python-shell-prompt-pdb-regexp' is validated."
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-pdb-regexp'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-pdb-regexp'")))))
(ert-deftest python-shell-prompt-validate-regexps-6 ()
"Check `python-shell-prompt-output-regexp' is validated."
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-output-regexp'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-output-regexp'")))))
(ert-deftest python-shell-prompt-validate-regexps-7 ()
"Check default regexps are valid."
:type 'user-error)))
(should
(string= (cadr error-data)
- "Invalid regexp \\( in `python-shell-prompt-output-regexp'"))))
+ (format-message
+ "Invalid regexp \\( in `python-shell-prompt-output-regexp'")))))
(ert-deftest python-shell-prompt-set-calculated-regexps-2 ()
"Check `python-shell-prompt-input-regexps' are set."
(provide 'python-tests)
;; Local Variables:
-;; coding: utf-8
;; indent-tabs-mode: nil
;; End: