Skip to content

Commit 3939fe4

Browse files
committed
Merge branch 'test-output'
2 parents c3e16db + 3987bda commit 3939fe4

File tree

4 files changed

+110
-16
lines changed

4 files changed

+110
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ before_install:
3535
# but to separate installation phase and testing phase:
3636
- make deps
3737
script:
38-
- make test
38+
- make travis-ci

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ELPA_DIR = \
77
.cask/$(shell ${EMACS} -Q --batch --eval '(princ emacs-version)')/elpa
88
# See: cask-elpa-dir
99

10-
.PHONY: test deps clean purge
10+
.PHONY: test deps clean purge travis-ci
1111

1212
test: deps
1313
${EMACS_TEST} --batch -f ert-run-tests-batch-and-exit
@@ -26,3 +26,6 @@ clean:
2626

2727
purge: clean
2828
rm -rf ${ELPA_DIR}
29+
30+
travis-ci: test
31+
test ! -d ~/.emacs.d/.python-environments

python-environment.el

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,23 @@ Thus, typically the default virtual environment path is
6262
(lambda (msg output)
6363
(message "%s...Done" msg)
6464
(when python-environment--verbose
65-
(princ output)))
65+
(message output)))
6666
msg))))
6767

6868
(defun python-environment--blocking-process (msg command)
6969
(message "%s (SYNC)..." msg)
70-
(let ((exit-code
71-
(if python-environment--verbose
72-
(with-temp-buffer
73-
(apply #'call-process (car command)
74-
nil ; INFILE (no input)
75-
t ; BUFFER (output to this buffer)
76-
nil ; DISPLAY (no refresh is needed)
77-
(cdr command))
78-
(princ (buffer-string)))
79-
(apply #'call-process (car command) nil nil nil (cdr command)))))
70+
(let (exit-code output)
71+
(with-temp-buffer
72+
(setq exit-code
73+
(apply #'call-process (car command)
74+
nil ; INFILE (no input)
75+
t ; BUFFER (output to this buffer)
76+
nil ; DISPLAY (no refresh is needed)
77+
(cdr command)))
78+
(setq output (buffer-string)))
79+
(when (or python-environment--verbose
80+
(not (= exit-code 0)))
81+
(message output))
8082
(message "%s (SYNC)...Done" msg)
8183
(unless (= exit-code 0)
8284
(error "Command %S exits with error code %S." command exit-code))))

test-python-environment.el

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
(indent 0))
3535
(let ((path (make-symbol "path")))
3636
`(let* ((,path (make-temp-file "pye-test-" t))
37-
(python-environment-root ,path))
37+
(python-environment-directory ,path))
3838
(unwind-protect
3939
(progn ,@body)
4040
(delete-directory ,path t)))))
4141

4242
(defmacro pye-deftest (name args &rest body)
43-
"Customized `ert-deftest'. Bind `python-environment-root' to a
43+
"Customized `ert-deftest'. Bind `python-environment-directory' to a
4444
temporary directory while executing BODY."
4545
(declare (debug (&define :name test
4646
name sexp [&optional stringp]
@@ -83,6 +83,95 @@ variable can be given as ENVIRONMENT (see `pye-with-mixed-environment')."
8383
(error "Subprocess terminated with code %S.\nOutput:\n%s"
8484
code (buffer-string)))))))))
8585

86+
(defmacro pye-test-with-capture-message (&rest form)
87+
(declare (debug (&rest form))
88+
(indent 0))
89+
`(let ((start (make-marker))
90+
(message-buffer (get-buffer "*Messages*")))
91+
(with-current-buffer message-buffer
92+
(set-marker start (point-max)))
93+
(progn ,@form)
94+
(with-current-buffer message-buffer
95+
(buffer-substring start (point-max)))))
96+
97+
(ert-deftest pye-test-test-with-capture-message ()
98+
(should (equal (pye-test-with-capture-message
99+
(message "test-1")
100+
(message "test-2"))
101+
"test-1\ntest-2\n")))
102+
103+
(defun pye-test-proc-runner-output-message (proc-runner desired-output)
104+
(let* ((command '("echo" "DUMMY-ECHO-MESSAGE"))
105+
(python-environment--verbose t)
106+
(message-output
107+
(pye-test-with-capture-message
108+
(funcall proc-runner "DUMMY-MESSAGE" command))))
109+
(should (equal message-output desired-output))))
110+
111+
(ert-deftest pye-test-deferred-process-output-message ()
112+
(pye-test-proc-runner-output-message
113+
(lambda (msg command)
114+
(deferred:sync! (python-environment--deferred-process msg command))) "\
115+
DUMMY-MESSAGE...Done
116+
DUMMY-ECHO-MESSAGE
117+
118+
"))
119+
120+
(ert-deftest pye-test-blocking-process-output-message ()
121+
(pye-test-proc-runner-output-message
122+
#'python-environment--blocking-process "\
123+
DUMMY-MESSAGE (SYNC)...
124+
DUMMY-ECHO-MESSAGE
125+
126+
DUMMY-MESSAGE (SYNC)...Done
127+
"))
128+
129+
(defun pye-test-deferred-process-should-error ()
130+
(let (err)
131+
(deferred:sync!
132+
(deferred:error
133+
(python-environment--deferred-process
134+
"DUMMY-MESSAGE"
135+
'("false"))
136+
(lambda (got) (setq err got))))
137+
(should err)))
138+
139+
(ert-deftest pye-test-deferred-process-error-without-verbose ()
140+
(let ((python-environment--verbose nil))
141+
(pye-test-deferred-process-should-error)))
142+
143+
(ert-deftest pye-test-deferred-process-noerror-without-verbose ()
144+
(let ((python-environment--verbose nil))
145+
(deferred:sync!
146+
(python-environment--deferred-process "DUMMY-MESSAGE" '("true")))))
147+
148+
(ert-deftest pye-test-blocking-process-error-without-verbose ()
149+
(let ((python-environment--verbose nil))
150+
(should-error
151+
(python-environment--blocking-process "DUMMY-MESSAGE" '("false")))))
152+
153+
(ert-deftest pye-test-blocking-process-noerror-without-verbose ()
154+
(let ((python-environment--verbose nil))
155+
(python-environment--blocking-process "DUMMY-MESSAGE" '("true"))))
156+
157+
(ert-deftest pye-test-deferred-process-error-with-verbose ()
158+
(let ((python-environment--verbose t))
159+
(pye-test-deferred-process-should-error)))
160+
161+
(ert-deftest pye-test-deferred-process-noerror-with-verbose ()
162+
(let ((python-environment--verbose t))
163+
(deferred:sync!
164+
(python-environment--deferred-process "DUMMY-MESSAGE" '("true")))))
165+
166+
(ert-deftest pye-test-blocking-process-error-with-verbose ()
167+
(let ((python-environment--verbose t))
168+
(should-error
169+
(python-environment--blocking-process "DUMMY-MESSAGE" '("false")))))
170+
171+
(ert-deftest pye-test-blocking-process-noerror-with-verbose ()
172+
(let ((python-environment--verbose t))
173+
(python-environment--blocking-process "DUMMY-MESSAGE" '("true"))))
174+
86175
(pye-deftest pye-test-make-environment-with-non-existing-command ()
87176
(should-error (python-environment-make nil '("non-existing-command"))))
88177

@@ -103,7 +192,7 @@ variable can be given as ENVIRONMENT (see `pye-with-mixed-environment')."
103192
(should-error (pye-eval-in-subprocess '(error "some error"))))
104193

105194
(pye-deftest pye-test-bare-make-environment ()
106-
(let ((tmp-home python-environment-root))
195+
(let ((tmp-home python-environment-directory))
107196
(pye-eval-in-subprocess '(deferred:sync! (python-environment-make))
108197
`(("HOME" ,tmp-home)))
109198
(should (file-directory-p (expand-file-name

0 commit comments

Comments
 (0)