forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputmodel.spec.ts
118 lines (85 loc) · 2.79 KB
/
outputmodel.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import expect = require('expect.js');
import {
nbformat
} from '@jupyterlab/coreutils';
import {
OutputModel
} from '@jupyterlab/rendermime';
import {
DEFAULT_OUTPUTS
} from '../../utils';
const DEFAULT_EXECUTE: nbformat.IOutput = {
output_type: 'execute_result',
execution_count: 1,
data: { 'text/plain': 'foo' },
metadata: {
'foo': 1,
'bar': 'baz'
}
};
const DEFAULT_STREAM: nbformat.IOutput = {
name: 'stderr',
output_type: 'stream',
text: [
'output to stderr\n'
]
};
describe('rendermime/outputmodel', () => {
describe('OutputModel', () => {
describe('#constructor()', () => {
it('should create a new output model', () => {
let value = DEFAULT_EXECUTE;
let model = new OutputModel({ value });
expect(model).to.be.an(OutputModel);
model = new OutputModel({ value, trusted: true });
expect(model).to.be.an(OutputModel);
});
});
describe('#type', () => {
it('should be the output type', () => {
let model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.type).to.be(DEFAULT_EXECUTE.output_type);
model = new OutputModel({ value: DEFAULT_STREAM });
expect(model.type).to.be(DEFAULT_STREAM.output_type);
});
});
describe('#executionCount', () => {
it('should be the execution count of an execution result', () => {
let model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.executionCount).to.be(1);
});
it('should be null for non-execution results', () => {
let model = new OutputModel({ value: DEFAULT_STREAM });
expect(model.executionCount).to.be(null);
});
});
describe('#toJSON()', () => {
it('should yield the raw value', () => {
let model = new OutputModel({ value: DEFAULT_EXECUTE });
expect(model.toJSON()).to.eql(DEFAULT_EXECUTE);
});
});
describe('.getData()', () => {
it('should handle all bundle types', () => {
for (let i = 0; i < DEFAULT_OUTPUTS.length; i++) {
let output = DEFAULT_OUTPUTS[i];
let bundle = OutputModel.getData(output);
expect(Object.keys(bundle).length).to.not.be(0);
}
});
});
describe('.getMetadata()', () => {
it('should get the metadata from the bundle', () => {
let metadata = OutputModel.getMetadata(DEFAULT_EXECUTE);
expect(metadata['foo']).to.be(1);
expect(metadata['bar']).to.be('baz');
});
it('should handle output with no metadata field', () => {
let metadata = OutputModel.getMetadata(DEFAULT_STREAM);
expect(Object.keys(metadata).length).to.be(0);
});
});
});
});