Permalink
Browse files

Add my own nosetests mode for python.

  • Loading branch information...
1 parent 1b212c0 commit d4175b700280f5530a33d5bd8adc80278f4267dd @chmouel committed Oct 14, 2012
Showing with 44 additions and 8 deletions.
  1. +3 −8 configs/programming/python.el
  2. +41 −0 modes/nosetests.el
@@ -5,13 +5,7 @@
(setq python-check-command (executable-find x)))
)
-(defun my-copy-current-function()
- (interactive)
- (let ((cmd)
- (function-name (python-info-current-defun)))
- (setq cmd (concat "python " (buffer-file-name) " " function-name))
- (progn (kill-new cmd) (message cmd))))
-
+(require 'nosetests)
(require 'flymake)
(defun flymake-pyflakes-init ()
(when (not (file-remote-p (buffer-file-name)))
@@ -30,7 +24,8 @@
(flymake-mode 't)
(local-set-key '[(control c)(\[)] 'flymake-goto-prev-error)
(local-set-key '[(control c)(\])] 'flymake-goto-next-error)
- (local-set-key (kbd "C-S-t") 'my-copy-current-function)
+ (local-set-key (kbd "C-S-t") 'nosetests-copy-shell-comand)
+ (local-set-key (kbd "C-S-r") 'nosetests-compile)
(which-func-mode 't)
(local-set-key '[(meta q)] 'python-fill-paragraph)
(set (make-local-variable 'my-compile-command) (concat python-check-command " \"" buffer-file-name "\""))
View
@@ -0,0 +1,41 @@
+;; Author: Chmouel Boudjnah <chmouel@chmouel.com>
+;;
+;; Provide two function to help with running nosetests. One
+;; `nosetests-get-command` that would copy your yank ring the current
+;; test to feed to nose on the shell and the other `nosetests-compile`
+;; that would launch the current test with nose in a compile buffer.
+
+(defvar nosetests-arg "-sx")
+
+(defun nosetests-get-command (&optional withcd)
+ (let (topdir test-path current-function cmd)
+ (setq topdir (file-truename (or (locate-dominating-file
+ (buffer-file-name) "setup.py") "./")))
+ (setq test-path (substring (file-truename
+ (buffer-file-name))
+ (length topdir)))
+ (setq current-function (python-info-current-defun))
+ (if (not current-function)
+ (error "No function at point"))
+
+ (setq cmd "")
+ (if withcd
+ (setq cmd (concat "cd " topdir ";")))
+ (concat cmd "nosetests "
+ nosetests-arg " " test-path ":"
+ current-function)))
+
+(defun nosetests-compile ()
+ (interactive)
+ (let (cmd)
+ (setq cmd (nosetests-get-command t))
+ (compile cmd)))
+
+(defun nosetests-copy-shell-comand ()
+ (interactive)
+ (let (cmd)
+ (setq cmd (nosetests-get-command))
+ (kill-new cmd)
+ (message cmd)))
+
+(provide 'nosetests)

0 comments on commit d4175b7

Please sign in to comment.