Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should create a new output model', () => {
const value = DEFAULT_EXECUTE;
let model = new OutputModel({ value });
expect(model).to.be.an.instanceof(OutputModel);
model = new OutputModel({ value, trusted: true });
expect(model).to.be.an.instanceof(OutputModel);
});
});
it('should yield the raw value', () => {
const model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.toJSON()).to.deep.equal(DEFAULT_EXECUTE);
});
});
it('should be the output type', () => {
let model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.type).to.equal(DEFAULT_EXECUTE.output_type);
model = new OutputModel({ value: DEFAULT_STREAM });
expect(model.type).to.equal(DEFAULT_STREAM.output_type);
});
});
it('should be the output type', () => {
let model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.type).to.equal(DEFAULT_EXECUTE.output_type);
model = new OutputModel({ value: DEFAULT_STREAM });
expect(model.type).to.equal(DEFAULT_STREAM.output_type);
});
});
it('should be the execution count of an execution result', () => {
const model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.executionCount).to.equal(1);
});
static isTrustSignificant(model: OutputDiffModel, rendermime: IRenderMimeRegistry): boolean {
if (model.trusted) {
return false;
}
let toTest: nbformat.IOutput[] = [];
if (model.base) {
toTest.push(model.base);
}
if (model.remote && model.remote !== model.base) {
toTest.push(model.remote);
}
for (let o of toTest) {
let untrustedModel = new OutputModel({value: o, trusted: false});
let modelMimeTypes = Object.keys(untrustedModel.data);
let rendererMimeTypes = toArray(rendermime.mimeTypes);
let candidates = intersection(modelMimeTypes, rendererMimeTypes);
for (let mimeType of candidates) {
let factory = rendermime.getFactory(mimeType);
if (factory && (!factory.safe || sanitizable.indexOf(mimeType) !== -1)) {
return true;
}
}
}
return false;
}
}
createOutputModel(options: IOutputModel.IOptions): IOutputModel {
return new OutputModel(options);
}
}
protected createRenderer(output: nbformat.IOutput, trusted: boolean, mimetype: string): IRenderMime.IRenderer {
let model = new OutputModel({value: output, trusted});
let widget = this.rendermime.createRenderer(mimetype);
widget.renderModel(model);
widget.addClass(RENDERED_OUTPUT_CLASS);
let bundle = OutputModel.getData(output);
if (isBase64(bundle[mimetype] as string)) {
widget.addClass(DATA_IS_BASE64_CLASS);
}
return widget;
}
createOutputModel(options: IOutputModel.IOptions): IOutputModel {
return new OutputModel(options);
}
}