Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,325 @@
//
// Kernel tests
//
casper.notebook_test(function () {
// test that the kernel is running
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel is running');
});
// test list
this.thenEvaluate(function () {
IPython._kernels = null;
IPython.notebook.kernel.list(function (data) {
IPython._kernels = data;
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython._kernels !== null;
});
});
this.then(function () {
var num_kernels = this.evaluate(function () {
return IPython._kernels.length;
});
this.test.assertEquals(num_kernels, 1, 'one kernel running');
});
// test get_info
var kernel_info = this.evaluate(function () {
return {
name: IPython.notebook.kernel.name,
id: IPython.notebook.kernel.id
};
});
this.thenEvaluate(function () {
IPython._kernel_info = null;
IPython.notebook.kernel.get_info(function (data) {
IPython._kernel_info = data;
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython._kernel_info !== null;
});
});
this.then(function () {
var new_kernel_info = this.evaluate(function () {
return IPython._kernel_info;
});
this.test.assertEquals(kernel_info.name, new_kernel_info.name, 'kernel: name correct');
this.test.assertEquals(kernel_info.id, new_kernel_info.id, 'kernel: id correct');
});
// test interrupt
this.thenEvaluate(function () {
IPython._interrupted = false;
IPython.notebook.kernel.interrupt(function () {
IPython._interrupted = true;
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython._interrupted;
});
});
this.then(function () {
var interrupted = this.evaluate(function () {
return IPython._interrupted;
});
this.test.assert(interrupted, 'kernel was interrupted');
});
// test restart
this.thenEvaluate(function () {
IPython.notebook.kernel.restart();
});
this.waitFor(this.kernel_disconnected);
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel restarted');
});
// test reconnect
this.thenEvaluate(function () {
IPython.notebook.kernel.stop_channels();
});
this.waitFor(this.kernel_disconnected);
this.thenEvaluate(function () {
IPython.notebook.kernel.reconnect();
});
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel reconnected');
});
// test kernel_info_request
this.evaluate(function () {
IPython.notebook.kernel.kernel_info(
function(msg){
IPython._kernel_info_response = msg;
});
});
this.waitFor(
function () {
return this.evaluate(function(){
return IPython._kernel_info_response;
});
});
this.then(function () {
var kernel_info_response = this.evaluate(function(){
return IPython._kernel_info_response;
});
this.test.assertTrue( kernel_info_response.msg_type === 'kernel_info_reply', 'Kernel info request return kernel_info_reply');
this.test.assertTrue( kernel_info_response.content !== undefined, 'Kernel_info_reply is not undefined');
});
// test kill
this.thenEvaluate(function () {
IPython.notebook.kernel.kill();
});
this.waitFor(this.kernel_disconnected);
this.then(function () {
this.test.assert(!this.kernel_running(), 'kernel is not running');
});
// test start
var url, base_url;
this.then(function () {
base_url = this.evaluate(function () {
return IPython.notebook.base_url;
});
url = this.evaluate(function () {
return IPython.notebook.kernel.start();
});
});
this.then(function () {
this.test.assertEquals(url, base_url + "api/kernels", "start url is correct");
});
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel is running');
});
// test start with parameters
this.thenEvaluate(function () {
IPython.notebook.kernel.kill();
});
this.waitFor(this.kernel_disconnected);
this.then(function () {
url = this.evaluate(function () {
return IPython.notebook.kernel.start({foo: "bar"});
});
});
this.then(function () {
this.test.assertEquals(url, base_url + "api/kernels?foo=bar", "start url with params is correct");
});
this.wait_for_kernel_ready();
this.then(function () {
this.test.assert(this.kernel_running(), 'kernel is running');
});
// check for events in kill/start cycle
this.event_test(
'kill/start',
[
'kernel_killed.Kernel',
'kernel_starting.Kernel',
'kernel_created.Kernel',
'kernel_connected.Kernel',
'kernel_ready.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.kill();
});
this.waitFor(this.kernel_disconnected);
this.thenEvaluate(function () {
IPython.notebook.kernel.start();
});
}
);
// wait for any last idle/busy messages to be handled
this.wait_for_kernel_ready();
// check for events in disconnect/connect cycle
this.event_test(
'reconnect',
[
'kernel_reconnecting.Kernel',
'kernel_connected.Kernel',
],
function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.stop_channels();
IPython.notebook.kernel.reconnect(1);
});
}
);
// wait for any last idle/busy messages to be handled
this.wait_for_kernel_ready();
// check for events in the restart cycle
this.event_test(
'restart',
[
'kernel_restarting.Kernel',
'kernel_created.Kernel',
'kernel_connected.Kernel',
'kernel_ready.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.restart();
});
}
);
// wait for any last idle/busy messages to be handled
this.wait_for_kernel_ready();
// check for events in the interrupt cycle
this.event_test(
'interrupt',
[
'kernel_interrupting.Kernel',
'kernel_busy.Kernel',
'kernel_idle.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.kernel.interrupt();
});
}
);
this.wait_for_kernel_ready();
// check for events after ws close
this.event_test(
'ws_closed_ok',
[
'kernel_disconnected.Kernel',
'kernel_reconnecting.Kernel',
'kernel_connected.Kernel',
'kernel_busy.Kernel',
'kernel_idle.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.kernel._ws_closed("", false);
});
}
);
// wait for any last idle/busy messages to be handled
this.wait_for_kernel_ready();
// check for events after ws close (error)
this.event_test(
'ws_closed_error',
[
'kernel_disconnected.Kernel',
'kernel_connection_failed.Kernel',
'kernel_reconnecting.Kernel',
'kernel_connected.Kernel',
'kernel_busy.Kernel',
'kernel_idle.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.kernel._ws_closed("", true);
});
}
);
// wait for any last idle/busy messages to be handled
this.wait_for_kernel_ready();
// start the kernel back up
this.thenEvaluate(function () {
IPython.notebook.kernel.restart();
});
this.waitFor(this.kernel_running);
this.wait_for_kernel_ready();
// test handling of autorestarting messages
this.event_test(
'autorestarting',
[
'kernel_restarting.Kernel',
'kernel_autorestarting.Kernel',
],
function () {
this.thenEvaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('import os\n' + 'os._exit(1)');
cell.execute();
});
}
);
this.wait_for_kernel_ready();
// test handling of failed restart
this.event_test(
'failed_restart',
[
'kernel_restarting.Kernel',
'kernel_autorestarting.Kernel',
'kernel_dead.Kernel'
],
function () {
this.thenEvaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text("import os\n" +
"from IPython.kernel.connect import get_connection_file\n" +
"with open(get_connection_file(), 'w') as f:\n" +
" f.write('garbage')\n" +
"os._exit(1)");
cell.execute();
});
},
// need an extra-long timeout, because it needs to try
// restarting the kernel 5 times!
20000
);
});

