Mercurial > dotfiles
annotate .elisp/nose.el @ 84:f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 14 Apr 2009 20:07:12 -0500 |
parents | 423b8666e6f6 |
children | 4b9b90486260 |
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")) | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
41 (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
|
42 (defvar nose-project-root-test 'nose-project-root) |
76 | 43 (defvar nose-global-name "nosetests") |
44 | |
45 (defun run-nose (&optional tests debug) | |
46 "run nosetests" | |
47 (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
|
48 (where (nose-find-project-root)) |
76 | 49 (args (if debug "--pdb" "")) |
50 (tnames (if tests tests ""))) | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
51 (funcall (if debug |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
52 'pdb |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
53 '(lambda (command) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
54 (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
|
55 nil |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
56 (lambda (mode) (concat "*nosetests*"))))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
57 (format "%s -v %s -w %s -c %ssetup.cfg %s" |
76 | 58 (nose-find-test-runner) args where where tnames))) |
59 ) | |
60 | |
61 (defun nosetests-all (&optional debug) | |
62 "run all tests" | |
63 (interactive) | |
64 (run-nose nil debug)) | |
65 | |
66 (defun nosetests-pdb-all () | |
67 (interactive) | |
68 (nosetests-all t)) | |
69 | |
70 (defun nosetests-module (&optional debug) | |
71 "run nosetests (via eggs/bin/test) on current buffer" | |
72 (interactive) | |
73 (run-nose buffer-file-name debug)) | |
74 | |
75 (defun nosetests-pdb-module () | |
76 (interactive) | |
77 (nosetests-module t)) | |
78 | |
79 (defun nosetests-one (&optional debug) | |
80 "run nosetests (via eggs/bin/test) on testable thing | |
81 at point in current buffer" | |
82 (interactive) | |
83 (run-nose (format "%s:%s" buffer-file-name (nose-py-testable)) debug)) | |
84 | |
85 (defun nosetests-pdb-one () | |
86 (interactive) | |
87 (nosetests-one t)) | |
88 | |
89 (defun nose-find-test-runner () | |
90 (message | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
91 (let ((result |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
92 (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
|
93 (mapcar 'nose-find-test-runner-names nose-project-names)))) |
76 | 94 (if result |
95 result | |
96 nose-global-name)))) | |
97 | |
98 (defun nose-find-test-runner-names (runner) | |
99 "find eggs/bin/test in a parent dir of current buffer's file" | |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
100 (nose-find-test-runner-in-dir-named |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
101 (file-name-directory buffer-file-name) runner)) |
76 | 102 |
103 (defun nose-find-test-runner-in-dir-named (dn runner) | |
104 (let ((fn (expand-file-name runner dn))) | |
105 (cond ((file-regular-p fn) fn) | |
106 ((equal dn "/") nil) | |
107 (t (nose-find-test-runner-in-dir-named | |
108 (file-name-directory (directory-file-name dn)) | |
109 runner))))) | |
110 | |
111 (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
|
112 (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
|
113 (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
|
114 ;; 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
|
115 (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
|
116 (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
|
117 (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
|
118 ((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
|
119 (t (format "%s.%s" outer-obj inner-obj))))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
120 |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
121 (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
|
122 (save-excursion |
76 | 123 (re-search-backward |
124 "^ \\{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
|
125 (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
|
126 |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
127 (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
|
128 (save-excursion |
76 | 129 (re-search-backward |
130 "^\\(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
|
131 (let ((result |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
132 (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
|
133 |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
134 (cons |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
135 (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
|
136 result)))) |
76 | 137 |
84
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
138 (defun nose-find-project-root (&optional dirname) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
139 (interactive) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
140 (let ((dn |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
141 (if dirname |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
142 dirname |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
143 (file-name-directory buffer-file-name)))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
144 (cond ((nose-project-root dn) (expand-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
|
145 ((equal (expand-file-name dn) "/") nil) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
146 (t1 (nose-find-project-root |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
147 (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
|
148 |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
149 (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
|
150 (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
|
151 (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
|
152 nose-project-root-files))) |
f013f40e7b63
Import latest nosemacs, set nose to output dots instead of verbose output.
Augie Fackler <durin42@gmail.com>
parents:
80
diff
changeset
|
153 |
76 | 154 (provide 'nose) |