whitespaces will be removed. Otherwise, wraps indented
regions under an \"if True:\" block so the interpreter
evaluates them correctly."
- (let* ((single-p (save-restriction
- (narrow-to-region start end)
- (= (progn
- (goto-char start)
- (python-nav-beginning-of-statement))
- (progn
- (goto-char end)
- (python-nav-beginning-of-statement)))))
+ (let* ((single-p (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (= (progn
+ (goto-char start)
+ (python-nav-beginning-of-statement))
+ (progn
+ (goto-char end)
+ (python-nav-beginning-of-statement))))))
(start (save-excursion
;; If we're at the start of the expression, and if
;; the region consists of a single statement, then
(line-beginning-position)
start))))
(substring (buffer-substring-no-properties start end))
- (starts-at-first-line-p (save-restriction
- (widen)
- (goto-char start)
- (= (line-number-at-pos) 1)))
+ (starts-at-first-line-p (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char start)
+ (= (line-number-at-pos) 1))))
(encoding (python-info-encoding))
(toplevel-p (zerop (save-excursion
(goto-char start)
(overlay-end overlay))))
(buffer-substring-no-properties (point-min) (point-max)))))
+(defun python-tests-should-not-move (func &rest args)
+ "Assert that point does not move while calling FUNC with ARGS.
+Returns the value returned by FUNC."
+ (let ((pos (point))
+ (ret (apply func args)))
+ (should (= pos (point)))
+ ret))
+
(defun python-virt-bin (&optional virt-root)
"Return the virtualenv bin dir, starting from VIRT-ROOT.
If nil, VIRT-ROOT defaults to `python-shell-virtualenv-root'.
pass
"
(should (string= (buffer-string)
- (python-shell-buffer-substring (point-min) (point-max))))))
+ (python-tests-should-not-move
+ #'python-shell-buffer-substring (point-min) (point-max))))))
(ert-deftest python-shell-buffer-substring-2 ()
"Main block should be removed if NOMAIN is non-nil."
foo = Foo()
print (foo)
"
- (should (string= (python-shell-buffer-substring (point-min) (point-max) t)
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring (point-min) (point-max) t)
"
class Foo(models.Model):
pass
class Bar(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring (point-min) (point-max) t)
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring (point-min) (point-max) t)
"
class Foo(models.Model):
pass
class Bar(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "class Foo(models.Model):")
(progn (python-nav-forward-sexp) (point)))
"# -*- coding: latin-1 -*-
class Bar(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "class Bar(models.Model):")
(progn (python-nav-forward-sexp) (point)))
"# -*- coding: latin-1 -*-
class Bar(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "# coding: latin-1")
(python-tests-look-at "if __name__ == \"__main__\":"))
"# -*- coding: latin-1 -*-
class Bar(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "# coding: latin-1")
(python-tests-look-at "if __name__ == \"__main__\":"))
"# -*- coding: utf-8 -*-
class Foo(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring (point-min) (point-max))
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring (point-min) (point-max))
"# coding: utf-8
class Bar(models.Model):
pass
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(point-min)
(python-tests-look-at "class Bar(models.Model):"))
"# coding: utf-8
def foo():
print ('a')
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "print ('a')")
(point-max))
"# -*- coding: utf-8 -*-\nif True:\n print ('a')\n\n"))))
def foo():
print ('a')
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(progn
(python-tests-look-at "print ('a')")
(backward-char 1)
print ('a')
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "# Whitespace")
(point-max))
"# -*- coding: utf-8 -*-\n\nif True:\n # Whitespace\n\n print ('a')\n\n"))))
def foo():
a = 1
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "a = 1")
(pos-eol))
"# -*- coding: utf-8 -*-\n\na = 1"))))
a = \"\"\"Some
string\"\"\"
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "a = \"\"\"Some")
(pos-eol 2))
"# -*- coding: utf-8 -*-\n\na = \"\"\"Some\n string\"\"\""))))
def foo():
a = 1
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at " a = 1")
(python-tests-look-at " = 1"))
"# -*- coding: utf-8 -*-\n\na"))))
def foo():
a = 1
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "1")
(1+ (point)))
"# -*- coding: utf-8 -*-\n\n1"))))
b = 2
\"\"\"
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "a = 1")
(python-tests-look-at "\"\"\""))
"# -*- coding: utf-8 -*-\n\nif True:\n a = 1\n b = 2\n\n"))))
(python-tests-with-temp-buffer
"s = 'test'
"
- (should (string= (python-shell-buffer-substring
+ (should (string= (python-tests-should-not-move
+ #'python-shell-buffer-substring
(python-tests-look-at "'test'")
(pos-eol))
"'test'"))))