From 4f4f26ea3fb4a0d89e17d58512eb3d53e5c63520 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 9 Dec 2013 15:15:32 -0500 Subject: Function to create python test file --- init/km-python.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'init') 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"))) -- cgit v1.2.3