Skip to content

Instantly share code, notes, and snippets.

@svanellewee
Created July 1, 2016 07:35
Show Gist options
  • Save svanellewee/ff8af92b26930d853337f1dce9859834 to your computer and use it in GitHub Desktop.
Save svanellewee/ff8af92b26930d853337f1dce9859834 to your computer and use it in GitHub Desktop.
My first python test hack in elisp!
;;python-testize!
;; test code
(defun sve-setup-test-pytestize(function-to-test)
(with-current-buffer "test"
(erase-buffer)
(insert "test pim_service/loadsheets/tests/test_db.py")
(funcall function-to-test (point))
(let ((return-value (buffer-string)))
(equal return-value "test pim_service.loadsheets.tests.test_db" ))))
;; code to test
(defun sve-pytestize (ending)
"create a python test from a path"
(interactive "d")
(goto-char (search-backward " "))
(while (search-forward "/" nil t)
(replace-match "."))
(let* ((ext ".py")
(size-ext (length ext))
(end-dot-py (search-forward ext))
(start-dot-py (- end-dot-py size-ext)))
(delete-region start-dot-py end-dot-py)))
;; run the test
(with-current-buffer (switch-to-buffer-other-window "test")
(if (sve-setup-test-pytestize 'sve-pytestize)
(message "Success!")
(message "failed")))
;; what no ert?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment