Skip to content

Instantly share code, notes, and snippets.

@k-bx
Created December 7, 2012 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-bx/4233445 to your computer and use it in GitHub Desktop.
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
(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