Skip to content

Commit 2899a35

Browse files
committed
Add `pythonic-proper-environment-p' function mockup.
1 parent ee5e991 commit 2899a35

File tree

2 files changed

+58
-22
lines changed

2 files changed

+58
-22
lines changed

pythonic.el

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,22 @@ process flag."
206206
(when sentinel
207207
(set-process-sentinel process sentinel))
208208
(set-process-query-on-exit-flag process query-on-exit)
209-
(process-put process 'default-directory default-directory)
210-
(process-put process 'environment python-shell-process-environment)
211-
(process-put process 'path (pythonic-get-path))
212-
(process-put process 'pythonpath (pythonic-get-pythonpath))
209+
(process-put process
210+
'pythonic
211+
(list
212+
:default-directory default-directory
213+
:environment python-shell-process-environment
214+
:path (pythonic-get-path)
215+
:pythonpath (pythonic-get-pythonpath)))
213216
process)))
214217

218+
(defun pythonic-proper-environment-p (process)
219+
"Determine if python environment has been changed since PROCESS was started."
220+
(if (process-get process 'pythonic)
221+
t
222+
(error "Process %s wasn't started with `start-pythonic'"
223+
(process-name process))))
224+
215225
;;;###autoload
216226
(defun pythonic-activate (virtualenv)
217227
"Activate python VIRTUALENV."

test/pythonic-test.el

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,23 @@ remote host."
312312
(python-shell-exec-path '("test"))
313313
(process-environment (list "PATH=/usr/bin" (concat "HOME" "=" home))))
314314
(should (equal "test:/usr/bin"
315-
(process-get
316-
(start-pythonic :process "out" :args '("-V"))
317-
'path)))))
315+
(plist-get
316+
(process-get
317+
(start-pythonic :process "out" :args '("-V"))
318+
'pythonic)
319+
:path)))))
318320

319321
(ert-deftest test-start-pythonic-path-property-tramp ()
320322
"Set `python-shell-exec-path' as `path' process property on remote process."
321323
(unwind-protect
322324
(let* ((python-shell-interpreter "/ssh:test@localhost:/path/to/the/python")
323325
(python-shell-exec-path '("/home/test/bin")))
324326
(should (equal "/home/test/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
325-
(process-get
326-
(start-pythonic :process "out" :args '("-V"))
327-
'path))))
327+
(plist-get
328+
(process-get
329+
(start-pythonic :process "out" :args '("-V"))
330+
'pythonic)
331+
:path))))
328332
(kill-buffer "*tramp/ssh test@localhost*")
329333
(setq tramp-current-connection)
330334
(sleep-for 0.5)))
@@ -335,9 +339,11 @@ remote host."
335339
(python-shell-extra-pythonpaths '("test"))
336340
(process-environment (list "PYTHONPATH=/home/me" (concat "HOME" "=" home))))
337341
(should (equal "test:/home/me"
338-
(process-get
339-
(start-pythonic :process "out" :args '("-V"))
340-
'pythonpath)))))
342+
(plist-get
343+
(process-get
344+
(start-pythonic :process "out" :args '("-V"))
345+
'pythonic)
346+
:pythonpath)))))
341347

342348
(ert-deftest test-start-pythonic-pythonpath-property-tramp ()
343349
"Set `python-shell-extra-pythonpaths' as `pythonpath' process property on remote host.
@@ -348,9 +354,11 @@ Respect remote PYTHONPATH value."
348354
(tramp-send-command ["ssh" "test" "localhost" "" nil]
349355
"export PYTHONPATH=/home/me/modules")
350356
(should (equal "/home/test/modules:/home/me/modules"
351-
(process-get
352-
(start-pythonic :process "out" :args '("-V"))
353-
'pythonpath))))
357+
(plist-get
358+
(process-get
359+
(start-pythonic :process "out" :args '("-V"))
360+
'pythonic)
361+
:pythonpath))))
354362
(kill-buffer "*tramp/ssh test@localhost*")
355363
(setq tramp-current-connection)
356364
(sleep-for 0.5)))
@@ -359,17 +367,35 @@ Respect remote PYTHONPATH value."
359367
"Set `pythonic-default-directory' result as `default-directory' process property."
360368
(let ((default-directorys "~"))
361369
(should (equal (f-full "~")
362-
(process-get
363-
(start-pythonic :process "out" :args '("-V"))
364-
'default-directory)))))
370+
(plist-get
371+
(process-get
372+
(start-pythonic :process "out" :args '("-V"))
373+
'pythonic)
374+
:default-directory)))))
365375

366376
(ert-deftest test-start-pythonic-environment-property ()
367377
"Set `python-shell-process-environment' as `environment' process property."
368378
(let ((python-shell-process-environment '("TEST=t")))
369379
(should (equal '("TEST=t")
370-
(process-get
371-
(start-pythonic :process "out" :args '("-V"))
372-
'environment)))))
380+
(plist-get
381+
(process-get
382+
(start-pythonic :process "out" :args '("-V"))
383+
'pythonic)
384+
:environment)))))
385+
386+
;;; Up to date process environment.
387+
388+
(ert-deftest test-pythonic-proper-environment-p-non-pythonic-process ()
389+
"Applying `pythonic-proper-environment-p' to the process
390+
doesn't started with `start-pythonic' will cause error."
391+
(let ((process (start-process "out" (generate-new-buffer-name "*out*") "python" "-V")))
392+
(should-error (pythonic-proper-environment-p process))))
393+
394+
(ert-deftest test-pythonic-proper-environment-p ()
395+
"`pythonic-proper-environment-p' is true if environment doesn't
396+
change since process was start."
397+
(let ((process (start-pythonic :process "out" :args '("-V"))))
398+
(should (pythonic-proper-environment-p process))))
373399

374400
;;; Activate/deactivate environment.
375401

0 commit comments

Comments
 (0)