Remove LSP-based Python test functions

This commit is contained in:
Ohad Livne 2025-06-04 22:47:12 +03:00
parent 87b86d71b9
commit 81ec639b70
Signed by: libohad-dev
GPG key ID: 34FDC68B51191A4D

View file

@ -240,49 +240,10 @@
(poetry-venv-workon)
(lsp)))
(defun symbols-at-point ()
"Utility function to get the hierarchy of the object at point."
(let* ((lsp--document-symbols-request-async t)
(symbols (lsp--get-document-symbols))
(symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols)))
(mapcar (lambda (symb)
(list (gethash "name" symb) (lsp--get-symbol-type symb)))
symbols-hierarchy)))
(defun python-test-at-point ()
"Use LSP to identify the test at point."
(let ((symbols (symbols-at-point)))
(pcase symbols
(`((,class "Class") (,method "Method") . ,_)
(if (equal "test_" (substring method 0 5))
`(,class ,method)
`(,class)))
(`((,class "Class") . ,_) `(,class))
(_ ()))))
(defun python-test-name-at-point ()
"Create a unittest-compatible descriptor for the test at point."
(let* ((path (mapcar #'substring-no-properties lsp-headerline--path-up-to-project-segments))
(filename (f-no-ext (f-filename (buffer-file-name)))))
(string-join (append path (list filename) (python-test-at-point)) ".")))
(defun python-run-test-at-point (debug)
"Identify and run the test at point.
When DEBUG is set, run the test in the debugger."
(interactive "P")
(let ((python (or (executable-find "python3")
(executable-find "python")))
(test-name (python-test-name-at-point)))
(if debug
(pdb (concat python " -m pdb -m unittest " test-name))
(compile (concat python " -m unittest " test-name)))))
(use-package python
:bind (:map python-mode-map
("C-c C-p" . nil)
("C-c C-l" . nil)
("C-c C-t" . python-run-test-at-point)
("C-M-t" . recompile))
("C-c C-l" . nil))
:hook (python-mode . load-python-env))
;; Jupyter notebook integration