annotate .elisp/nose.el @ 80:423b8666e6f6

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