當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jupyter-js-services.IKernel類代碼示例

本文整理匯總了TypeScript中jupyter-js-services.IKernel的典型用法代碼示例。如果您正苦於以下問題:TypeScript IKernel類的具體用法?TypeScript IKernel怎麽用?TypeScript IKernel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IKernel類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: updateKernelNameItem

/**
 * Update the text of the kernel name item.
 */
function updateKernelNameItem(widget: Widget, kernel: IKernel): void {
  widget.node.textContent = 'No Kernel!';
  if (!kernel) {
    return;
  }
  if (kernel.spec) {
    widget.node.textContent = kernel.spec.display_name;
  } else {
    kernel.getKernelSpec().then(spec => {
      widget.node.textContent = kernel.spec.display_name;
    });
  }
}
開發者ID:matt-bowers,項目名稱:jupyterlab,代碼行數:16,代碼來源:kernel.ts

示例2: describe

    describe('#execute()', () => {

      let kernel: IKernel;

      beforeEach((done) => {
        Kernel.startNew().then(k => {
          kernel = k;
          return kernel.kernelInfo();
        }).then(() => {
          done();
        }).catch(done);
      });

      it('should execute code on a kernel and send outputs to the model', (done) => {
        let model = new OutputAreaModel();
        expect(model.length).to.be(0);
        model.execute('print("hello")', kernel).then(reply => {
          expect(reply.content.execution_count).to.be(1);
          expect(reply.content.status).to.be('ok');
          expect(model.length).to.be(1);
          kernel.shutdown();
          done();
        }).catch(done);
      });

      it('should clear existing outputs', (done) => {
        let model = new OutputAreaModel();
        for (let output of DEFAULT_OUTPUTS) {
          model.add(output);
        }
        return model.execute('print("hello")', kernel).then(reply => {
          expect(reply.content.execution_count).to.be(1);
          expect(model.length).to.be(1);
          kernel.shutdown();
          done();
        }).catch(done);
      });

    });
開發者ID:aggFTW,項目名稱:jupyterlab,代碼行數:39,代碼來源:model.spec.ts

示例3: describe

