Skip to content

Commit

Permalink
Merge pull request #4971 from ellisonbg/testjs-fd
Browse files Browse the repository at this point in the history
Fixing issues with js tests
  • Loading branch information
minrk committed Feb 1, 2014
2 parents c8de25e + 2582520 commit 869d734
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
19 changes: 18 additions & 1 deletion IPython/html/static/notebook/js/notebook.js
Expand Up @@ -1836,7 +1836,24 @@ var IPython = (function (IPython) {
);
$.ajax(url, settings);
};


Notebook.prototype.delete = function () {
var that = this;
var settings = {
processData : false,
cache : false,
type : "DELETE",
dataType: "json",
};
var url = utils.url_join_encode(
this._baseProjectUrl,
'api/notebooks',
this.notebook_path,
this.notebook_name
);
$.ajax(url, settings);
};


Notebook.prototype.rename_success = function (json, status, xhr) {
this.notebook_name = json.name;
Expand Down
43 changes: 19 additions & 24 deletions IPython/html/tests/casperjs/util.js
Expand Up @@ -18,17 +18,10 @@ casper.open_new_notebook = function () {

this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
this.then(function () {
// XXX: Kind of odd, the next line works for one test, but not when
// running multiple tests back-to-back, so we will just point the main
// casper browser to the same URL as the popup we just grabbed.

//this.page = this.popups[0];
this.open(this.popups[0].url);
});

// initially, the cells aren't created, so wait for them to appear
this.waitForSelector('.CodeMirror-code');
// and make sure the kernel has started
// Make sure the kernel has started
this.waitFor( this.kernel_running );
// track the IPython busy/idle state
this.thenEvaluate(function () {
Expand All @@ -41,7 +34,7 @@ casper.open_new_notebook = function () {
});
};

// return whether or not the kernel is running
// Return whether or not the kernel is running.
casper.kernel_running = function kernel_running() {
return this.evaluate(function kernel_running() {
return IPython.notebook.kernel.running;
Expand All @@ -53,16 +46,15 @@ casper.shutdown_current_kernel = function () {
this.thenEvaluate(function() {
IPython.notebook.kernel.kill();
});
// We close the page right after this so we need to give it time to complete.
this.wait(1000);
};

// Delete created notebook.
casper.delete_current_notebook = function () {
// For some unknown reason, this doesn't work?!?
this.thenEvaluate(function() {
var nbData = $('body').data();
var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
$.ajax(url, {
type: 'DELETE',
});
IPython.notebook.delete();
});
};

Expand Down Expand Up @@ -135,9 +127,7 @@ casper.set_cell_text = function(index, text){
// Inserts a cell at the bottom of the notebook
// Returns the new cell's index.
casper.insert_cell_at_bottom = function(cell_type){
if (cell_type===undefined) {
cell_type = 'code';
}
cell_type = cell_type || 'code';

return this.evaluate(function (cell_type) {
var cell = IPython.notebook.insert_cell_at_bottom(cell_type);
Expand Down Expand Up @@ -210,15 +200,20 @@ casper.cell_element_function = function(index, selector, function_name, function
casper.notebook_test = function(test) {
this.open_new_notebook();
this.then(test);
//XXX: we get sporadic error messages when shutting down some of the tests.
// Since the entire server will go down at the end of running the test
// suite, it's ok for now to not try to shut anything down.

// Kill the kernel and delete the notebook.
this.shutdown_current_kernel();
// This is still broken but shouldn't be a problem for now.
// this.delete_current_notebook();

//XXX: the implementation of delete_current_notebook is currently broken
// it's not a big deal, since the notebook directory will be deleted on
// cleanup, but we should add tests for deleting the notebook separately
//this.delete_current_notebook();
// This is required to clean up the page we just finished with. If we don't call this
// casperjs will leak file descriptors of all the open WebSockets in that page. We
// have to set this.page=null so that next time casper.start runs, it will create a
// new page from scratch.
this.then(function () {
this.page.close();
this.page = null;
});

// Run the browser automation.
this.run(function() {
Expand Down
1 change: 1 addition & 0 deletions IPython/testing/iptestcontroller.py
Expand Up @@ -167,6 +167,7 @@ def __init__(self, section):
self.section = section

self.ipydir = TemporaryDirectory()
# print(self.ipydir.name)
self.dirs.append(self.ipydir)
self.env['IPYTHONDIR'] = self.ipydir.name

Expand Down

0 comments on commit 869d734

Please sign in to comment.