Mercurial > dotfiles
annotate .elisp/nose.el @ 82:89f6d05cd7d5
Fix some ruby mode keybindings.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Mon, 13 Apr 2009 20:33:26 -0500 |
parents | 423b8666e6f6 |
children | f013f40e7b63 |
rev | line source |
---|---|
76 | 1 ;; nose.el --- Easy Python test running in Emacs |
2 | |
3 ;; Copyright (C) 2009 Jason Pellerin, Augie Fackler | |
4 | |
5 ;; Licensed under the same terms as Emacs. | |
6 | |
7 ;; Version: 0.1.0 | |
8 ;; Keywords: nose python testing | |
9 ;; Created: 04 Apr 2009 | |
10 | |
11 ;; This file is NOT part of GNU Emacs. | |
12 | |
13 ;; Licensed under the same terms as Emacs. | |
14 | |
15 ;;; Commentary: | |
16 ;; This gives a bunch of functions that handle running nosetests on a | |
17 ;; particular buffer or part of a buffer. | |
18 | |
19 ;;; Installation | |
20 | |
21 ;; In your emacs config: | |
22 ;; | |
23 ;; (require 'nose) | |
24 ;; ; next line only for people with non-eco non-global test runners | |
25 ;; ; (add-to-list 'nose-project-names "my/crazy/runner") | |
26 | |
27 ;; Note that if your global nose isn't called "nosetests", then you'll want to | |
28 ;; redefine nose-global-name to be the command that should be used. | |
29 | |
30 ;; Probably also want some keybindings: | |
31 ;; (add-hook 'python-mode-hook | |
32 ;; (lambda () | |
33 ;; (local-set-key "\C-ca" 'nosetests-all) | |
34 ;; (local-set-key "\C-cm" 'nosetests-module) | |
35 ;; (local-set-key "\C-c." 'nosetests-one) | |
36 ;; (local-set-key "\C-cpa" 'nosetests-pdb-all) | |
37 ;; (local-set-key "\C-cpm" 'nosetests-pdb-module) | |
38 ;; (local-set-key "\C-cp." 'nosetests-pdb-one))) | |
39 | |
40 (defvar nose-project-names '("eco/bin/test")) | |
41 (defvar nose-global-name "nosetests") | |
42 | |
43 (defun run-nose (&optional tests debug) | |
44 "run nosetests" | |
45 (let* ((nose (nose-find-test-runner)) | |
46 (where (expand-file-name "../.." (file-name-directory nose))) | |
47 (args (if debug "--pdb" "")) | |
48 (tnames (if tests tests ""))) | |
80
423b8666e6f6
Latest nose.el from nosemacs.
Augie Fackler <durin42@gmail.com>
parents:
76
diff
changeset
|
49 (funcall (if debug 'pdb '(lambda (command) |
423b8666e6f6
Latest nose.el from nosemacs.
Augie Fackler <durin42@gmail.com>
parents:
76
diff
changeset
|
50 (compilation-start command |
423b8666e6f6
Latest nose.el from nosemacs.
Augie Fackler <durin42@gmail.com>
parents:
76
diff
changeset
|
51 nil |
423b8666e6f6
Latest nose.el from nosemacs.
Augie Fackler <durin42@gmail.com>
parents:
76
diff
changeset
|
52 (lambda (mode) (concat "*nosetests*"))))) |
76 | 53 (format "%s -v %s -w %s -c %s/setup.cfg %s" |
54 (nose-find-test-runner) args where where tnames))) | |
55 ) | |
56 | |
57 (defun nosetests-all (&optional debug) | |
58 "run all tests" | |
59 (interactive) | |
60 (run-nose nil debug)) | |
61 | |
62 (defun nosetests-pdb-all () | |
63 (interactive) | |
64 (nosetests-all t)) | |
65 | |
66 (defun nosetests-module (&optional debug) | |
67 "run nosetests (via eggs/bin/test) on current buffer" | |
68 (interactive) | |
69 (run-nose buffer-file-name debug)) | |
70 | |
71 (defun nosetests-pdb-module () | |
72 (interactive) | |
73 (nosetests-module t)) | |
74 | |
75 (defun nosetests-one (&optional debug) | |
76 "run nosetests (via eggs/bin/test) on testable thing | |
77 at point in current buffer" | |
78 (interactive) | |
79 (run-nose (format "%s:%s" buffer-file-name (nose-py-testable)) debug)) | |
80 | |
81 (defun nosetests-pdb-one () | |
82 (interactive) | |
83 (nosetests-one t)) | |
84 | |
85 (defun nose-find-test-runner () | |
86 (message | |
87 (let ((result (reduce '(lambda (x y) (or x y)) | |
88 (mapcar 'nose-find-test-runner-names nose-project-names)))) | |
89 (if result | |
90 result | |
91 nose-global-name)))) | |
92 | |
93 (defun nose-find-test-runner-names (runner) | |
94 "find eggs/bin/test in a parent dir of current buffer's file" | |
95 (nose-find-test-runner-in-dir-named (file-name-directory buffer-file-name) runner)) | |
96 | |
97 (defun nose-find-test-runner-in-dir-named (dn runner) | |
98 (let ((fn (expand-file-name runner dn))) | |
99 (cond ((file-regular-p fn) fn) | |
100 ((equal dn "/") nil) | |
101 (t (nose-find-test-runner-in-dir-named | |
102 (file-name-directory (directory-file-name dn)) | |
103 runner))))) | |
104 | |
105 (defun nose-py-testable () | |
106 (let ((remember-point (point))) | |
107 (re-search-backward | |
108 "^ \\{0,4\\}\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t) | |
109 (setq t1 (buffer-substring-no-properties (match-beginning 2) (match-end 2))) | |
110 (goto-char remember-point) | |
111 (re-search-backward | |
112 "^\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t) | |
113 (setq outer | |
114 (buffer-substring-no-properties (match-beginning 1) (match-end 1))) | |
115 (setq t2 (buffer-substring-no-properties (match-beginning 2) (match-end 2))) | |
116 (let | |
117 ((result (cond ((string= outer "def") t2) | |
118 ((string= t1 t2) t2) | |
119 (t (format "%s.%s" t2 t1))))) | |
120 (goto-char remember-point) | |
121 result))) | |
122 | |
123 (provide 'nose) |