;;; python-tests.el --- Test suite for python.el
-;; Copyright (C) 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
(should (eq (car (python-indent-context)) 'after-beginning-of-block))
(should (= (python-indent-calculate-indentation) 12))))
+(ert-deftest python-indent-dedenters-2 ()
+ "Check one-liner block special case.."
+ (python-tests-with-temp-buffer
+ "
+cond = True
+if cond:
+
+ if cond: print 'True'
+else: print 'False'
+
+else:
+ return
+"
+ (python-tests-look-at "else: print 'False'")
+ ;; When a block has code after ":" it's just considered a simple
+ ;; line as that's a common thing to happen in one-liners.
+ (should (eq (car (python-indent-context)) 'after-line))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at "else:")
+ (should (eq (car (python-indent-context)) 'after-line))
+ (should (= (python-indent-calculate-indentation) 0))))
+
(ert-deftest python-indent-after-backslash-1 ()
"The most common case."
(python-tests-with-temp-buffer
(python-tests-look-at
"if request.user.is_authenticated():" -1)))))
-(ert-deftest python-nav-lisp-forward-sexp-safe-1 ()
- (python-tests-with-temp-buffer
- "
-profile = Profile.objects.create(user=request.user)
-profile.notify()
-"
- (python-tests-look-at "profile =")
- (python-nav-lisp-forward-sexp-safe 4)
- (should (looking-at "(user=request.user)"))
- (python-tests-look-at "user=request.user")
- (python-nav-lisp-forward-sexp-safe -1)
- (should (looking-at "(user=request.user)"))
- (python-nav-lisp-forward-sexp-safe -4)
- (should (looking-at "profile ="))
- (python-tests-look-at "user=request.user")
- (python-nav-lisp-forward-sexp-safe 3)
- (should (looking-at ")"))
- (python-nav-lisp-forward-sexp-safe 1)
- (should (looking-at "$"))
- (python-nav-lisp-forward-sexp-safe 1)
- (should (looking-at ".notify()"))))
-
(ert-deftest python-nav-forward-sexp-1 ()
(python-tests-with-temp-buffer
"
(python-nav-forward-sexp -1)
(should (looking-at "from some_module import some_sub_module"))))
+(ert-deftest python-nav-forward-sexp-safe-1 ()
+ (python-tests-with-temp-buffer
+ "
+profile = Profile.objects.create(user=request.user)
+profile.notify()
+"
+ (python-tests-look-at "profile =")
+ (python-nav-forward-sexp-safe 1)
+ (should (looking-at "$"))
+ (beginning-of-line 1)
+ (python-tests-look-at "user=request.user")
+ (python-nav-forward-sexp-safe -1)
+ (should (looking-at "(user=request.user)"))
+ (python-nav-forward-sexp-safe -4)
+ (should (looking-at "profile ="))
+ (python-tests-look-at "user=request.user")
+ (python-nav-forward-sexp-safe 3)
+ (should (looking-at ")"))
+ (python-nav-forward-sexp-safe 1)
+ (should (looking-at "$"))
+ (python-nav-forward-sexp-safe 1)
+ (should (looking-at "$"))))
+
(ert-deftest python-nav-up-list-1 ()
(python-tests-with-temp-buffer
"