View file

@ -0,0 +1,123 @@
//
// Test binary messages on websockets.
// Only works on slimer for now, due to old websocket impl in phantomjs.
//
casper.notebook_test(function () {
// create EchoBuffers target on js-side.
// it just captures and echos comm messages.
this.then(function () {
var success = this.evaluate(function () {
IPython._msgs = [];
var EchoBuffers = function(comm) {
this.comm = comm;
this.comm.on_msg($.proxy(this.on_msg, this));
};
EchoBuffers.prototype.on_msg = function (msg) {
IPython._msgs.push(msg);
this.comm.send(msg.content.data, {}, {}, msg.buffers);
};
IPython.notebook.kernel.comm_manager.register_target("echo", function (comm) {
return new EchoBuffers(comm);
});
return true;
});
this.test.assertEquals(success, true, "Created echo comm target");
});
// Create a similar comm that captures messages Python-side
this.then(function () {
var index = this.append_cell([
"import os",
"from IPython.kernel.comm import Comm",
"comm = Comm(target_name='echo')",
"msgs = []",
"def on_msg(msg):",
" msgs.append(msg)",
"comm.on_msg(on_msg)"
].join('\n'), 'code');
this.execute_cell(index);
});
// send a message with binary data
this.then(function () {
var index = this.append_cell([
"buffers = [b'\\xFF\\x00', b'\\x00\\x01\\x02']",
"comm.send(data='message 0', buffers=buffers)",
"comm.send(data='message 1')",
"comm.send(data='message 2', buffers=buffers)",
].join('\n'), 'code');
this.execute_cell(index);
});
// wait for capture
this.waitFor(function () {
return this.evaluate(function () {
return IPython._msgs.length >= 3;
});
});
// validate captured buffers js-side
this.then(function () {
var msgs = this.evaluate(function () {
return IPython._msgs;
});
this.test.assertEquals(msgs.length, 3, "Captured three comm messages");
// check the messages came in the right order
this.test.assertEquals(msgs[0].content.data, "message 0", "message 0 processed first");
this.test.assertEquals(msgs[0].buffers.length, 2, "comm message 0 has two buffers");
this.test.assertEquals(msgs[1].content.data, "message 1", "message 1 processed second");
this.test.assertEquals(msgs[1].buffers.length, 0, "comm message 1 has no buffers");
this.test.assertEquals(msgs[2].content.data, "message 2", "message 2 processed third");
this.test.assertEquals(msgs[2].buffers.length, 2, "comm message 2 has two buffers");
// extract attributes to test in evaluate,
// because the raw DataViews can't be passed across
var buf_info = function (message, index) {
var buf = IPython._msgs[message].buffers[index];
var data = {};
data.byteLength = buf.byteLength;
data.bytes = [];
for (var i = 0; i < data.byteLength; i++) {
data.bytes.push(buf.getUint8(i));
}
return data;
};
var msgs_with_buffers = [0, 2];
for (var i = 0; i < msgs_with_buffers.length; i++) {
msg_index = msgs_with_buffers[i];
buf0 = this.evaluate(buf_info, msg_index, 0);
buf1 = this.evaluate(buf_info, msg_index, 1);
this.test.assertEquals(buf0.byteLength, 2, 'buf[0] has correct size in message '+msg_index);
this.test.assertEquals(buf0.bytes, [255, 0], 'buf[0] has correct bytes in message '+msg_index);
this.test.assertEquals(buf1.byteLength, 3, 'buf[1] has correct size in message '+msg_index);
this.test.assertEquals(buf1.bytes, [0, 1, 2], 'buf[1] has correct bytes in message '+msg_index);
}
});
// validate captured buffers Python-side
this.then(function () {
var index = this.append_cell([
"assert len(msgs) == 3, len(msgs)",
"bufs = msgs[0]['buffers']",
"assert len(bufs) == len(buffers), bufs",
"assert bufs[0].tobytes() == buffers[0], bufs[0]",
"assert bufs[1].tobytes() == buffers[1], bufs[1]",
"1",
].join('\n'), 'code');
this.execute_cell(index);
this.wait_for_output(index);
this.then(function () {
var out = this.get_output_cell(index);
this.test.assertEquals(out.data['text/plain'], '1', "Python received buffers");
});
});
});

