Mercurial > dotfiles
annotate .elisp/nose.el @ 179:ebbbf3567a0e
zsh prompt: detabify
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 13 Jan 2010 10:34:12 -0600 |
parents | e83373ab1581 |
children |
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 | |
88 | 30 ;; By default, the root of a project is found by looking for any of the files |
31 ;; 'setup.py', '.hg' and '.git'. You can add files to check for to the file | |
32 ;; list: | |
33 ;; | |
34 ;; ; (add-to-list 'nose-project-root-files "something") | |
35 | |
36 ;; or you can change the project root test to detect in some other way | |
37 ;; whether a directory is the project root: | |
38 ;; | |
39 ;; ; (setq nose-project-root-test (lambda (dirname) (equal dirname "foo"))) | |
40 | |
41 ;; If you want dots as output, rather than the verbose output: | |
42 ;; (defvar nose-use-verbose nil) ; default is t | |
43 | |
76 | 44 ;; Probably also want some keybindings: |
45 ;; (add-hook 'python-mode-hook | |
46 ;; (lambda () | |
47 ;; (local-set-key "\C-ca" 'nosetests-all) | |
48 ;; (local-set-key "\C-cm" 'nosetests-module) | |
49 ;; (local-set-key "\C-c." 'nosetests-one) | |
50 ;; (local-set-key "\C-cpa" 'nosetests-pdb-all) | |
51 ;; (local-set-key "\C-cpm" 'nosetests-pdb-module) | |
52 ;; (local-set-key "\C-cp." 'nosetests-pdb-one))) | |
53 | |
54 (defvar nose-project-names '("eco/bin/test")) | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
55 (defvar nose-project-root-files '("setup.py" ".hg" ".git")) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
56 (defvar nose-project-root-test 'nose-project-root) |
76 | 57 (defvar nose-global-name "nosetests") |
88 | 58 (defvar nose-use-verbose t) |
76 | 59 |
120
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
60 (defun run-nose (&optional tests debug failed) |
76 | 61 "run nosetests" |
62 (let* ((nose (nose-find-test-runner)) | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
63 (where (nose-find-project-root)) |
120
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
64 (args (concat (if debug "--pdb" "") |
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
65 " " |
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
66 (if failed "--failed" ""))) |
76 | 67 (tnames (if tests tests ""))) |
85 | 68 (funcall (if debug |
69 'pdb | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
70 '(lambda (command) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
71 (compilation-start command |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
72 nil |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
73 (lambda (mode) (concat "*nosetests*"))))) |
88 | 74 (format |
75 (concat "%s " | |
92 | 76 (if nose-use-verbose "-v " "") |
88 | 77 "%s -w %s -c %ssetup.cfg %s") |
78 (nose-find-test-runner) args where where tnames))) | |
76 | 79 ) |
80 | |
120
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
81 (defun nosetests-all (&optional debug failed) |
76 | 82 "run all tests" |
83 (interactive) | |
120
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
84 (run-nose nil debug failed)) |
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
85 |
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
86 (defun nosetests-failed (&optional debug) |
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
87 (interactive) |
e83373ab1581
Latest nosemacs, python menu item for running nose with --failed.
Augie Fackler <durin42@gmail.com>
parents:
92
diff
changeset
|
88 (nosetests-all debug t)) |
76 | 89 |
90 (defun nosetests-pdb-all () | |
91 (interactive) | |
92 (nosetests-all t)) | |
93 | |
94 (defun nosetests-module (&optional debug) | |
95 "run nosetests (via eggs/bin/test) on current buffer" | |
96 (interactive) | |
97 (run-nose buffer-file-name debug)) | |
98 | |
99 (defun nosetests-pdb-module () | |
100 (interactive) | |
101 (nosetests-module t)) | |
102 | |
103 (defun nosetests-one (&optional debug) | |
104 "run nosetests (via eggs/bin/test) on testable thing | |
105 at point in current buffer" | |
106 (interactive) | |
107 (run-nose (format "%s:%s" buffer-file-name (nose-py-testable)) debug)) | |
108 | |
109 (defun nosetests-pdb-one () | |
110 (interactive) | |
111 (nosetests-one t)) | |
112 | |
113 (defun nose-find-test-runner () | |
114 (message | |
85 | 115 (let ((result |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
116 (reduce '(lambda (x y) (or x y)) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
117 (mapcar 'nose-find-test-runner-names nose-project-names)))) |
76 | 118 (if result |
119 result | |
120 nose-global-name)))) | |
121 | |
122 (defun nose-find-test-runner-names (runner) | |
123 "find eggs/bin/test in a parent dir of current buffer's file" | |
85 | 124 (nose-find-test-runner-in-dir-named |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
125 (file-name-directory buffer-file-name) runner)) |
76 | 126 |
127 (defun nose-find-test-runner-in-dir-named (dn runner) | |
128 (let ((fn (expand-file-name runner dn))) | |
129 (cond ((file-regular-p fn) fn) | |
130 ((equal dn "/") nil) | |
131 (t (nose-find-test-runner-in-dir-named | |
132 (file-name-directory (directory-file-name dn)) | |
133 runner))))) | |
134 | |
135 (defun nose-py-testable () | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
136 (let* ((inner-obj (inner-testable)) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
137 (outer (outer-testable)) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
138 ;; elisp can't return multiple values |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
139 (outer-def (car outer)) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
140 (outer-obj (cdr outer))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
141 (cond ((equal outer-def "def") outer-obj) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
142 ((equal inner-obj outer-obj) outer-obj) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
143 (t (format "%s.%s" outer-obj inner-obj))))) |
85 | 144 |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
145 (defun inner-testable () |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
146 (save-excursion |
76 | 147 (re-search-backward |
148 "^ \\{0,4\\}\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t) | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
149 (buffer-substring-no-properties (match-beginning 2) (match-end 2)))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
150 |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
151 (defun outer-testable () |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
152 (save-excursion |
76 | 153 (re-search-backward |
154 "^\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t) | |
85 | 155 (let ((result |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
156 (buffer-substring-no-properties (match-beginning 2) (match-end 2)))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
157 |
85 | 158 (cons |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
159 (buffer-substring-no-properties (match-beginning 1) (match-end 1)) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
160 result)))) |
76 | 161 |
85 | 162 (defun nose-find-project-root (&optional dirname) |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
163 (let ((dn |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
164 (if dirname |
85 | 165 dirname |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
166 (file-name-directory buffer-file-name)))) |
88 | 167 (cond ((funcall nose-project-root-test dn) (expand-file-name dn)) |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
168 ((equal (expand-file-name dn) "/") nil) |
85 | 169 (t (nose-find-project-root |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
170 (file-name-directory (directory-file-name dn))))))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
171 |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
172 (defun nose-project-root (dirname) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
173 (reduce '(lambda (x y) (or x y)) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
174 (mapcar (lambda (d) (member d (directory-files dirname))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
175 nose-project-root-files))) |
85 | 176 |
76 | 177 (provide 'nose) |