describe('console/history', () => {

  let kernel: IKernel;

  beforeEach((done) => {
    kernelPromise.then(k => {
      kernel = k;
      done();
    });
  });

  after(() => {
    kernel.shutdown();
  });

  describe('ConsoleHistory', () => {

    describe('#constructor()', () => {

      it('should create a new console history object', () => {
        let history = new ConsoleHistory();
        expect(history).to.be.a(ConsoleHistory);
      });

      it('should accept an options argument', () => {
        let history = new ConsoleHistory({ kernel });
        expect(history).to.be.a(ConsoleHistory);
      });

    });

    describe('#isDisposed', () => {

      it('should get whether the object is disposed', () => {
        let history = new ConsoleHistory();
        expect(history.isDisposed).to.be(false);
        history.dispose();
        expect(history.isDisposed).to.be(true);
      });

    });

    describe('#kernel', () => {

      it('should return the kernel that was passed in', () => {
        let history = new ConsoleHistory({ kernel });
        expect(history.kernel).to.be(kernel);
      });

      it('should be settable', () => {
        let history = new ConsoleHistory();
        expect(history.kernel).to.be(null);
        history.kernel = kernel;
        expect(history.kernel).to.be(kernel);
        history.kernel = null;
        expect(history.kernel).to.be(null);
      });

      it('should be safe to set multiple times', () => {
        let history = new ConsoleHistory();
        history.kernel = kernel;
        history.kernel = kernel;
        expect(history.kernel).to.be(kernel);
      });

    });

    describe('#dispose()', () => {

      it('should dispose the history object', () => {
        let history = new ConsoleHistory();
        expect(history.isDisposed).to.be(false);
        history.dispose();
        expect(history.isDisposed).to.be(true);
      });

      it('should be safe to dispose multiple times', () => {
        let history = new ConsoleHistory();
        expect(history.isDisposed).to.be(false);
        history.dispose();
        history.dispose();
        expect(history.isDisposed).to.be(true);
      });

    });

    describe('#back()', () => {

      it('should return void promise if no history exists', (done) => {
        let history = new ConsoleHistory();
        history.back('').then(result => {
          expect(result).to.be(void 0);
          done();
        });
      });

      it('should return previous items if they exist', (done) => {
        let history = new TestHistory({ kernel });
        history.onHistory(mockHistory);
        history.back('').then(result => {
//.........這裏部分代碼省略.........
開發者ID:aggFTW,項目名稱:jupyterlab,代碼行數:101,代碼來源:history.spec.ts

示例4: describe

  describe('NotebookActions', () => {

    let widget: Notebook;
    let kernel: IKernel;

    beforeEach(() => {
      widget = new Notebook({ rendermime: defaultRenderMime() });
      let model = new NotebookModel();
      model.fromJSON(DEFAULT_CONTENT);
      widget.model = model;

      kernel = new MockKernel({ name: 'python' });
      widget.activeCellIndex = 0;
    });

    afterEach(() => {
      widget.dispose();
      kernel.dispose();
      clipboard.clear();
    });

    describe('#splitCell()', () => {

      it('should split the active cell into two cells', () => {
        let cell = widget.activeCell;
        let source = 'thisisasamplestringwithnospaces';
        cell.model.source = source;
        let index = widget.activeCellIndex;
        cell.editor.setCursorPosition(10);
        NotebookActions.splitCell(widget);
        let cells = widget.model.cells;
        let newSource = cells.get(index).source + cells.get(index + 1).source;
        expect(newSource).to.be(source);
      });

      it('should remove leading white space in the second cell', () => {
        let cell = widget.activeCell;
        let source = 'this\n\n   is a test';
        cell.model.source = source;
        cell.editor.setCursorPosition(4);
        NotebookActions.splitCell(widget);
        expect(widget.activeCell.model.source).to.be('is a test');
      });

      it('should clear the existing selection', () => {
        for (let i = 0; i < widget.childCount(); i++) {
          widget.select(widget.childAt(i));
        }
        NotebookActions.splitCell(widget);
        for (let i = 0; i < widget.childCount(); i++) {
          if (i === widget.activeCellIndex) {
            continue;
          }
          expect(widget.isSelected(widget.childAt(i))).to.be(false);
        }
      });

      it('should activate the second cell', () => {
        NotebookActions.splitCell(widget);
        expect(widget.activeCellIndex).to.be(1);
      });

      it('should preserve the types of each cell', () => {
        NotebookActions.changeCellType(widget, 'markdown');
        NotebookActions.splitCell(widget);
        expect(widget.activeCell).to.be.a(MarkdownCellWidget);
        let prev = widget.childAt(0);
        expect(prev).to.be.a(MarkdownCellWidget);
      });

      it('should create two empty cells if there is no content', () => {
        widget.activeCell.model.source = '';
        NotebookActions.splitCell(widget);
        expect(widget.activeCell.model.source).to.be('');
        let prev = widget.childAt(0);
        expect(prev.model.source).to.be('');
      });

      it('should be a no-op if there is no model', () => {
        widget.model = null;
        NotebookActions.splitCell(widget);
        expect(widget.activeCell).to.be(void 0);
      });

      it('should preserve the widget mode', () => {
        NotebookActions.splitCell(widget);
        expect(widget.mode).to.be('command');
        widget.mode = 'edit';
        NotebookActions.splitCell(widget);
        expect(widget.mode).to.be('edit');
      });

      it('should be undo-able', () => {
        let source = widget.activeCell.model.source;
        let count = widget.childCount();
        NotebookActions.splitCell(widget);
        NotebookActions.undo(widget);
        expect(widget.childCount()).to.be(count);
        let cell = widget.childAt(0);
        expect(cell.model.source).to.be(source);
//.........這裏部分代碼省略.........
開發者ID:akshaydixi,項目名稱:jupyterlab,代碼行數:101,代碼來源:actions.spec.ts

示例5: expect

 model.execute('print("hello")', kernel).then(reply => {
   expect(reply.content.execution_count).to.be(1);
   expect(reply.content.status).to.be('ok');
   expect(model.length).to.be(1);
   kernel.shutdown();
   done();
 }).catch(done);
開發者ID:aggFTW,項目名稱:jupyterlab,代碼行數:7,代碼來源:model.spec.ts

示例6:

 }).then(result => {
   if (result.text === 'OK') {
     return kernel.restart().then(() => { return true; });
   } else {
     return false;
   }
 });
開發者ID:ChinaQuants,項目名稱:jupyterlab,代碼行數:7,代碼來源:kernelactions.ts

示例7: after

 after(() => {
   kernel.shutdown();
 });
開發者ID:aggFTW,項目名稱:jupyterlab,代碼行數:3,代碼來源:history.spec.ts

示例8: afterEach

 afterEach(() => {
   widget.dispose();
   kernel.dispose();
   clipboard.clear();
 });
開發者ID:akshaydixi,項目名稱:jupyterlab,代碼行數:5,代碼來源:actions.spec.ts

示例9:

 Kernel.startNew().then(k => {
   kernel = k;
   return kernel.kernelInfo();
 }).then(() => {
開發者ID:aggFTW,項目名稱:jupyterlab,代碼行數:4,代碼來源:model.spec.ts


注:本文中的jupyter-js-services.IKernel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。