Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Raises-exception #6424

Merged
merged 3 commits into from May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/outputarea/src/widget.ts
Expand Up @@ -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
vidartf marked this conversation as resolved.
Show resolved Hide resolved
) {
stopOnError = false;
}
let content: KernelMessage.IExecuteRequest = {
code,
stop_on_error: true
stop_on_error: stopOnError
};

if (!session.kernel) {
Expand Down
43 changes: 43 additions & 0 deletions tests/test-outputarea/src/widget.spec.ts
Expand Up @@ -257,6 +257,49 @@ describe('outputarea/widget', () => {
expect(outputs[2].data).to.deep.equal({ 'text/plain': '4' });
await ipySession.shutdown();
});

it('should stop on an error', async () => {
let ipySession: ClientSession;
ipySession = await createClientSession({
kernelPreference: { name: 'ipython' }
});
await ipySession.initialize();
await ipySession.kernel.ready;
const widget1 = new LogOutputArea({ rendermime, model });
const future1 = OutputArea.execute('a++1', widget, ipySession);
const future2 = OutputArea.execute('a=1', widget1, ipySession);
const reply = await future1;
const reply2 = await future2;
expect(reply.content.status).to.equal('error');
expect(reply2.content.status).to.equal('aborted');
expect(model.length).to.equal(1);
widget1.dispose();
await ipySession.shutdown();
});

it('should allow an error given "raises-exception" metadata tag', async () => {
let ipySession: ClientSession;
ipySession = await createClientSession({
kernelPreference: { name: 'ipython' }
});
await ipySession.initialize();
await ipySession.kernel.ready;
const widget1 = new LogOutputArea({ rendermime, model });
const metadata = { tags: ['raises-exception'] };
const future1 = OutputArea.execute(
'a++1',
widget,
ipySession,
metadata
);
const future2 = OutputArea.execute('a=1', widget1, ipySession);
const reply = await future1;
const reply2 = await future2;
expect(reply.content.status).to.equal('error');
expect(reply2.content.status).to.equal('ok');
widget1.dispose();
await ipySession.shutdown();
});
});

describe('.ContentFactory', () => {
Expand Down