diff options
author | Kyle Meyer <kyle@kyleam.com> | 2013-12-09 15:15:32 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2013-12-09 15:15:32 -0500 |
commit | 4f4f26ea3fb4a0d89e17d58512eb3d53e5c63520 (patch) | |
tree | 3e7fc52caf068e3e1e23429a71ad2a1d169b4bdf /init | |
parent | 7a85498565f8cbe2b13a9ea503fc62eccfd5be14 (diff) | |
download | emacs.d-4f4f26ea3fb4a0d89e17d58512eb3d53e5c63520.tar.gz |
Function to create python test file
Diffstat (limited to 'init')
-rw-r--r-- | init/km-python.el | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/init/km-python.el b/init/km-python.el index 8518018..ade857d 100644 --- a/init/km-python.el +++ b/init/km-python.el @@ -13,7 +13,21 @@ python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")) +(defun km/create-python-test-file (arg) + "Create a python test file from the name of the current file. +Unless a prefix argument ARG is given, py.test is also imported." + (interactive "P") + (let* ((py-file (file-name-nondirectory buffer-file-name)) + (test-file (concat "test_" py-file))) + (when (file-exists-p test-file) + (error "Test file %s already exists." test-file)) + (with-current-buffer (find-file test-file) + (insert (format "import %s\n" (file-name-sans-extension py-file))) + (unless arg + (insert "import pytest\n"))))) + (defun km/python-hook () + (local-set-key (kbd "C-c m c") 'km/create-python-test-file) (local-set-key (kbd "C-c m t") '(lambda () (interactive) (compile "py.test"))) |