How to use the @jupyterlab/cells.CodeCell.execute function in @jupyterlab/cells

To help you get started, we’ve selected a few @jupyterlab/cells examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab-data-explorer / tests / test-cells / src / widget.spec.ts View on Github external
it('should set the cell prompt properly while executing', async () => {
        const widget = new CodeCell({ model, rendermime, contentFactory });
        widget.initializeState();
        widget.model.value.text = 'foo';
        const future1 = CodeCell.execute(widget, session);
        expect(widget.promptNode.textContent).toEqual('[*]:');
        const future2 = CodeCell.execute(widget, session);
        expect(widget.promptNode.textContent).toEqual('[*]:');
        await expect(future1).rejects.toThrow('Canceled');
        expect(widget.promptNode.textContent).toEqual('[*]:');
        let msg = await future2;
        expect(msg).not.toBeUndefined;

        // The `if` is a Typescript type guard so that msg.content works below.
        if (msg) {
          expect(widget.promptNode.textContent).toEqual(
            `[${msg.content.execution_count}]:`
          );
        }
      });
    });
github jupyterlab / jupyterlab / tests / test-cells / src / widget.spec.ts View on Github external
it('should set the cell prompt properly while executing', async () => {
        const widget = new CodeCell({ model, rendermime, contentFactory });
        widget.initializeState();
        widget.model.value.text = 'foo';
        const future1 = CodeCell.execute(widget, session);
        expect(widget.promptNode.textContent).toEqual('[*]:');
        const future2 = CodeCell.execute(widget, session);
        expect(widget.promptNode.textContent).toEqual('[*]:');
        await expect(future1).rejects.toThrow('Canceled');
        expect(widget.promptNode.textContent).toEqual('[*]:');
        let msg = await future2;
        expect(msg).not.toBeUndefined;

        // The `if` is a Typescript type guard so that msg.content works below.
        if (msg) {
          expect(widget.promptNode.textContent).toEqual(
            `[${msg.content.execution_count}]:`
          );
        }
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-cells / src / widget.spec.ts View on Github external
it('should fulfill a promise if there is no code to execute', async () => {
        const widget = new CodeCell({ model, rendermime, contentFactory });
        widget.initializeState();
        try {
          await CodeCell.execute(widget, session);
        } catch (error) {
          throw error;
        }
      });
github jupyterlab / jupyterlab / packages / console / src / widget.ts View on Github external
cell.setPrompt('');
          }
        });
      }
      cell.model.contentChanged.disconnect(this.update, this);
      this.update();
      this._executed.emit(new Date());
    };
    let onFailure = () => {
      if (this.isDisposed) {
        return;
      }
      cell.model.contentChanged.disconnect(this.update, this);
      this.update();
    };
    return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
  }
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / notebook / src / actions.tsx View on Github external
function runCell(
    notebook: Notebook,
    cell: Cell,
    session?: IClientSession
  ): Promise {
    switch (cell.model.type) {
      case 'markdown':
        (cell as MarkdownCell).rendered = true;
        cell.inputHidden = false;
        executed.emit({ notebook, cell });
        break;
      case 'code':
        if (session) {
          return CodeCell.execute(cell as CodeCell, session, {
            deletedCells: notebook.model.deletedCells
          })
            .then(reply => {
              notebook.model.deletedCells.splice(
                0,
                notebook.model.deletedCells.length
              );
              if (cell.isDisposed) {
                return false;
              }

              if (!reply) {
                return true;
              }

              if (reply.content.status === 'ok') {
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / console / src / widget.ts View on Github external
cell.setPrompt('');
          }
        });
      }
      cell.model.contentChanged.disconnect(this.update, this);
      this.update();
      this._executed.emit(new Date());
    };
    let onFailure = () => {
      if (this.isDisposed) {
        return;
      }
      cell.model.contentChanged.disconnect(this.update, this);
      this.update();
    };
    return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
  }
github jupyterlab / jupyterlab / packages / console / src / widget.ts View on Github external
cell.setPrompt('');
          }
        });
      }
      listener.dispose();
      this.update();
      this._executed.emit(new Date());
    };
    let onFailure = () => {
      if (this.isDisposed) {
        return;
      }
      listener.dispose();
      this.update();
    };
    return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
  }