|
1 | 1 | (When "^I clear log expr \"\\(.+\\)\"$" |
2 | 2 | (lambda (log-expr) |
3 | | - (with-current-buffer (symbol-value (intern log-expr)) |
4 | | - (let ((inhibit-read-only t)) |
5 | | - (erase-buffer))))) |
| 3 | + (let ((buffer (get-buffer (symbol-value (intern log-expr))))) |
| 4 | + (when (buffer-live-p buffer) |
| 5 | + (with-current-buffer buffer |
| 6 | + (let ((inhibit-read-only t)) |
| 7 | + (erase-buffer))))))) |
6 | 8 |
|
7 | 9 | (When "^I switch to log expr \"\\(.+\\)\"$" |
8 | 10 | (lambda (log-expr) |
|
15 | 17 | (sit-for 0.8) |
16 | 18 | ))) |
17 | 19 |
|
18 | | -(When "^I wait \\([.0-9]+\\) seconds$" |
| 20 | +(When "^I wait \\([.0-9]+\\) seconds?$" |
19 | 21 | (lambda (seconds) |
20 | 22 | (sit-for (string-to-number seconds)))) |
21 | 23 |
|
22 | 24 | (When "^I am in log buffer$" |
23 | 25 | (lambda () |
24 | 26 | (switch-to-buffer ein:log-all-buffer-name))) |
25 | 27 |
|
| 28 | +(defun ein:testing-new-notebook (url-or-port ks) |
| 29 | + (lexical-let (notebook) |
| 30 | + (condition-case err |
| 31 | + (progn |
| 32 | + (ein:notebooklist-new-notebook url-or-port ks nil |
| 33 | + (lambda (nb created &rest ignore) |
| 34 | + (setq notebook nb))) |
| 35 | + (ein:testing-wait-until (lambda () |
| 36 | + (and notebook |
| 37 | + (ein:aand (ein:$notebook-kernel notebook) |
| 38 | + (ein:kernel-live-p it)))) |
| 39 | + nil 10000 2000) |
| 40 | + notebook) |
| 41 | + (error (message "ein:testing-new-notebook: %s" (error-message-string err)) |
| 42 | + (when notebook |
| 43 | + (ein:notebook-close notebook)) |
| 44 | + nil)))) |
| 45 | + |
26 | 46 | (When "^new \\(.+\\) notebook$" |
27 | 47 | (lambda (kernel) |
28 | 48 | (multiple-value-bind (url-or-port token) (ein:jupyter-server-conn-info) |
29 | | - (lexical-let ((ks (ein:get-kernelspec url-or-port kernel)) notebook) |
30 | | - (ein:notebooklist-new-notebook url-or-port ks nil |
31 | | - (lambda (nb created &rest ignore) |
32 | | - (setq notebook nb))) |
33 | | - (ein:testing-wait-until (lambda () (and notebook |
34 | | - (ein:aand (ein:$notebook-kernel notebook) |
35 | | - (ein:kernel-live-p it)))) |
36 | | - nil 10000 2000) |
37 | | - (let ((buf-name (format ein:notebook-buffer-name-template |
38 | | - (ein:$notebook-url-or-port notebook) |
39 | | - (ein:$notebook-notebook-name notebook)))) |
40 | | - (switch-to-buffer buf-name) |
41 | | - (Then "I should be in buffer \"%s\"" buf-name)))))) |
42 | | - |
43 | | -(When "^I open notebooklist" |
44 | | - (lambda () |
45 | | - (multiple-value-bind (url-or-port token) (ein:jupyter-server-conn-info) |
46 | | - (cl-letf (((symbol-function 'ein:notebooklist-ask-url-or-port) |
47 | | - (lambda (&rest args) url-or-port))) |
48 | | - (When "I call \"ein:notebooklist-open\"") |
| 49 | + (with-current-buffer (ein:notebooklist-get-buffer url-or-port) |
| 50 | + (lexical-let ((ks (ein:get-kernelspec url-or-port kernel)) notebook) |
| 51 | + (loop repeat 2 |
| 52 | + until notebook |
| 53 | + do (setq notebook (ein:testing-new-notebook url-or-port ks))) |
| 54 | + (let ((buf-name (format ein:notebook-buffer-name-template |
| 55 | + (ein:$notebook-url-or-port notebook) |
| 56 | + (ein:$notebook-notebook-name notebook)))) |
| 57 | + (switch-to-buffer buf-name) |
| 58 | + (Then "I should be in buffer \"%s\"" buf-name))))))) |
| 59 | + |
| 60 | +(When "^I start \\(and login to \\)?the server configured \"\\(.*\\)\"$" |
| 61 | + (lambda (login config) |
| 62 | + (cl-letf (((symbol-function 'y-or-n-p) #'ignore)) |
| 63 | + (ein:jupyter-server-stop t)) |
| 64 | + (loop repeat 10 |
| 65 | + with buffer = (get-buffer ein:jupyter-server-buffer-name) |
| 66 | + until (null (get-buffer-process buffer)) |
| 67 | + do (sleep-for 1) |
| 68 | + finally do (ein:aif (get-buffer-process buffer) (delete-process it))) |
| 69 | + (When "I clear log expr \"ein:log-all-buffer-name\"") |
| 70 | + (When "I clear log expr \"ein:jupyter-server-buffer-name\"") |
| 71 | + (clrhash ein:notebooklist-map) |
| 72 | + (with-temp-file ".ecukes-temp-config.py" (insert (s-replace "\\n" "\n" config))) |
| 73 | + (setq ein:jupyter-server-args '("--no-browser" "--debug" "--config=.ecukes-temp-config.py")) |
| 74 | + (ein:jupyter-server-start (executable-find "jupyter") |
| 75 | + ein:testing-jupyter-server-root (not login)) |
| 76 | + (if login |
| 77 | + (ein:testing-wait-until (lambda () (ein:notebooklist-list)) nil 20000 1000)))) |
| 78 | + |
| 79 | +(When "^I login to \\([.0-9]+\\)$" |
| 80 | + (lambda (port) |
| 81 | + (cl-letf (((symbol-function 'ein:notebooklist-ask-url-or-port) |
| 82 | + (lambda (&rest args) (ein:url port))) |
| 83 | + ((symbol-function 'read-passwd) |
| 84 | + (lambda (&rest args) "foo"))) |
| 85 | + (with-demoted-errors "demoted: %s" |
| 86 | + (When "I call \"ein:notebooklist-login\"") |
49 | 87 | (And "I wait for the smoke to clear"))))) |
50 | 88 |
|
51 | | -(When "^I login if necessary" |
| 89 | +(When "^I login if necessary$" |
52 | 90 | (lambda () |
53 | 91 | (multiple-value-bind (url-or-port token) (ein:jupyter-server-conn-info) |
54 | 92 | (when token |
|
59 | 97 | (When "I call \"ein:notebooklist-login\"") |
60 | 98 | (And "I wait for the smoke to clear")))))) |
61 | 99 |
|
62 | | -(When "^I wait for the smoke to clear" |
63 | | - (lambda () |
64 | | - (ein:testing-flush-queries))) |
65 | | - |
66 | | -(When "^I enter the prevailing port" |
67 | | - (lambda () |
| 100 | +(When "^I login with password \"\\(.+\\)\"$" |
| 101 | + (lambda (password) |
68 | 102 | (multiple-value-bind (url-or-port token) (ein:jupyter-server-conn-info) |
69 | | - (let ((parsed-url (url-generic-parse-url url-or-port))) |
70 | | - (When "I type \"%d\"") (url-port parsed-url))))) |
| 103 | + (cl-letf (((symbol-function 'ein:notebooklist-ask-url-or-port) |
| 104 | + (lambda (&rest args) url-or-port)) |
| 105 | + ((symbol-function 'read-passwd) |
| 106 | + (lambda (&rest args) password))) |
| 107 | + (When "I call \"ein:notebooklist-login\"") |
| 108 | + (And "I wait for the smoke to clear"))))) |
71 | 109 |
|
72 | 110 | (When "^I wait for the smoke to clear" |
73 | 111 | (lambda () |
|
0 commit comments