From d95bbff52a8e293711b14e164e40327909c966bd 2014-01-12 21:54:47 From: Paul Ivanov Date: 2014-01-12 21:54:47 Subject: [PATCH] add test for custom mimetypes --- diff --git a/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js b/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js index 78e6be7..9f5efbe 100644 --- a/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js +++ b/IPython/html/tests/casperjs/test_cases/nb_roundtrip.js @@ -17,7 +17,7 @@ mime = { var black_dot_jpeg="\"\"\"/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 = '\"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QA\\niAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AA\\nAAACAAHiIbwzAAAAAElFTkSuQmCC\"'; -var svg = "\"\"" +var svg = "\"\""; // helper function to ensure that the short_name is found in the toJSON // represetnation, while the original in-memory cell retains its long mimetype @@ -207,5 +207,29 @@ casper.notebook_test(function () { }); this.thenEvaluate(function() { IPython.notebook.save_notebook(); }); - + + 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') + ); + + }); + + this.then(function ( ) { + 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), + 'pyout custom mimetype ' + long_name); + + }); + }); diff --git a/IPython/html/tests/casperjs/util.js b/IPython/html/tests/casperjs/util.js index f071e8f..5204032 100644 --- a/IPython/html/tests/casperjs/util.js +++ b/IPython/html/tests/casperjs/util.js @@ -76,12 +76,13 @@ casper.wait_for_output = function (cell_num) { }; // return the output of a given cell -casper.get_output_cell = function (cell_num) { - var result = casper.evaluate(function (c) { +casper.get_output_cell = function (cell_num, out_num) { + out_num = out_num || 0; + var result = casper.evaluate(function (c, o) { var cell = IPython.notebook.get_cell(c); - return cell.output_area.outputs[0]; + return cell.output_area.outputs[o]; }, - {c : cell_num}); + {c : cell_num, o : out_num}); return result; };