-
Notifications
You must be signed in to change notification settings - Fork 23
/
pipenv-test.el
149 lines (113 loc) · 5.45 KB
/
pipenv-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
;; Test suite for pipenv.el
(require 'ert)
(require 'f)
(require 's)
(require 'flycheck)
(load (f-expand "pipenv.el" default-directory))
(setq existing-project (f-expand "existing-project" default-directory))
(setq new-project (f-expand "new-project" temporary-file-directory))
(ert-deftest test-pipenv--clean-response ()
(let ((response "example/response\n")
(expected "example/response"))
(should (s-equals? (pipenv--clean-response response) expected))))
(ert-deftest test-pipenv--force-list ()
(should (equal (pipenv--force-list "this that") '("this" "that")))
(should (equal (pipenv--force-list "this that") '("this" "that")))
(should (equal (pipenv--force-list '("this" "that")) '("this" "that"))))
(ert-deftest test-pipenv--get-executables-dir ()
(let ((python-shell-virtualenv-root nil))
(should (eq (pipenv--get-executables-dir) nil)))
(let ((python-shell-virtualenv-root "/directory/that/does/not/exist"))
(should (eq (pipenv--get-executables-dir) nil)))
(let ((python-shell-virtualenv-root default-directory)) ;;just tests logic
(should (equal (pipenv--get-executables-dir)
(concat default-directory "bin")))))
(ert-deftest pipenv-with-no-active-project ()
"Basic behavior when we do not have an active project."
(should (not (pipenv-project?)))
(pipenv--force-wait (pipenv-where))
(should (s-contains? "No Pipfile present at project home" pipenv-process-response))
(pipenv--force-wait (pipenv-venv))
(should (s-contains? "Aborted!" pipenv-process-response))
(pipenv--force-wait (pipenv-py))
(should (s-contains? "location not created nor specified" pipenv-process-response))
(should (eq nil python-shell-virtualenv-path))
(should (eq nil python-shell-virtualenv-root))
(should (s-equals? "python" python-shell-interpreter)))
(defun python-from-venv? (folder)
(setq which-python (shell-command-to-string "which python"))
(s-contains? (f-filename folder) which-python))
(ert-deftest pipenv-behavior-with-new-project ()
(f-mkdir new-project)
(cd new-project)
(should (not (pipenv-project?)))
(pipenv--force-wait (pipenv-python "2"))
(should (pipenv-project?))
(should-not (python-from-venv? new-project))
(pipenv-activate)
(should (python-from-venv? new-project))
(pipenv--force-wait (pipenv-where))
(should (s-ends-with? (f-filename new-project) pipenv-process-response))
(pipenv--force-wait (pipenv-venv))
(should (s-contains? (f-filename new-project) pipenv-process-response))
(should (s-contains? (f-filename new-project) python-shell-virtualenv-path))
(should (s-contains? (f-filename new-project) python-shell-virtualenv-root))
(let ((venv-executables (pipenv--get-executables-dir)))
(should (member venv-executables exec-path))
(should (not (executable-find "ipython")))
(pipenv--force-wait (pipenv-install "ipython"))
(should (executable-find "ipython"))
(should (s-contains? venv-executables (executable-find "ipython")))
(should (s-contains? "ipython" (f-read-text "Pipfile" 'utf-8)))
(pipenv--force-wait (pipenv-uninstall "ipython"))
(should (not (executable-find "ipython")))
(should (not (s-contains? "ipython" (f-read-text "Pipfile" 'utf-8)))))
(pipenv-deactivate)
(should-not (python-from-venv? new-project))
(should (eq nil python-shell-virtualenv-path))
(should (eq nil python-shell-virtualenv-root))
(should (s-equals? "python" python-shell-interpreter))
(let ((venv-executables (pipenv--get-executables-dir)))
(should (not (member venv-executables exec-path))))
(f-delete new-project 1))
(ert-deftest pipenv-behavior-with-existing-project ()
(cd existing-project)
(should (pipenv-project?))
(should-not (python-from-venv? existing-project))
(pipenv-activate)
(should (python-from-venv? existing-project))
(pipenv--force-wait (pipenv-where))
(should (s-ends-with? (f-filename existing-project) pipenv-process-response))
(pipenv--force-wait (pipenv-venv))
(should (s-contains? (f-filename existing-project) pipenv-process-response))
(should (s-contains? (f-filename existing-project) python-shell-virtualenv-path))
(should (s-contains? (f-filename existing-project) python-shell-virtualenv-root))
(let ((venv-executables (pipenv--get-executables-dir)))
(should (member venv-executables exec-path))
(should (not (executable-find "ipython")))
(pipenv--force-wait (pipenv-install "ipython"))
(should (executable-find "ipython"))
(should (s-contains? venv-executables (executable-find "ipython")))
(should (s-contains? "ipython" (f-read-text "Pipfile" 'utf-8)))
(pipenv--force-wait (pipenv-uninstall "ipython"))
(should (not (executable-find "ipython")))
(should (not (s-contains? "ipython" (f-read-text "Pipfile" 'utf-8)))))
(pipenv-deactivate)
(should-not (python-from-venv? existing-project))
(should (eq nil python-shell-virtualenv-path))
(should (eq nil python-shell-virtualenv-root))
(should (s-equals? "python" python-shell-interpreter))
(let ((venv-executables (pipenv--get-executables-dir)))
(should (not (member venv-executables exec-path)))))
(ert-deftest flycheck-integration ()
(cd existing-project)
(pipenv--force-wait (pipenv-install "flake8"))
(find-file "some.py")
(flycheck-mode)
(should-not (flycheck-may-use-checker 'python-flake8))
(pipenv-activate)
(should-not (flycheck-disabled-checker-p 'python-flake8))
(pipenv-deactivate)
(should (flycheck-disabled-checker-p 'python-flake8))
(pipenv--force-wait (pipenv-uninstall "flake8"))
)