浏览代码

Update main tests

Steven Silvester 8 年之前
父节点
当前提交
4b186775ee
共有 3 个文件被更改,包括 86 次插入42 次删除
  1. 6 8
      test/src/apputils/toolbar.spec.ts
  2. 26 26
      test/src/cells/widget.spec.ts
  3. 54 8
      test/src/outputarea/widget.spec.ts

+ 6 - 8
test/src/apputils/toolbar.spec.ts

@@ -177,7 +177,7 @@ describe('@jupyterlab/apputils', () => {
         });
       });
 
-      it('should display a busy status if the kernel status is not idle', (done) => {
+      it('should display a busy status if the kernel status is not idle', () => {
         let item = Toolbar.createKernelStatusItem(session);
         let called = false;
         let future = session.kernel.requestExecute({ code: 'a = 1' });
@@ -187,13 +187,12 @@ describe('@jupyterlab/apputils', () => {
             called = true;
           }
         };
-        future.onDone = () => {
+        return future.done.then(() => {
           expect(called).to.be(true);
-          done();
-        };
+        });
       });
 
-      it('should show the current status in the node title', (done) => {
+      it('should show the current status in the node title', () => {
         let item = Toolbar.createKernelStatusItem(session);
         let status = session.status;
         expect(item.node.title.toLowerCase()).to.contain(status);
@@ -205,10 +204,9 @@ describe('@jupyterlab/apputils', () => {
             called = true;
           }
         };
-        future.onDone = () => {
+        return future.done.then(() => {
           expect(called).to.be(true);
-          done();
-        };
+        });
       });
 
       it('should handle a starting session', () => {

+ 26 - 26
test/src/cells/widget.spec.ts

@@ -409,7 +409,30 @@ describe('cells/widget', () => {
 
     });
 
-    describe('#execute()', () => {
+    describe('#onUpdateRequest()', () => {
+
+      it('should update the widget', () => {
+        let widget = new LogCodeCell();
+        expect(widget.methods).to.not.contain('onUpdateRequest');
+        MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
+        expect(widget.methods).to.contain('onUpdateRequest');
+      });
+
+    });
+
+    describe('#onMetadataChanged()', () => {
+
+      it('should fire when model metadata changes', () => {
+        let method = 'onMetadataChanged';
+        let widget = new LogCodeCell();
+        expect(widget.methods).to.not.contain(method);
+        widget.model.metadata.set('foo', 1);
+        expect(widget.methods).to.contain(method);
+      });
+
+    });
+
+    describe('.execute()', () => {
 
       let session: IClientSession;
 
@@ -428,7 +451,7 @@ describe('cells/widget', () => {
 
       it('should fulfill a promise if there is no code to execute', () => {
         let widget = new CodeCell({ model, rendermime, contentFactory });
-        return widget.execute(session);
+        return CodeCell.execute(widget, session);
       });
 
       it('should fulfill a promise if there is code to execute', () => {
@@ -436,7 +459,7 @@ describe('cells/widget', () => {
         let originalCount: number;
         widget.model.value.text = 'foo';
         originalCount = (widget.model).executionCount;
-        return widget.execute(session).then(() => {
+        return CodeCell.execute(widget, session).then(() => {
           let executionCount = (widget.model).executionCount;
           expect(executionCount).to.not.equal(originalCount);
         });
@@ -444,29 +467,6 @@ describe('cells/widget', () => {
 
     });
 
-    describe('#onUpdateRequest()', () => {
-
-      it('should update the widget', () => {
-        let widget = new LogCodeCell();
-        expect(widget.methods).to.not.contain('onUpdateRequest');
-        MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
-        expect(widget.methods).to.contain('onUpdateRequest');
-      });
-
-    });
-
-    describe('#onMetadataChanged()', () => {
-
-      it('should fire when model metadata changes', () => {
-        let method = 'onMetadataChanged';
-        let widget = new LogCodeCell();
-        expect(widget.methods).to.not.contain(method);
-        widget.model.metadata.set('foo', 1);
-        expect(widget.methods).to.contain(method);
-      });
-
-    });
-
   });
 
   describe('MarkdownCell', () => {

+ 54 - 8
test/src/outputarea/widget.spec.ts

@@ -33,6 +33,8 @@ import {
  */
 const rendermime = defaultRenderMime();
 
+const CODE = 'print("hello")';
+
 
 class LogOutputArea extends OutputArea {
 
@@ -120,7 +122,7 @@ describe('outputarea/widget', () => {
 
     });
 
-    describe('#execute()', () => {
+    describe('#future', () => {
 
       let session: ClientSession;
 
@@ -139,17 +141,23 @@ describe('outputarea/widget', () => {
 
       it('should execute code on a kernel and send outputs to the model', () => {
         return session.kernel.ready.then(() => {
-          return widget.execute('print("hello")', session).then(reply => {
-            expect(reply.content.execution_count).to.be.ok();
-            expect(reply.content.status).to.be('ok');
-            expect(model.length).to.be(1);
-          });
+          let future = session.kernel.requestExecute({ code: CODE });
+          widget.future = future;
+          return future.done;
+        }).then(reply => {
+          expect(reply.content.execution_count).to.be.ok();
+          expect(reply.content.status).to.be('ok');
+          expect(model.length).to.be(1);
         });
       });
 
       it('should clear existing outputs', () => {
         widget.model.fromJSON(DEFAULT_OUTPUTS);
-        return widget.execute('print("hello")', session).then(reply => {
+        return session.kernel.ready.then(() => {
+          let future = session.kernel.requestExecute({ code: CODE });
+          widget.future = future;
+          return future.done;
+        }).then(reply => {
           expect(reply.content.execution_count).to.be.ok();
           expect(model.length).to.be(1);
         });
@@ -186,6 +194,43 @@ describe('outputarea/widget', () => {
 
     });
 
+    describe('.execute()', () => {
+
+      let session: ClientSession;
+
+      beforeEach(() => {
+        return createClientSession().then(s => {
+          session = s;
+          return session.initialize();
+        });
+      });
+
+      afterEach(() => {
+        return session.shutdown().then(() => {
+          session.dispose();
+        });
+      });
+
+      it('should execute code on a kernel and send outputs to the model', () => {
+        return session.kernel.ready.then(() => {
+          return OutputArea.execute(widget, CODE, session).then(reply => {
+            expect(reply.content.execution_count).to.be.ok();
+            expect(reply.content.status).to.be('ok');
+            expect(model.length).to.be(1);
+          });
+        });
+      });
+
+      it('should clear existing outputs', () => {
+        widget.model.fromJSON(DEFAULT_OUTPUTS);
+        return OutputArea.execute(widget, CODE, session).then(reply => {
+          expect(reply.content.execution_count).to.be.ok();
+          expect(model.length).to.be(1);
+        });
+      });
+
+    });
+
     describe('.ContentFactory', () => {
 
       describe('#createOutputPrompt()', () => {
@@ -202,10 +247,11 @@ describe('outputarea/widget', () => {
         it('should create a stdin widget', () => {
           return Kernel.startNew().then(kernel => {
             let factory = new OutputArea.ContentFactory();
+            let future = kernel.requestExecute({ code: CODE });
             let options = {
               prompt: 'hello',
               password: false,
-              kernel
+              future
             };
             expect(factory.createStdin(options)).to.be.a(Widget);
             return kernel.shutdown().then(() => { kernel.dispose(); });