View file

@ -0,0 +1,186 @@
//
// Tests for the Session object
//
casper.notebook_test(function () {
var that = this;
var get_info = function () {
return that.evaluate(function () {
return JSON.parse(JSON.stringify(IPython.notebook.session._get_model()));
});
};
// test that the kernel is running
this.then(function () {
this.test.assert(this.kernel_running(), 'session: kernel is running');
});
// test list
this.thenEvaluate(function () {
IPython._sessions = null;
IPython.notebook.session.list(function (data) {
IPython._sessions = data;
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython._sessions !== null;
});
});
this.then(function () {
var num_sessions = this.evaluate(function () {
return IPython._sessions.length;
});
this.test.assertEquals(num_sessions, 1, 'one session running');
});
// test get_info
var session_info = get_info();
this.thenEvaluate(function () {
IPython._session_info = null;
IPython.notebook.session.get_info(function (data) {
IPython._session_info = data;
});
});
this.waitFor(function () {
return this.evaluate(function () {
return IPython._session_info !== null;
});
});
this.then(function () {
var new_session_info = this.evaluate(function () {
return IPython._session_info;
});
this.test.assertEquals(session_info.name, new_session_info.name, 'session: notebook name correct');
this.test.assertEquals(session_info.path, new_session_info.path, 'session: notebook path correct');
this.test.assertEquals(session_info.kernel.name, new_session_info.kernel.name, 'session: kernel name correct');
this.test.assertEquals(session_info.kernel.id, new_session_info.kernel.id, 'session: kernel id correct');
});
// test rename_notebook
//
// TODO: the PATCH request isn't supported by phantom, so this test always
// fails, see https://github.com/ariya/phantomjs/issues/11384
// when this is fixed we can properly run this test
//
// this.thenEvaluate(function () {
// IPython._renamed = false;
// IPython.notebook.session.rename_notebook(
// "foo",
// "bar",
// function (data) {
// IPython._renamed = true;
// }
// );
// });
// this.waitFor(function () {
// return this.evaluate(function () {
// return IPython._renamed;
// });
// });
// this.then(function () {
// var info = get_info();
// this.test.assertEquals(info.notebook.name, "foo", "notebook was renamed");
// this.test.assertEquals(info.notebook.path, "bar", "notebook path was changed");
// });
// test delete
this.thenEvaluate(function () {
IPython.notebook.session.delete();
});
this.waitFor(this.kernel_disconnected);
this.then(function () {
this.test.assert(!this.kernel_running(), 'session deletes kernel');
});
// check for events when starting the session
this.event_test(
'start_session',
[
'kernel_created.Session',
'kernel_connected.Kernel',
'kernel_ready.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.session.start();
});
}
);
this.wait_for_kernel_ready();
// check for events when killing the session
this.event_test(
'delete_session',
['kernel_killed.Session'],
function () {
this.thenEvaluate(function () {
IPython.notebook.session.delete();
});
}
);
this.thenEvaluate( function() {IPython.notebook.session.start()});
this.wait_for_kernel_ready();
// check for events when restarting the session
this.event_test(
'restart_session',
[
'kernel_killed.Session',
'kernel_created.Session',
'kernel_connected.Kernel',
'kernel_ready.Kernel'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.session.restart();
});
}
);
this.wait_for_kernel_ready();
// test handling of failed restart
this.event_test(
'failed_restart',
[
'kernel_restarting.Kernel',
'kernel_autorestarting.Kernel',
'kernel_killed.Session',
'kernel_dead.Kernel',
],
function () {
this.thenEvaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text("import os\n" +
"from IPython.kernel.connect import get_connection_file\n" +
"with open(get_connection_file(), 'w') as f:\n" +
" f.write('garbage')\n" +
"os._exit(1)");
cell.execute();
});
},
// need an extra-long timeout, because it needs to try
// restarting the kernel 5 times!
20000
);
this.thenEvaluate( function() {IPython.notebook.session.start()});
this.wait_for_kernel_ready();
// check for events when starting a nonexistent kernel
this.event_test(
'bad_start_session',
[
'kernel_killed.Session',
'kernel_dead.Session'
],
function () {
this.thenEvaluate(function () {
IPython.notebook.session.restart({kernel_name: 'foo'});
});
}
);
});