Browse Source

wip allow raises-exception

Steven Silvester 6 years ago
parent
commit
4dfe84106f
2 changed files with 34 additions and 1 deletions
  1. 9 1
      packages/outputarea/src/widget.ts
  2. 25 0
      tests/test-outputarea/src/widget.spec.ts

+ 9 - 1
packages/outputarea/src/widget.ts

@@ -535,9 +535,17 @@ export namespace OutputArea {
     metadata?: JSONObject
   ): Promise<KernelMessage.IExecuteReplyMsg> {
     // Override the default for `stop_on_error`.
+    let stopOnError = true;
+    if (
+      metadata &&
+      metadata.tags &&
+      (metadata.tags as string[]).indexOf('raises-exception') !== -1
+    ) {
+      stopOnError = false;
+    }
     let content: KernelMessage.IExecuteRequest = {
       code,
-      stop_on_error: true
+      stop_on_error: stopOnError
     };
 
     if (!session.kernel) {

+ 25 - 0
tests/test-outputarea/src/widget.spec.ts

@@ -257,6 +257,31 @@ describe('outputarea/widget', () => {
         expect(outputs[2].data).to.deep.equal({ 'text/plain': '4' });
         await ipySession.shutdown();
       });
+
+      it('should raise an error', async () => {
+        const widget1 = new LogOutputArea({ rendermime, model });
+        const reply = await OutputArea.execute('a++1', widget, session);
+        const reply2 = await OutputArea.execute('a=1', widget1, session);
+        expect(reply.content.status).to.equal('hi');
+        expect(reply2.content.status).to.equal('hi');
+        expect(model.length).to.equal(1);
+        widget1.dispose();
+      });
+
+      it('should allow an error given "raises-exception" metadata tag', async () => {
+        const widget1 = new LogOutputArea({ rendermime, model });
+        const metadata = { tags: ['raises-exception'] };
+        const reply = await OutputArea.execute(
+          'a++1',
+          widget,
+          session,
+          metadata
+        );
+        const reply2 = await OutputArea.execute('a=1', widget1, session);
+        expect(reply.content.execution_count).to.equal('hi');
+        expect(reply2.content.execution_count).to.equal('hi');
+        widget1.dispose();
+      });
     });
 
     describe('.ContentFactory', () => {