comparison .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
comparison
equal deleted inserted replaced
83:568f9f350844 84:f013f40e7b63
36 ;; (local-set-key "\C-cpa" 'nosetests-pdb-all) 36 ;; (local-set-key "\C-cpa" 'nosetests-pdb-all)
37 ;; (local-set-key "\C-cpm" 'nosetests-pdb-module) 37 ;; (local-set-key "\C-cpm" 'nosetests-pdb-module)
38 ;; (local-set-key "\C-cp." 'nosetests-pdb-one))) 38 ;; (local-set-key "\C-cp." 'nosetests-pdb-one)))
39 39
40 (defvar nose-project-names '("eco/bin/test")) 40 (defvar nose-project-names '("eco/bin/test"))
41 (defvar nose-project-root-files '("setup.py" ".hg" ".git"))
42 (defvar nose-project-root-test 'nose-project-root)
41 (defvar nose-global-name "nosetests") 43 (defvar nose-global-name "nosetests")
42 44
43 (defun run-nose (&optional tests debug) 45 (defun run-nose (&optional tests debug)
44 "run nosetests" 46 "run nosetests"
45 (let* ((nose (nose-find-test-runner)) 47 (let* ((nose (nose-find-test-runner))
46 (where (expand-file-name "../.." (file-name-directory nose))) 48 (where (nose-find-project-root))
47 (args (if debug "--pdb" "")) 49 (args (if debug "--pdb" ""))
48 (tnames (if tests tests ""))) 50 (tnames (if tests tests "")))
49 (funcall (if debug 'pdb '(lambda (command) 51 (funcall (if debug
50 (compilation-start command 52 'pdb
51 nil 53 '(lambda (command)
52 (lambda (mode) (concat "*nosetests*"))))) 54 (compilation-start command
53 (format "%s -v %s -w %s -c %s/setup.cfg %s" 55 nil
56 (lambda (mode) (concat "*nosetests*")))))
57 (format "%s -v %s -w %s -c %ssetup.cfg %s"
54 (nose-find-test-runner) args where where tnames))) 58 (nose-find-test-runner) args where where tnames)))
55 ) 59 )
56 60
57 (defun nosetests-all (&optional debug) 61 (defun nosetests-all (&optional debug)
58 "run all tests" 62 "run all tests"
82 (interactive) 86 (interactive)
83 (nosetests-one t)) 87 (nosetests-one t))
84 88
85 (defun nose-find-test-runner () 89 (defun nose-find-test-runner ()
86 (message 90 (message
87 (let ((result (reduce '(lambda (x y) (or x y)) 91 (let ((result
88 (mapcar 'nose-find-test-runner-names nose-project-names)))) 92 (reduce '(lambda (x y) (or x y))
93 (mapcar 'nose-find-test-runner-names nose-project-names))))
89 (if result 94 (if result
90 result 95 result
91 nose-global-name)))) 96 nose-global-name))))
92 97
93 (defun nose-find-test-runner-names (runner) 98 (defun nose-find-test-runner-names (runner)
94 "find eggs/bin/test in a parent dir of current buffer's file" 99 "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)) 100 (nose-find-test-runner-in-dir-named
101 (file-name-directory buffer-file-name) runner))
96 102
97 (defun nose-find-test-runner-in-dir-named (dn runner) 103 (defun nose-find-test-runner-in-dir-named (dn runner)
98 (let ((fn (expand-file-name runner dn))) 104 (let ((fn (expand-file-name runner dn)))
99 (cond ((file-regular-p fn) fn) 105 (cond ((file-regular-p fn) fn)
100 ((equal dn "/") nil) 106 ((equal dn "/") nil)
101 (t (nose-find-test-runner-in-dir-named 107 (t (nose-find-test-runner-in-dir-named
102 (file-name-directory (directory-file-name dn)) 108 (file-name-directory (directory-file-name dn))
103 runner))))) 109 runner)))))
104 110
105 (defun nose-py-testable () 111 (defun nose-py-testable ()
106 (let ((remember-point (point))) 112 (let* ((inner-obj (inner-testable))
113 (outer (outer-testable))
114 ;; elisp can't return multiple values
115 (outer-def (car outer))
116 (outer-obj (cdr outer)))
117 (cond ((equal outer-def "def") outer-obj)
118 ((equal inner-obj outer-obj) outer-obj)
119 (t (format "%s.%s" outer-obj inner-obj)))))
120
121 (defun inner-testable ()
122 (save-excursion
107 (re-search-backward 123 (re-search-backward
108 "^ \\{0,4\\}\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t) 124 "^ \\{0,4\\}\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t)
109 (setq t1 (buffer-substring-no-properties (match-beginning 2) (match-end 2))) 125 (buffer-substring-no-properties (match-beginning 2) (match-end 2))))
110 (goto-char remember-point) 126
127 (defun outer-testable ()
128 (save-excursion
111 (re-search-backward 129 (re-search-backward
112 "^\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t) 130 "^\\(class\\|def\\)[ \t]+\\([a-zA-Z0-9_]+\\)" nil t)
113 (setq outer 131 (let ((result
114 (buffer-substring-no-properties (match-beginning 1) (match-end 1))) 132 (buffer-substring-no-properties (match-beginning 2) (match-end 2))))
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 133
134 (cons
135 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
136 result))))
137
138 (defun nose-find-project-root (&optional dirname)
139 (interactive)
140 (let ((dn
141 (if dirname
142 dirname
143 (file-name-directory buffer-file-name))))
144 (cond ((nose-project-root dn) (expand-file-name dn))
145 ((equal (expand-file-name dn) "/") nil)
146 (t1 (nose-find-project-root
147 (file-name-directory (directory-file-name dn)))))))
148
149 (defun nose-project-root (dirname)
150 (reduce '(lambda (x y) (or x y))
151 (mapcar (lambda (d) (member d (directory-files dirname)))
152 nose-project-root-files)))
153
123 (provide 'nose) 154 (provide 'nose)