Add debug variants of the nosetests commands
This commit is contained in:
parent
dd354e9046
commit
36e5bfab7f
@ -2745,29 +2745,37 @@ And borrowing some functions from python-pytest, we can get some nosetests suppo
|
||||
(defvar nosetests-args ""
|
||||
"Additional args to pass to nosetests")
|
||||
|
||||
(defun run-nose (args)
|
||||
"Runs nosetests with `args'"
|
||||
(let ((nosetests-cmd (executable-find "nosetests")))
|
||||
(defun run-nose (args &optional debug)
|
||||
"Runs nosetests with `args'
|
||||
|
||||
If `debug' is non-nil, run in a GUD PDB session."
|
||||
(let* ((nosetests-cmd (executable-find "nosetests"))
|
||||
(cmdline (format "%s %s" nosetests-cmd args)))
|
||||
(when (not nosetests-cmd)
|
||||
(user-error "Nosetests command not found"))
|
||||
(compile (format "%s %s" nosetests-cmd args) t)))
|
||||
(if debug
|
||||
(pdb cmdline)
|
||||
(compile cmdline))))
|
||||
|
||||
(defun run-nose-reading-args (arg nose-args)
|
||||
"Runs nosetests with default args
|
||||
or prompts for args with prefix"
|
||||
(defun run-nose-reading-args (arg nose-args &optional debug)
|
||||
"Runs nosetests with default args or prompts for args with prefix
|
||||
|
||||
If `debug' is non-nil, run in a GUD PDB session."
|
||||
(let ((args (if arg
|
||||
(read-string "Nosetests arguments: "
|
||||
nil nil nosetests-args)
|
||||
nosetests-args)))
|
||||
(run-nose (format "%s %s" args nose-args))))
|
||||
(run-nose (format "%s %s" args nose-args) debug)))
|
||||
|
||||
(defun run-nose-in-project (arg nose-args)
|
||||
"Runs nosetests from the project root"
|
||||
(defun run-nose-in-project (arg nose-args &optional debug)
|
||||
"Runs nosetests from the project root
|
||||
|
||||
If `debug' is non-nil, run in a GUD PDB session."
|
||||
(let ((dir (or (projectile-project-root)
|
||||
default-directory)))
|
||||
(with-temp-buffer
|
||||
(cd dir)
|
||||
(run-nose-reading-args arg nose-args))))
|
||||
(run-nose-reading-args arg nose-args debug))))
|
||||
|
||||
(defun nosetests-all (arg)
|
||||
"Runs nosetests on all project tests, prompting for the tests directory"
|
||||
@ -2778,6 +2786,15 @@ And borrowing some functions from python-pytest, we can get some nosetests suppo
|
||||
nil t "tests" #'directory-name-p)))
|
||||
(run-nose-in-project arg (directory-file-name test-dir))))
|
||||
|
||||
(defun nosetests-debug-all (arg)
|
||||
"Runs nosetests in a GUD session on all project tests"
|
||||
(interactive "P")
|
||||
(let ((test-dir (read-file-name "Test directory: "
|
||||
(or (projectile-project-root)
|
||||
default-directory)
|
||||
nil t "tests" #'directory-name-p)))
|
||||
(run-nose-in-project arg (directory-file-name test-dir) t)))
|
||||
|
||||
(defun nosetests-module (arg module)
|
||||
"Runs nosetests in the module of the current file"
|
||||
(interactive (list current-prefix-arg
|
||||
@ -2788,6 +2805,16 @@ And borrowing some functions from python-pytest, we can get some nosetests suppo
|
||||
#'directory-name-p)))
|
||||
(run-nose-in-project arg (directory-file-name module)))
|
||||
|
||||
(defun nosetests-debug-module (arg module)
|
||||
"Runs nosetests in a GUD session in the module of the current file"
|
||||
(interactive (list current-prefix-arg
|
||||
(read-file-name "Run nosetests on module: "
|
||||
nil nil t
|
||||
(file-name-directory
|
||||
(buffer-file-name))
|
||||
#'directory-name-p)))
|
||||
(run-nose-in-project arg (directory-file-name module) t))
|
||||
|
||||
(defun nosetests-file (arg file)
|
||||
"Runs nosetests on the current file"
|
||||
(interactive (list current-prefix-arg
|
||||
@ -2795,6 +2822,13 @@ And borrowing some functions from python-pytest, we can get some nosetests suppo
|
||||
nil nil t (buffer-file-name))))
|
||||
(run-nose-in-project arg file))
|
||||
|
||||
(defun nosetests-debug-file (arg file)
|
||||
"Runs nosetests in a GUD session on the current file"
|
||||
(interactive (list current-prefix-arg
|
||||
(read-file-name "Run nosetests on file: "
|
||||
nil nil t (buffer-file-name))))
|
||||
(run-nose-in-project arg file t))
|
||||
|
||||
(defun nosetests-def (arg def)
|
||||
"Runs nosetests on the enclosing function at point"
|
||||
(interactive (list current-prefix-arg
|
||||
@ -2803,17 +2837,38 @@ And borrowing some functions from python-pytest, we can get some nosetests suppo
|
||||
(buffer-file-name)
|
||||
def)))
|
||||
|
||||
(defun nosetests-debug-def (arg def)
|
||||
"Runs nosetests in a GUD session on the enclosing function at point"
|
||||
(interactive (list current-prefix-arg
|
||||
(python-pytest--current-defun)))
|
||||
(run-nose-in-project arg
|
||||
(format "%s:%s"
|
||||
(buffer-file-name)
|
||||
def)
|
||||
t))
|
||||
|
||||
(defvar nosetests-map (make-sparse-keymap)
|
||||
"Keymap for nosetests")
|
||||
|
||||
(defvar nosetests-debug-map (make-sparse-keymap)
|
||||
"Keymap for debugging nosetests")
|
||||
|
||||
(general-def python-mode-map "C-c t n" nosetests-map)
|
||||
(general-def nosetests-map "a" #'nosetests-all)
|
||||
(general-def nosetests-map "m" #'nosetests-module)
|
||||
(general-def nosetests-map "f" #'nosetests-file)
|
||||
(general-def nosetests-map "d" #'nosetests-def)
|
||||
(general-def nosetests-map "b" nosetests-debug-map)
|
||||
|
||||
(general-def nosetests-debug-map "a" #'nosetests-debug-all)
|
||||
(general-def nosetests-debug-map "m" #'nosetests-debug-module)
|
||||
(general-def nosetests-debug-map "f" #'nosetests-debug-file)
|
||||
(general-def nosetests-debug-map "d" #'nosetests-debug-def)
|
||||
|
||||
(which-key-add-major-mode-key-based-replacements
|
||||
'python-mode "C-c t n" "nosetests")
|
||||
(which-key-add-major-mode-key-based-replacements
|
||||
'python-mode "C-c t n b" "debug")
|
||||
#+END_SRC
|
||||
|
||||
* Hy
|
||||
|
Loading…
Reference in New Issue
Block a user