Created
December 7, 2012 14:02
-
-
Save k-bx/4233445 to your computer and use it in GitHub Desktop.
Emacs Lisp function to get nose path to current python unit-test
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 python-get-runcmd-for-current-unit-test () | |
"Runs current python unit-test." | |
(interactive) | |
(defun get-test-name () | |
(setq before-everything (point)) | |
(setq def-start (search-backward "def ")) | |
(forward-char (length "def ")) | |
(setq name-start (point)) | |
(setq name-end (- (search-forward "(") 1)) | |
(setq rv (buffer-substring name-start name-end)) | |
(goto-char before-everything) | |
rv) | |
(defun get-class-name () | |
(setq before-everything (point)) | |
(setq def-start (search-backward "class ")) | |
(forward-char (length "class ")) | |
(setq name-start (point)) | |
(setq name-end (- (search-forward "(") 1)) | |
(setq rv (buffer-substring name-start name-end)) | |
(goto-char before-everything) | |
rv) | |
(defun get-test-path () | |
(setq without-dotpy (substring buffer-file-name 0 (- (length ".py")))) | |
(setq splitted-path (split-string without-dotpy "/")) | |
(setq magic-headoff (nthcdr 5 splitted-path)) | |
(setq joined (mapconcat 'identity magic-headoff ".")) | |
joined) | |
(setq nose-path-to-test (concatenate 'string (get-test-path) ":" (get-class-name) "." (get-test-name))) | |
(setq whole-command (concatenate 'string | |
"python manage.py test --settings settings_test " | |
nose-path-to-test)) | |
(kill-new whole-command) | |
whole-command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment