##// END OF EJS Templates
Added debug log to see what is happening...
Jonathan Frederic -
Show More
@@ -1,134 +1,134 b''
1 1 var xor = function (a, b) {return !a ^ !b;};
2 var isArray = function (a) {return toString.call(a) === "[object Array]";};
2 var isArray = function (a) {console.log(toString.call(a)); return toString.call(a) === "[object Array]";};
3 3 var recursive_compare = function(a, b) {
4 4 // Recursively compare two objects.
5 5 var same = true;
6 6 same = same && !xor(a instanceof Object, b instanceof Object);
7 7 same = same && !xor(isArray(a), isArray(b));
8 8
9 9 if (same) {
10 10 if (a instanceof Object) {
11 11 for (var key in a) {
12 12 if (a.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
13 13 same = false;
14 14 break;
15 15 }
16 16 }
17 17 for (var key in b) {
18 18 if (b.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
19 19 same = false;
20 20 break;
21 21 }
22 22 }
23 23 } else {
24 24 return a === b;
25 25 }
26 26 }
27 27
28 28 return same;
29 29 }
30 30
31 31 // Test the widget framework.
32 32 casper.notebook_test(function () {
33 33 var index;
34 34
35 35 this.then(function () {
36 36
37 37 // Check if the WidgetManager class is defined.
38 38 this.test.assert(this.evaluate(function() {
39 39 return IPython.WidgetManager !== undefined;
40 40 }), 'WidgetManager class is defined');
41 41 });
42 42
43 43 index = this.append_cell(
44 44 'from IPython.html import widgets\n' +
45 45 'from IPython.display import display, clear_output\n' +
46 46 'print("Success")');
47 47 this.execute_cell_then(index);
48 48
49 49 this.then(function () {
50 50 // Check if the widget manager has been instantiated.
51 51 this.test.assert(this.evaluate(function() {
52 52 return IPython.notebook.kernel.widget_manager !== undefined;
53 53 }), 'Notebook widget manager instantiated');
54 54
55 55 // Functions that can be used to test the packing and unpacking APIs
56 56 var that = this;
57 57 var test_pack = function (input) {
58 58 var output = that.evaluate(function(input) {
59 59 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
60 60 var results = model._pack_models(input);
61 61 delete model;
62 62 return results;
63 63 }, {input: input});
64 64 that.test.assert(recursive_compare(input, output),
65 65 JSON.stringify(input) + ' passed through Model._pack_model unchanged');
66 66 };
67 67 var test_unpack = function (input) {
68 68 var output = that.evaluate(function(input) {
69 69 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
70 70 var results = model._unpack_models(input);
71 71 delete model;
72 72 return results;
73 73 }, {input: input});
74 74 that.test.assert(recursive_compare(input, output),
75 75 JSON.stringify(input) + ' passed through Model._unpack_model unchanged');
76 76 };
77 77 var test_packing = function(input) {
78 78 test_pack(input);
79 79 test_unpack(input);
80 80 };
81 81
82 82 test_packing({0: 'hi', 1: 'bye'})
83 83 test_packing(['hi', 'bye'])
84 84 test_packing(['hi', 5])
85 85 test_packing(['hi', '5'])
86 86 test_packing([1.0, 0])
87 87 test_packing([1.0, false])
88 88 test_packing([1, false])
89 89 test_packing([1, false, {a: 'hi'}])
90 90 test_packing([1, false, ['hi']])
91 91 });
92 92
93 93 var textbox = {};
94 94 throttle_index = this.append_cell(
95 95 'import time\n' +
96 96 'textbox = widgets.TextWidget()\n' +
97 97 'display(textbox)\n' +
98 98 'textbox.add_class("my-throttle-textbox")\n' +
99 99 'def handle_change(name, old, new):\n' +
100 100 ' print(len(new))\n' +
101 101 ' time.sleep(0.5)\n' +
102 102 'textbox.on_trait_change(handle_change, "value")\n' +
103 103 'print(textbox.model_id)');
104 104 this.execute_cell_then(throttle_index, function(index){
105 105 textbox.model_id = this.get_output_cell(index).text.trim();
106 106
107 107 this.test.assert(this.cell_element_exists(index,
108 108 '.widget-area .widget-subarea'),
109 109 'Widget subarea exists.');
110 110
111 111 this.test.assert(this.cell_element_exists(index,
112 112 '.my-throttle-textbox'), 'Textbox exists.');
113 113
114 114 // Send 20 characters
115 115 this.sendKeys('.my-throttle-textbox', '....................');
116 116 });
117 117
118 118 this.wait_for_widget(textbox);
119 119
120 120 this.then(function () {
121 121 var outputs = this.evaluate(function(i) {
122 122 return IPython.notebook.get_cell(i).output_area.outputs;
123 123 }, {i : throttle_index});
124 124
125 125 // Only 4 outputs should have printed, but because of timing, sometimes
126 126 // 5 outputs will print. All we need to do is verify num outputs <= 5
127 127 // because that is much less than 20.
128 128 this.test.assert(outputs.length <= 5, 'Messages throttled.');
129 129
130 130 // We also need to verify that the last state sent was correct.
131 131 var last_state = outputs[outputs.length-1].text;
132 132 this.test.assertEquals(last_state, "20\n", "Last state sent when throttling.");
133 133 });
134 134 });
General Comments 0
You need to be logged in to leave comments. Login now