##// END OF EJS Templates
Add about dialog in Notebook Help Menu....
Add about dialog in Notebook Help Menu. This allow to get info on version of IPython when running remotely. The about dialog also send a kernel info request and display the banner which is useful for non-python kernel that don't match IPython version

File last commit:

r16568:68000560
r18359:7fd73a83
Show More
roundtrip.js
245 lines | 8.9 KiB | application/javascript | JavascriptLexer
Paul Ivanov
minimal notebook rountrip test
r14125 // Test opening a rich notebook, saving it, and reopening it again.
//
//toJSON fromJSON toJSON and do a string comparison
Paul Ivanov
refactor tests with more concise assertion checks
r14137
// this is just a copy of OutputArea.mime_mape_r in IPython/html/static/notebook/js/outputarea.js
mime = {
"text" : "text/plain",
"html" : "text/html",
"svg" : "image/svg+xml",
"png" : "image/png",
"jpeg" : "image/jpeg",
"latex" : "text/latex",
"json" : "application/json",
"javascript" : "application/javascript",
};
MinRK
b64 unicode literals for images
r14163 var black_dot_jpeg="u\"\"\"/9j/4AAQSkZJRgABAQEASABIAAD/2wBDACodICUgGiolIiUvLSoyP2lEPzo6P4FcYUxpmYagnpaG\nk5GovfLNqLPltZGT0v/V5fr/////o8v///////L/////2wBDAS0vLz83P3xERHz/rpOu////////\n////////////////////////////////////////////////////////////wgARCAABAAEDAREA\nAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAABP/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEA\nAhADEAAAARn/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oACAEBAAEFAn//xAAUEQEAAAAAAAAAAAAA\nAAAAAAAA/9oACAEDAQE/AX//xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oACAECAQE/AX//xAAUEAEA\nAAAAAAAAAAAAAAAAAAAA/9oACAEBAAY/An//xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oACAEBAAE/\nIX//2gAMAwEAAgADAAAAEB//xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oACAEDAQE/EH//xAAUEQEA\nAAAAAAAAAAAAAAAAAAAA/9oACAECAQE/EH//xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oACAEBAAE/\nEH//2Q==\"\"\"";
var black_dot_png = 'u\"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QA\\niAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AA\\nAAACAAHiIbwzAAAAAElFTkSuQmCC\"';
Paul Ivanov
add test for custom mimetypes
r14147 var svg = "\"<svg width='1cm' height='1cm' viewBox='0 0 1000 500'><defs><style>rect {fill:red;}; </style></defs><rect id='r1' x='200' y='100' width='600' height='300' /></svg>\"";
Paul Ivanov
added jpeg mimetype tests
r14145
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 // helper function to ensure that the short_name is found in the toJSON
// represetnation, while the original in-memory cell retains its long mimetype
// name, and that fromJSON also gets its long mimetype name
Paul Ivanov
refactor tests with more concise assertion checks
r14137 function assert_has(short_name, json, result, result2) {
long_name = mime[short_name];
this.test.assertTrue(json[0].hasOwnProperty(short_name),
'toJSON() representation uses ' + short_name);
Paul Ivanov
minor formatting
r14138 this.test.assertTrue(result.hasOwnProperty(long_name),
MinRK
adjustments to nb_roundtrip.js...
r14905 'toJSON() original embedded JSON keeps ' + long_name);
Paul Ivanov
refactor tests with more concise assertion checks
r14137 this.test.assertTrue(result2.hasOwnProperty(long_name),
MinRK
adjustments to nb_roundtrip.js...
r14905 'fromJSON() embedded ' + short_name + ' gets mime key ' + long_name);
Paul Ivanov
refactor tests with more concise assertion checks
r14137 }
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139
// helper function for checkout that the first two cells have a particular
MinRK
pyout -> execute_result...
r16568 // output_type (either 'execute_result' or 'display_data'), and checks the to/fromJSON
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 // for a set of mimetype keys, using their short names ('javascript', 'text',
// 'png', etc).
function check_output_area(output_type, keys) {
Paul Ivanov
adding png mimetype tests
r14144 this.wait_for_output(0);
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 json = this.evaluate(function() {
var json = IPython.notebook.get_cell(0).output_area.toJSON();
MinRK
adjustments to nb_roundtrip.js...
r14905 // appended cell will initially be empty, let's add some output
IPython.notebook.get_cell(1).output_area.fromJSON(json);
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 return json;
});
MinRK
adjustments to nb_roundtrip.js...
r14905 // The evaluate call above happens asynchronously: wait for cell[1] to have output
Paul Ivanov
minor js test fix
r14185 this.wait_for_output(1);
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 var result = this.get_output_cell(0);
var result2 = this.get_output_cell(1);
this.test.assertEquals(result.output_type, output_type,
'testing ' + output_type + ' for ' + keys.join(' and '));
for (var idx in keys) {
assert_has.apply(this, [keys[idx], json, result, result2]);
}
}
Paul Ivanov
refactor tests with more concise assertion checks
r14137
Paul Ivanov
refactor clearing and executing first cell in test
r14141
// helper function to clear the first two cells, set the text of and execute
// the first one
function clear_and_execute(that, code) {
that.evaluate(function() {
IPython.notebook.get_cell(0).clear_output();
IPython.notebook.get_cell(1).clear_output();
});
MinRK
adjust some events in nb_roundtrip...
r15244 that.then(function () {
that.set_cell_text(0, code);
that.execute_cell(0);
that.wait_for_idle();
});
};
Paul Ivanov
refactor clearing and executing first cell in test
r14141
Paul Ivanov
minimal notebook rountrip test
r14125 casper.notebook_test(function () {
this.evaluate(function () {
var cell = IPython.notebook.get_cell(0);
// "we have to make messes to find out who we are"
cell.set_text([
"%%javascript",
Paul Ivanov
add (failling) roundtrip test case
r14126 "IPython.notebook.insert_cell_below('code')"
Paul Ivanov
minimal notebook rountrip test
r14125 ].join('\n')
);
});
Paul Ivanov
plain text and json display_data and pyout tests
r14129
MinRK
adjust some events in nb_roundtrip...
r15244 this.execute_cell_then(0, function () {
Paul Ivanov
add (failling) roundtrip test case
r14126 var result = this.get_output_cell(0);
Paul Ivanov
minimal notebook rountrip test
r14125 var num_cells = this.get_cells_length();
this.test.assertEquals(num_cells, 2, '%%javascript magic works');
Paul Ivanov
add (failling) roundtrip test case
r14126 this.test.assertTrue(result.hasOwnProperty('application/javascript'),
MinRK
adjustments to nb_roundtrip.js...
r14905 'testing JS embedded with mime key');
Paul Ivanov
minimal notebook rountrip test
r14125 });
Paul Ivanov
add (failling) roundtrip test case
r14126 //this.thenEvaluate(function() { IPython.notebook.save_notebook(); });
MinRK
adjustments to nb_roundtrip.js...
r14905 this.then(function () {
clear_and_execute(this, [
"%%javascript",
"var a=5;"
].join('\n'));
});
Paul Ivanov
add (failling) roundtrip test case
r14126
MinRK
adjustments to nb_roundtrip.js...
r14905 this.then(function () {
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 check_output_area.apply(this, ['display_data', ['javascript']]);
Paul Ivanov
add (failling) roundtrip test case
r14126
});
Paul Ivanov
minimal notebook rountrip test
r14125
Paul Ivanov
plain text and json display_data and pyout tests
r14129 this.then(function() {
Paul Ivanov
refactor clearing and executing first cell in test
r14141 clear_and_execute(this, '%lsmagic');
Paul Ivanov
plain text and json display_data and pyout tests
r14129 });
Paul Ivanov
refactor tests with more concise assertion checks
r14137
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 this.then(function () {
MinRK
pyout -> execute_result...
r16568 check_output_area.apply(this, ['execute_result', ['text', 'json']]);
Paul Ivanov
plain text and json display_data and pyout tests
r14129 });
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139
Paul Ivanov
plain text and json display_data and pyout tests
r14129 this.then(function() {
Paul Ivanov
refactor clearing and executing first cell in test
r14141 clear_and_execute(this,
Paul Ivanov
plain text and json display_data and pyout tests
r14129 "x = %lsmagic\nfrom IPython.display import display; display(x)");
});
this.then(function ( ) {
Paul Ivanov
more refactoring - test to/fromJSON for mimetypes
r14139 check_output_area.apply(this, ['display_data', ['text', 'json']]);
Paul Ivanov
plain text and json display_data and pyout tests
r14129 });
Paul Ivanov
add test for latex to/fromJSON
r14142
this.then(function() {
clear_and_execute(this,
"from IPython.display import Latex; Latex('$X^2$')");
});
this.then(function ( ) {
MinRK
pyout -> execute_result...
r16568 check_output_area.apply(this, ['execute_result', ['text', 'latex']]);
Paul Ivanov
add test for latex to/fromJSON
r14142 });
this.then(function() {
clear_and_execute(this,
"from IPython.display import Latex, display; display(Latex('$X^2$'))");
});
this.then(function ( ) {
check_output_area.apply(this, ['display_data', ['text', 'latex']]);
});
Paul Ivanov
tests for HTML mimetype
r14143
this.then(function() {
clear_and_execute(this,
"from IPython.display import HTML; HTML('<b>it works!</b>')");
});
this.then(function ( ) {
MinRK
pyout -> execute_result...
r16568 check_output_area.apply(this, ['execute_result', ['text', 'html']]);
Paul Ivanov
tests for HTML mimetype
r14143 });
this.then(function() {
clear_and_execute(this,
"from IPython.display import HTML, display; display(HTML('<b>it works!</b>'))");
});
this.then(function ( ) {
check_output_area.apply(this, ['display_data', ['text', 'html']]);
});
Paul Ivanov
plain text and json display_data and pyout tests
r14129
Paul Ivanov
adding png mimetype tests
r14144
this.then(function() {
clear_and_execute(this,
Paul Ivanov
added jpeg mimetype tests
r14145 "from IPython.display import Image; Image(" + black_dot_png + ")");
Paul Ivanov
adding png mimetype tests
r14144 });
Paul Ivanov
added jpeg mimetype tests
r14145 this.thenEvaluate(function() { IPython.notebook.save_notebook(); });
Paul Ivanov
adding png mimetype tests
r14144
this.then(function ( ) {
MinRK
pyout -> execute_result...
r16568 check_output_area.apply(this, ['execute_result', ['text', 'png']]);
Paul Ivanov
adding png mimetype tests
r14144 });
this.then(function() {
clear_and_execute(this,
Paul Ivanov
added jpeg mimetype tests
r14145 "from IPython.display import Image, display; display(Image(" + black_dot_png + "))");
Paul Ivanov
adding png mimetype tests
r14144 });
this.then(function ( ) {
check_output_area.apply(this, ['display_data', ['text', 'png']]);
});
Paul Ivanov
added jpeg mimetype tests
r14145
this.then(function() {
clear_and_execute(this,
"from IPython.display import Image; Image(" + black_dot_jpeg + ", format='jpeg')");
});
this.then(function ( ) {
MinRK
pyout -> execute_result...
r16568 check_output_area.apply(this, ['execute_result', ['text', 'jpeg']]);
Paul Ivanov
added jpeg mimetype tests
r14145 });
this.then(function() {
clear_and_execute(this,
"from IPython.display import Image, display; display(Image(" + black_dot_jpeg + ", format='jpeg'))");
});
this.then(function ( ) {
check_output_area.apply(this, ['display_data', ['text', 'jpeg']]);
});
Paul Ivanov
added svg to/fromJSON tests
r14146
this.then(function() {
clear_and_execute(this,
"from IPython.core.display import SVG; SVG(" + svg + ")");
});
this.then(function ( ) {
MinRK
pyout -> execute_result...
r16568 check_output_area.apply(this, ['execute_result', ['text', 'svg']]);
Paul Ivanov
added svg to/fromJSON tests
r14146 });
this.then(function() {
clear_and_execute(this,
"from IPython.core.display import SVG, display; display(SVG(" + svg + "))");
});
this.then(function ( ) {
check_output_area.apply(this, ['display_data', ['text', 'svg']]);
});
this.thenEvaluate(function() { IPython.notebook.save_notebook(); });
Paul Ivanov
add test for custom mimetypes
r14147
this.then(function() {
clear_and_execute(this, [
"from IPython.core.formatters import HTMLFormatter",
"x = HTMLFormatter()",
"x.format_type = 'text/superfancymimetype'",
"get_ipython().display_formatter.formatters['text/superfancymimetype'] = x",
"from IPython.display import HTML, display",
'display(HTML("yo"))',
"HTML('hello')"].join('\n')
);
});
MinRK
adjustments to nb_roundtrip.js...
r14905 this.wait_for_output(0, 1);
this.then(function () {
Paul Ivanov
add test for custom mimetypes
r14147 var long_name = 'text/superfancymimetype';
var result = this.get_output_cell(0);
this.test.assertTrue(result.hasOwnProperty(long_name),
'display_data custom mimetype ' + long_name);
var result = this.get_output_cell(0, 1);
this.test.assertTrue(result.hasOwnProperty(long_name),
MinRK
pyout -> execute_result...
r16568 'execute_result custom mimetype ' + long_name);
Paul Ivanov
add test for custom mimetypes
r14147
});
Paul Ivanov
minimal notebook rountrip test
r14125 });