2
2
// Test buffering for execution requests.
3
3
//
4
4
casper . notebook_test ( function ( ) {
5
- this . evaluate ( function ( ) {
5
+ this . then ( function ( ) {
6
+ // make sure there are at least three cells for the tests below.
7
+ this . append_cell ( ) ;
8
+ this . append_cell ( ) ;
9
+ this . append_cell ( ) ;
10
+ } )
11
+
12
+ this . thenEvaluate ( function ( ) {
13
+ IPython . notebook . kernel . stop_channels ( ) ;
6
14
var cell = IPython . notebook . get_cell ( 0 ) ;
7
15
cell . set_text ( 'a=10; print(a)' ) ;
8
- IPython . notebook . kernel . stop_channels ( ) ;
9
16
IPython . notebook . execute_cells ( [ 0 ] ) ;
10
17
IPython . notebook . kernel . reconnect ( 1 ) ;
11
18
} ) ;
@@ -16,7 +23,7 @@ casper.notebook_test(function () {
16
23
var result = this . get_output_cell ( 0 ) ;
17
24
this . test . assertEquals ( result . text , '10\n' , 'kernels buffer execution requests if connection is down' ) ;
18
25
} ) ;
19
-
26
+
20
27
this . thenEvaluate ( function ( ) {
21
28
var cell = IPython . notebook . get_cell ( 0 ) ;
22
29
cell . set_text ( 'a=11; print(a)' ) ;
@@ -33,4 +40,71 @@ casper.notebook_test(function () {
33
40
this . test . assertEquals ( result . text , '11\n' , 'notebooks buffer cell execution requests if kernel is not set' ) ;
34
41
} ) ;
35
42
43
+ // Repeated execution behavior differs in the two queues
44
+
45
+ this . thenEvaluate ( function ( ) {
46
+
47
+ var cell = IPython . notebook . get_cell ( 0 ) ;
48
+ var cellplus = IPython . notebook . get_cell ( 1 ) ;
49
+ var cellprint = IPython . notebook . get_cell ( 2 ) ;
50
+ cell . set_text ( 'k=1' ) ;
51
+ cellplus . set_text ( 'k+=1' ) ;
52
+ cellprint . set_text ( 'k*=2' )
53
+
54
+ IPython . notebook . kernel . stop_channels ( ) ;
55
+
56
+ // Repeated execution of cell queued up in the kernel executes
57
+ // each execution request.
58
+ IPython . notebook . execute_cells ( [ 0 ] ) ;
59
+ IPython . notebook . execute_cells ( [ 2 ] ) ;
60
+ IPython . notebook . execute_cells ( [ 1 ] ) ;
61
+ IPython . notebook . execute_cells ( [ 1 ] ) ;
62
+ IPython . notebook . execute_cells ( [ 1 ] ) ;
63
+ cellprint . set_text ( 'print(k)' )
64
+ IPython . notebook . execute_cells ( [ 2 ] ) ;
65
+
66
+ IPython . notebook . kernel . reconnect ( 1 ) ;
67
+ } ) ;
68
+
69
+ this . wait_for_output ( 2 ) ;
70
+
71
+ this . then ( function ( ) {
72
+ var result = this . get_output_cell ( 2 ) ;
73
+ this . test . assertEquals ( result . text , '5\n' , 'kernel message buffer sends each message queued' ) ;
74
+ } ) ;
75
+
76
+ this . thenEvaluate ( function ( ) {
77
+
78
+ var cell = IPython . notebook . get_cell ( 0 ) ;
79
+ var cellplus = IPython . notebook . get_cell ( 1 ) ;
80
+ var cellprint = IPython . notebook . get_cell ( 2 ) ;
81
+ cell . set_text ( 'n=1' ) ;
82
+ cellplus . set_text ( 'n+=1' ) ;
83
+ cellprint . set_text ( 'n*=2' )
84
+
85
+ cell . kernel = null ;
86
+ cellplus . kernel = null ;
87
+ cellprint . kernel = null ;
88
+ IPython . notebook . kernel = null ;
89
+
90
+ // Repeated execution of cell queued up in the notebook moves the cell
91
+ // to the end of the queue, only executing it once.
92
+ IPython . notebook . execute_cells ( [ 0 ] ) ;
93
+ IPython . notebook . execute_cells ( [ 2 ] ) ;
94
+ IPython . notebook . execute_cells ( [ 1 ] ) ;
95
+ IPython . notebook . execute_cells ( [ 1 ] ) ;
96
+ IPython . notebook . execute_cells ( [ 1 ] ) ;
97
+ cellprint . set_text ( 'print(n)' )
98
+ IPython . notebook . execute_cells ( [ 2 ] ) ;
99
+
100
+ IPython . notebook . _session_started ( ) ;
101
+ } ) ;
102
+
103
+ this . wait_for_output ( 2 ) ;
104
+
105
+ this . then ( function ( ) {
106
+ var result = this . get_output_cell ( 2 ) ;
107
+ this . test . assertEquals ( result . text , '2\n' , 'notebook execution buffer moves repeatedly executed cell to end of queue' ) ;
108
+ } ) ;
109
+
36
110
} ) ;
0 commit comments