Created
October 20, 2012 16:26
-
-
Save bobjansen/3923840 to your computer and use it in GitHub Desktop.
Run nosetests from any directory in your virtualenv (Windows compatible)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun run-tests () | |
"Finds the virtualenv bin-dir and run nosetests" | |
(interactive) | |
(let ((bin-dir (if (eq system-type 'windows-nt) "Scripts" "bin")) | |
(cwd (reverse (split-string default-directory "/")))) | |
(let ((venv-dir (if (string= (first cwd) "") | |
(find-bin-dir (rest cwd) bin-dir) | |
(find-bin-dir cwd bin-dir)))) | |
(if venv-dir | |
(let ((old-path (getenv "PATH"))) | |
(setenv "PATH" (concat venv-dir ";" old-path)) | |
(compile "nosetests") | |
(setenv old-path)) | |
(message "Virtualenv not found"))))) | |
(defun find-bin-dir (path target) | |
"Move up the dir tree looking for a virtualenv bin-dir" | |
(let ((test-path | |
(mapconcat 'identity (append (reverse path) (list target)) "/"))) | |
(if (file-exists-p test-path) | |
test-path | |
(if (not (eq (rest path) nil)) | |
(find-bin-dir (rest path) target) | |
nil)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment