@jupyterlab/testutils 4.0.0-alpha.15 → 4.0.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/mock.js CHANGED
@@ -2,737 +2,20 @@
2
2
  // Copyright (c) Jupyter Development Team.
3
3
  // Distributed under the terms of the Modified BSD License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.DocumentWidgetOpenerMock = exports.createFileContext = exports.MockShellFuture = exports.ServiceManagerMock = exports.KernelSpecManagerMock = exports.SessionManagerMock = exports.ContentsManagerMock = exports.SessionContextMock = exports.SessionConnectionMock = exports.KernelMock = exports.cloneKernel = exports.createSimpleSessionContext = exports.emitIopubMessage = exports.updateKernelStatus = exports.NOTEBOOK_PATHS = exports.KERNEL_MODELS = exports.KERNELSPECS = exports.DEFAULT_NAME = void 0;
6
- const coreutils_1 = require("@jupyterlab/coreutils");
7
- const docregistry_1 = require("@jupyterlab/docregistry");
8
- const services_1 = require("@jupyterlab/services");
9
- const properties_1 = require("@lumino/properties");
10
- const coreutils_2 = require("@lumino/coreutils");
11
- const signaling_1 = require("@lumino/signaling");
12
- // The default kernel name
13
- exports.DEFAULT_NAME = 'python3';
14
- exports.KERNELSPECS = {
15
- [exports.DEFAULT_NAME]: {
16
- argv: [
17
- '/Users/someuser/miniconda3/envs/jupyterlab/bin/python',
18
- '-m',
19
- 'ipykernel_launcher',
20
- '-f',
21
- '{connection_file}'
22
- ],
23
- display_name: 'Python 3',
24
- language: 'python',
25
- metadata: {},
26
- name: exports.DEFAULT_NAME,
27
- resources: {}
28
- },
29
- irkernel: {
30
- argv: [
31
- '/Users/someuser/miniconda3/envs/jupyterlab/bin/python',
32
- '-m',
33
- 'ipykernel_launcher',
34
- '-f',
35
- '{connection_file}'
36
- ],
37
- display_name: 'R',
38
- language: 'r',
39
- metadata: {},
40
- name: 'irkernel',
41
- resources: {}
42
- }
43
- };
44
- exports.KERNEL_MODELS = [
45
- {
46
- name: exports.DEFAULT_NAME,
47
- id: coreutils_2.UUID.uuid4()
48
- },
49
- {
50
- name: 'r',
51
- id: coreutils_2.UUID.uuid4()
52
- },
53
- {
54
- name: exports.DEFAULT_NAME,
55
- id: coreutils_2.UUID.uuid4()
56
- }
57
- ];
58
- // Notebook Paths for certain kernel name
59
- exports.NOTEBOOK_PATHS = {
60
- python3: ['Untitled.ipynb', 'Untitled1.ipynb', 'Untitled2.ipynb'],
61
- r: ['Visualization.ipynb', 'Analysis.ipynb', 'Conclusion.ipynb']
62
- };
63
- /**
64
- * Forceably change the status of a session context.
65
- * An iopub message is emitted for the change.
66
- *
67
- * @param sessionContext The session context of interest.
68
- * @param newStatus The new kernel status.
69
- */
70
- function updateKernelStatus(sessionContext, newStatus) {
71
- const kernel = sessionContext.session.kernel;
72
- kernel.status = newStatus;
73
- sessionContext.statusChanged.emit(newStatus);
74
- const msg = services_1.KernelMessage.createMessage({
75
- session: kernel.clientId,
76
- channel: 'iopub',
77
- msgType: 'status',
78
- content: { execution_state: newStatus }
79
- });
80
- emitIopubMessage(sessionContext, msg);
81
- }
82
- exports.updateKernelStatus = updateKernelStatus;
83
- /**
84
- * Emit an iopub message on a session context.
85
- *
86
- * @param sessionContext The session context
87
- * @param msg Message created with `KernelMessage.createMessage`
88
- */
89
- function emitIopubMessage(context, msg) {
90
- const kernel = context.session.kernel;
91
- const msgId = Private.lastMessageProperty.get(kernel);
92
- msg.parent_header.session = kernel.clientId;
93
- msg.parent_header.msg_id = msgId;
94
- kernel.iopubMessage.emit(msg);
95
- }
96
- exports.emitIopubMessage = emitIopubMessage;
97
- /**
98
- * Create a session context given a partial session model.
99
- *
100
- * @param model The session model to use.
101
- */
102
- function createSimpleSessionContext(model = {}) {
103
- const kernel = new exports.KernelMock({ model: (model === null || model === void 0 ? void 0 : model.kernel) || {} });
104
- const session = new exports.SessionConnectionMock({ model }, kernel);
105
- return new exports.SessionContextMock({}, session);
106
- }
107
- exports.createSimpleSessionContext = createSimpleSessionContext;
108
- /**
109
- * Clone a kernel connection.
110
- */
111
- function cloneKernel(kernel) {
112
- return kernel.clone();
113
- }
114
- exports.cloneKernel = cloneKernel;
115
- /**
116
- * A mock kernel object.
117
- *
118
- * @param model The model of the kernel
119
- */
120
- exports.KernelMock = jest.fn(options => {
121
- const model = { id: 'foo', name: exports.DEFAULT_NAME, ...options.model };
122
- options = {
123
- clientId: coreutils_2.UUID.uuid4(),
124
- username: coreutils_2.UUID.uuid4(),
125
- ...options,
126
- model
127
- };
128
- let executionCount = 0;
129
- const spec = Private.kernelSpecForKernelName(model.name);
130
- const thisObject = {
131
- ...jest.requireActual('@jupyterlab/services'),
132
- ...options,
133
- ...model,
134
- model,
135
- serverSettings: services_1.ServerConnection.makeSettings(options.serverSettings),
136
- status: 'idle',
137
- spec: Promise.resolve(spec),
138
- dispose: jest.fn(),
139
- clone: jest.fn(() => {
140
- const newKernel = Private.cloneKernel(options);
141
- newKernel.iopubMessage.connect((_, args) => {
142
- iopubMessageSignal.emit(args);
143
- });
144
- newKernel.statusChanged.connect((_, args) => {
145
- thisObject.status = args;
146
- statusChangedSignal.emit(args);
147
- });
148
- return newKernel;
149
- }),
150
- info: Promise.resolve(Private.getInfo(model.name)),
151
- shutdown: jest.fn(() => Promise.resolve(void 0)),
152
- requestHistory: jest.fn(() => {
153
- const historyReply = services_1.KernelMessage.createMessage({
154
- channel: 'shell',
155
- msgType: 'history_reply',
156
- session: options.clientId,
157
- username: options.username,
158
- content: {
159
- history: [],
160
- status: 'ok'
161
- }
162
- });
163
- return Promise.resolve(historyReply);
164
- }),
165
- restart: jest.fn(() => Promise.resolve(void 0)),
166
- requestExecute: jest.fn(options => {
167
- const msgId = coreutils_2.UUID.uuid4();
168
- executionCount++;
169
- Private.lastMessageProperty.set(thisObject, msgId);
170
- const msg = services_1.KernelMessage.createMessage({
171
- channel: 'iopub',
172
- msgType: 'execute_input',
173
- session: thisObject.clientId,
174
- username: thisObject.username,
175
- msgId,
176
- content: {
177
- code: options.code,
178
- execution_count: executionCount
179
- }
180
- });
181
- iopubMessageSignal.emit(msg);
182
- const reply = services_1.KernelMessage.createMessage({
183
- channel: 'shell',
184
- msgType: 'execute_reply',
185
- session: thisObject.clientId,
186
- username: thisObject.username,
187
- msgId,
188
- content: {
189
- user_expressions: {},
190
- execution_count: executionCount,
191
- status: 'ok'
192
- }
193
- });
194
- return new exports.MockShellFuture(reply);
195
- })
196
- };
197
- // Add signals.
198
- const iopubMessageSignal = new signaling_1.Signal(thisObject);
199
- const statusChangedSignal = new signaling_1.Signal(thisObject);
200
- const pendingInputSignal = new signaling_1.Signal(thisObject);
201
- thisObject.statusChanged = statusChangedSignal;
202
- thisObject.iopubMessage = iopubMessageSignal;
203
- thisObject.pendingInput = pendingInputSignal;
204
- thisObject.hasPendingInput = false;
205
- return thisObject;
206
- });
207
- /**
208
- * A mock session connection.
209
- *
210
- * @param options Addition session options to use
211
- * @param model A session model to use
212
- */
213
- exports.SessionConnectionMock = jest.fn((options, kernel) => {
214
- var _a, _b;
215
- const name = (kernel === null || kernel === void 0 ? void 0 : kernel.name) || ((_b = (_a = options.model) === null || _a === void 0 ? void 0 : _a.kernel) === null || _b === void 0 ? void 0 : _b.name) || exports.DEFAULT_NAME;
216
- kernel = kernel || new exports.KernelMock({ model: { name } });
217
- const model = {
218
- id: coreutils_2.UUID.uuid4(),
219
- path: 'foo',
220
- type: 'notebook',
221
- name: 'foo',
222
- ...options.model,
223
- kernel: kernel.model
224
- };
225
- const thisObject = {
226
- ...jest.requireActual('@jupyterlab/services'),
227
- ...options,
228
- model,
229
- ...model,
230
- kernel,
231
- serverSettings: services_1.ServerConnection.makeSettings(options.serverSettings),
232
- dispose: jest.fn(),
233
- changeKernel: jest.fn(partialModel => {
234
- return Private.changeKernel(kernel, partialModel);
235
- }),
236
- shutdown: jest.fn(() => Promise.resolve(void 0)),
237
- setPath: jest.fn(path => {
238
- thisObject.path = path;
239
- propertyChangedSignal.emit('path');
240
- return Promise.resolve();
241
- }),
242
- setName: jest.fn(name => {
243
- thisObject.name = name;
244
- propertyChangedSignal.emit('name');
245
- return Promise.resolve();
246
- }),
247
- setType: jest.fn(type => {
248
- thisObject.type = type;
249
- propertyChangedSignal.emit('type');
250
- return Promise.resolve();
251
- })
252
- };
253
- const disposedSignal = new signaling_1.Signal(thisObject);
254
- const propertyChangedSignal = new signaling_1.Signal(thisObject);
255
- const statusChangedSignal = new signaling_1.Signal(thisObject);
256
- const connectionStatusChangedSignal = new signaling_1.Signal(thisObject);
257
- const kernelChangedSignal = new signaling_1.Signal(thisObject);
258
- const iopubMessageSignal = new signaling_1.Signal(thisObject);
259
- const unhandledMessageSignal = new signaling_1.Signal(thisObject);
260
- const pendingInputSignal = new signaling_1.Signal(thisObject);
261
- kernel.iopubMessage.connect((_, args) => {
262
- iopubMessageSignal.emit(args);
263
- }, thisObject);
264
- kernel.statusChanged.connect((_, args) => {
265
- statusChangedSignal.emit(args);
266
- }, thisObject);
267
- kernel.pendingInput.connect((_, args) => {
268
- pendingInputSignal.emit(args);
269
- }, thisObject);
270
- thisObject.disposed = disposedSignal;
271
- thisObject.connectionStatusChanged = connectionStatusChangedSignal;
272
- thisObject.propertyChanged = propertyChangedSignal;
273
- thisObject.statusChanged = statusChangedSignal;
274
- thisObject.kernelChanged = kernelChangedSignal;
275
- thisObject.iopubMessage = iopubMessageSignal;
276
- thisObject.unhandledMessage = unhandledMessageSignal;
277
- thisObject.pendingInput = pendingInputSignal;
278
- return thisObject;
279
- });
280
- /**
281
- * A mock session context.
282
- *
283
- * @param session The session connection object to use
284
- */
285
- exports.SessionContextMock = jest.fn((options, connection) => {
286
- const session = connection ||
287
- new exports.SessionConnectionMock({
288
- model: {
289
- path: options.path || '',
290
- type: options.type || '',
291
- name: options.name || ''
292
- }
293
- }, null);
294
- const thisObject = {
295
- ...jest.requireActual('@jupyterlab/apputils'),
296
- ...options,
297
- path: session.path,
298
- type: session.type,
299
- name: session.name,
300
- session,
301
- dispose: jest.fn(),
302
- initialize: jest.fn(() => Promise.resolve(false)),
303
- ready: Promise.resolve(),
304
- changeKernel: jest.fn(partialModel => {
305
- return Private.changeKernel(session.kernel || Private.RUNNING_KERNELS[0], partialModel);
306
- }),
307
- shutdown: jest.fn(() => Promise.resolve())
308
- };
309
- const disposedSignal = new signaling_1.Signal(thisObject);
310
- const propertyChangedSignal = new signaling_1.Signal(thisObject);
311
- const statusChangedSignal = new signaling_1.Signal(thisObject);
312
- const kernelChangedSignal = new signaling_1.Signal(thisObject);
313
- const iopubMessageSignal = new signaling_1.Signal(thisObject);
314
- session.statusChanged.connect((_, args) => {
315
- statusChangedSignal.emit(args);
316
- }, thisObject);
317
- session.iopubMessage.connect((_, args) => {
318
- iopubMessageSignal.emit(args);
319
- });
320
- session.kernelChanged.connect((_, args) => {
321
- kernelChangedSignal.emit(args);
322
- });
323
- session.pendingInput.connect((_, args) => {
324
- thisObject.pendingInput = args;
325
- });
326
- thisObject.statusChanged = statusChangedSignal;
327
- thisObject.kernelChanged = kernelChangedSignal;
328
- thisObject.iopubMessage = iopubMessageSignal;
329
- thisObject.propertyChanged = propertyChangedSignal;
330
- thisObject.disposed = disposedSignal;
331
- thisObject.session = session;
332
- thisObject.pendingInput = false;
333
- return thisObject;
334
- });
335
- /**
336
- * A mock contents manager.
337
- */
338
- exports.ContentsManagerMock = jest.fn(() => {
339
- const files = new Map();
340
- const dummy = new services_1.ContentsManager();
341
- const checkpoints = new Map();
342
- const checkPointContent = new Map();
343
- const baseModel = Private.createFile({ type: 'directory' });
344
- files.set('', { ...baseModel, path: '', name: '' });
345
- const thisObject = {
346
- ...jest.requireActual('@jupyterlab/services'),
347
- newUntitled: jest.fn(options => {
348
- const model = Private.createFile(options || {});
349
- files.set(model.path, model);
350
- fileChangedSignal.emit({
351
- type: 'new',
352
- oldValue: null,
353
- newValue: model
354
- });
355
- return Promise.resolve(model);
356
- }),
357
- createCheckpoint: jest.fn(path => {
358
- var _a;
359
- const lastModified = new Date().toISOString();
360
- const data = { id: coreutils_2.UUID.uuid4(), last_modified: lastModified };
361
- checkpoints.set(path, data);
362
- checkPointContent.set(path, (_a = files.get(path)) === null || _a === void 0 ? void 0 : _a.content);
363
- return Promise.resolve(data);
364
- }),
365
- listCheckpoints: jest.fn(path => {
366
- const p = checkpoints.get(path);
367
- if (p !== undefined) {
368
- return Promise.resolve([p]);
369
- }
370
- return Promise.resolve([]);
371
- }),
372
- deleteCheckpoint: jest.fn(path => {
373
- if (!checkpoints.has(path)) {
374
- return Private.makeResponseError(404);
375
- }
376
- checkpoints.delete(path);
377
- return Promise.resolve();
378
- }),
379
- restoreCheckpoint: jest.fn(path => {
380
- if (!checkpoints.has(path)) {
381
- return Private.makeResponseError(404);
382
- }
383
- files.get(path).content = checkPointContent.get(path);
384
- return Promise.resolve();
385
- }),
386
- normalize: jest.fn(path => {
387
- return dummy.normalize(path);
388
- }),
389
- localPath: jest.fn(path => {
390
- return dummy.localPath(path);
391
- }),
392
- resolvePath: jest.fn((root, path) => {
393
- return dummy.resolvePath(root, path);
394
- }),
395
- get: jest.fn((path, options) => {
396
- path = Private.fixSlash(path);
397
- if (!files.has(path)) {
398
- return Private.makeResponseError(404);
399
- }
400
- const model = files.get(path);
401
- if (model.type === 'directory') {
402
- if ((options === null || options === void 0 ? void 0 : options.content) !== false) {
403
- const content = [];
404
- files.forEach(fileModel => {
405
- if (
406
- // If file path is under this directory, add it to contents array.
407
- coreutils_1.PathExt.dirname(fileModel.path) == model.path &&
408
- // But the directory should exclude itself from the contents array.
409
- fileModel !== model) {
410
- content.push(fileModel);
411
- }
412
- });
413
- return Promise.resolve({ ...model, content });
414
- }
415
- return Promise.resolve(model);
416
- }
417
- if ((options === null || options === void 0 ? void 0 : options.content) != false) {
418
- return Promise.resolve(model);
419
- }
420
- return Promise.resolve({ ...model, content: '' });
421
- }),
422
- driveName: jest.fn(path => {
423
- return dummy.driveName(path);
424
- }),
425
- rename: jest.fn((oldPath, newPath) => {
426
- oldPath = Private.fixSlash(oldPath);
427
- newPath = Private.fixSlash(newPath);
428
- if (!files.has(oldPath)) {
429
- return Private.makeResponseError(404);
430
- }
431
- const oldValue = files.get(oldPath);
432
- files.delete(oldPath);
433
- const name = coreutils_1.PathExt.basename(newPath);
434
- const newValue = { ...oldValue, name, path: newPath };
435
- files.set(newPath, newValue);
436
- fileChangedSignal.emit({
437
- type: 'rename',
438
- oldValue,
439
- newValue
440
- });
441
- return Promise.resolve(newValue);
442
- }),
443
- delete: jest.fn(path => {
444
- path = Private.fixSlash(path);
445
- if (!files.has(path)) {
446
- return Private.makeResponseError(404);
447
- }
448
- const oldValue = files.get(path);
449
- files.delete(path);
450
- fileChangedSignal.emit({
451
- type: 'delete',
452
- oldValue,
453
- newValue: null
454
- });
455
- return Promise.resolve(void 0);
456
- }),
457
- save: jest.fn((path, options) => {
458
- if (path == 'readonly.txt') {
459
- return Private.makeResponseError(403);
460
- }
461
- path = Private.fixSlash(path);
462
- const timeStamp = new Date().toISOString();
463
- if (files.has(path)) {
464
- files.set(path, {
465
- ...files.get(path),
466
- ...options,
467
- last_modified: timeStamp
468
- });
469
- }
470
- else {
471
- files.set(path, {
472
- path,
473
- name: coreutils_1.PathExt.basename(path),
474
- content: '',
475
- writable: true,
476
- created: timeStamp,
477
- type: 'file',
478
- format: 'text',
479
- mimetype: 'plain/text',
480
- ...options,
481
- last_modified: timeStamp
482
- });
483
- }
484
- fileChangedSignal.emit({
485
- type: 'save',
486
- oldValue: null,
487
- newValue: files.get(path)
488
- });
489
- return Promise.resolve(files.get(path));
490
- }),
491
- getDownloadUrl: jest.fn(path => {
492
- return dummy.getDownloadUrl(path);
493
- }),
494
- addDrive: jest.fn(drive => {
495
- dummy.addDrive(drive);
496
- }),
497
- dispose: jest.fn()
498
- };
499
- const fileChangedSignal = new signaling_1.Signal(thisObject);
500
- thisObject.fileChanged = fileChangedSignal;
501
- return thisObject;
502
- });
503
- /**
504
- * A mock sessions manager.
505
- */
506
- exports.SessionManagerMock = jest.fn(() => {
507
- let sessions = [];
508
- const thisObject = {
509
- ...jest.requireActual('@jupyterlab/services'),
510
- ready: Promise.resolve(void 0),
511
- isReady: true,
512
- startNew: jest.fn(options => {
513
- const session = new exports.SessionConnectionMock({ model: options }, null);
514
- sessions.push(session.model);
515
- runningChangedSignal.emit(sessions);
516
- return Promise.resolve(session);
517
- }),
518
- connectTo: jest.fn(options => {
519
- return new exports.SessionConnectionMock(options, null);
520
- }),
521
- stopIfNeeded: jest.fn(path => {
522
- const length = sessions.length;
523
- sessions = sessions.filter(model => model.path !== path);
524
- if (sessions.length !== length) {
525
- runningChangedSignal.emit(sessions);
526
- }
527
- return Promise.resolve(void 0);
528
- }),
529
- refreshRunning: jest.fn(() => Promise.resolve(void 0)),
530
- running: jest.fn(() => sessions[Symbol.iterator]())
531
- };
532
- const runningChangedSignal = new signaling_1.Signal(thisObject);
533
- thisObject.runningChanged = runningChangedSignal;
534
- return thisObject;
535
- });
536
- /**
537
- * A mock kernel specs manager
538
- */
539
- exports.KernelSpecManagerMock = jest.fn(() => {
540
- const thisObject = {
541
- ...jest.requireActual('@jupyterlab/services'),
542
- specs: { default: exports.DEFAULT_NAME, kernelspecs: exports.KERNELSPECS },
543
- isReady: true,
544
- ready: Promise.resolve(void 0),
545
- refreshSpecs: jest.fn(() => Promise.resolve(void 0))
546
- };
547
- return thisObject;
548
- });
549
- /**
550
- * A mock service manager.
551
- */
552
- exports.ServiceManagerMock = jest.fn(() => {
553
- const thisObject = {
554
- ...jest.requireActual('@jupyterlab/services'),
555
- ready: Promise.resolve(void 0),
556
- isReady: true,
557
- contents: new exports.ContentsManagerMock(),
558
- sessions: new exports.SessionManagerMock(),
559
- kernelspecs: new exports.KernelSpecManagerMock(),
560
- dispose: jest.fn()
561
- };
562
- return thisObject;
563
- });
564
- /**
565
- * A mock kernel shell future.
566
- */
567
- exports.MockShellFuture = jest.fn((result) => {
568
- const thisObject = {
569
- ...jest.requireActual('@jupyterlab/services'),
570
- dispose: jest.fn(),
571
- done: Promise.resolve(result)
572
- };
573
- return thisObject;
574
- });
575
- /**
576
- * Create a context for a file.
577
- */
578
- async function createFileContext(startKernel = false, manager) {
579
- const path = coreutils_2.UUID.uuid4() + '.txt';
580
- manager = manager || new exports.ServiceManagerMock();
581
- const factory = new docregistry_1.TextModelFactory();
582
- const context = new docregistry_1.Context({
583
- manager: manager || new exports.ServiceManagerMock(),
584
- factory,
585
- path,
586
- kernelPreference: {
587
- shouldStart: startKernel,
588
- canStart: startKernel,
589
- autoStartDefault: startKernel
590
- }
591
- });
592
- await context.initialize(true);
593
- await context.sessionContext.initialize();
594
- return context;
595
- }
596
- exports.createFileContext = createFileContext;
597
- /**
598
- * A namespace for module private data.
599
- */
600
- var Private;
601
- (function (Private) {
602
- function flattenArray(arr) {
603
- const result = [];
604
- arr.forEach(innerArr => {
605
- innerArr.forEach(elem => {
606
- result.push(elem);
607
- });
608
- });
609
- return result;
610
- }
611
- Private.flattenArray = flattenArray;
612
- function createFile(options) {
613
- options = options || {};
614
- let name = coreutils_2.UUID.uuid4();
615
- switch (options.type) {
616
- case 'directory':
617
- name = `Untitled Folder_${name}`;
618
- break;
619
- case 'notebook':
620
- name = `Untitled_${name}.ipynb`;
621
- break;
622
- default:
623
- name = `untitled_${name}${options.ext || '.txt'}`;
624
- }
625
- const path = coreutils_1.PathExt.join(options.path || '', name);
626
- let content = '';
627
- if (options.type === 'notebook') {
628
- content = JSON.stringify({});
629
- }
630
- const timeStamp = new Date().toISOString();
631
- return {
632
- path,
633
- content,
634
- name,
635
- last_modified: timeStamp,
636
- writable: true,
637
- created: timeStamp,
638
- type: options.type || 'file',
639
- format: 'text',
640
- mimetype: 'plain/text'
641
- };
642
- }
643
- Private.createFile = createFile;
644
- function fixSlash(path) {
645
- if (path.endsWith('/')) {
646
- path = path.slice(0, path.length - 1);
647
- }
648
- return path;
649
- }
650
- Private.fixSlash = fixSlash;
651
- function makeResponseError(status) {
652
- const resp = new Response(void 0, { status });
653
- return Promise.reject(new services_1.ServerConnection.ResponseError(resp));
654
- }
655
- Private.makeResponseError = makeResponseError;
656
- function cloneKernel(options) {
657
- return new exports.KernelMock({ ...options, clientId: coreutils_2.UUID.uuid4() });
658
- }
659
- Private.cloneKernel = cloneKernel;
660
- // Get the kernel spec for kernel name
661
- function kernelSpecForKernelName(name) {
662
- return exports.KERNELSPECS[name];
663
- }
664
- Private.kernelSpecForKernelName = kernelSpecForKernelName;
665
- // Get the kernel info for kernel name
666
- function getInfo(name) {
667
- return {
668
- protocol_version: '1',
669
- implementation: 'foo',
670
- implementation_version: '1',
671
- language_info: {
672
- version: '1',
673
- name
674
- },
675
- banner: 'hello, world!',
676
- help_links: [],
677
- status: 'ok'
678
- };
679
- }
680
- Private.getInfo = getInfo;
681
- function changeKernel(kernel, partialModel) {
682
- if (partialModel.id) {
683
- const kernelIdx = exports.KERNEL_MODELS.findIndex(model => {
684
- return model.id === partialModel.id;
685
- });
686
- if (kernelIdx !== -1) {
687
- kernel.model = Private.RUNNING_KERNELS[kernelIdx].model;
688
- kernel.id = partialModel.id;
689
- return Promise.resolve(Private.RUNNING_KERNELS[kernelIdx]);
690
- }
691
- else {
692
- throw new Error(`Unable to change kernel to one with id: ${partialModel.id}`);
693
- }
694
- }
695
- else if (partialModel.name) {
696
- const kernelIdx = exports.KERNEL_MODELS.findIndex(model => {
697
- return model.name === partialModel.name;
698
- });
699
- if (kernelIdx !== -1) {
700
- kernel.model = Private.RUNNING_KERNELS[kernelIdx].model;
701
- kernel.id = partialModel.id;
702
- return Promise.resolve(Private.RUNNING_KERNELS[kernelIdx]);
703
- }
704
- else {
705
- throw new Error(`Unable to change kernel to one with name: ${partialModel.name}`);
706
- }
707
- }
708
- else {
709
- throw new Error(`Unable to change kernel`);
710
- }
711
- }
712
- Private.changeKernel = changeKernel;
713
- // This list of running kernels simply mirrors the KERNEL_MODELS and KERNELSPECS lists
714
- Private.RUNNING_KERNELS = exports.KERNEL_MODELS.map((model, _) => {
715
- return new exports.KernelMock({ model });
716
- });
717
- Private.lastMessageProperty = new properties_1.AttachedProperty({
718
- name: 'lastMessageId',
719
- create: () => ''
720
- });
721
- })(Private || (Private = {}));
722
- /**
723
- * A mock document widget opener.
724
- */
725
- class DocumentWidgetOpenerMock {
726
- constructor() {
727
- this._opened = new signaling_1.Signal(this);
728
- }
729
- get opened() {
730
- return this._opened;
731
- }
732
- open(widget) {
733
- // no-op, just emit the signal
734
- this._opened.emit(widget);
735
- }
736
- }
737
- exports.DocumentWidgetOpenerMock = DocumentWidgetOpenerMock;
5
+ exports.SessionConnectionMock = exports.NOTEBOOK_PATHS = exports.KERNEL_MODELS = exports.KERNELSPECS = exports.DEFAULT_NAME = exports.ContentsManagerMock = exports.cloneKernel = exports.updateKernelStatus = exports.SessionContextMock = exports.emitIopubMessage = exports.DocumentWidgetOpenerMock = exports.createSimpleSessionContext = exports.createFileContext = void 0;
6
+ var testutils_1 = require("@jupyterlab/docregistry/lib/testutils");
7
+ Object.defineProperty(exports, "createFileContext", { enumerable: true, get: function () { return testutils_1.createFileContext; } });
8
+ Object.defineProperty(exports, "createSimpleSessionContext", { enumerable: true, get: function () { return testutils_1.createSimpleSessionContext; } });
9
+ Object.defineProperty(exports, "DocumentWidgetOpenerMock", { enumerable: true, get: function () { return testutils_1.DocumentWidgetOpenerMock; } });
10
+ Object.defineProperty(exports, "emitIopubMessage", { enumerable: true, get: function () { return testutils_1.emitIopubMessage; } });
11
+ Object.defineProperty(exports, "SessionContextMock", { enumerable: true, get: function () { return testutils_1.SessionContextMock; } });
12
+ Object.defineProperty(exports, "updateKernelStatus", { enumerable: true, get: function () { return testutils_1.updateKernelStatus; } });
13
+ var testutils_2 = require("@jupyterlab/services/lib/testutils");
14
+ Object.defineProperty(exports, "cloneKernel", { enumerable: true, get: function () { return testutils_2.cloneKernel; } });
15
+ Object.defineProperty(exports, "ContentsManagerMock", { enumerable: true, get: function () { return testutils_2.ContentsManagerMock; } });
16
+ Object.defineProperty(exports, "DEFAULT_NAME", { enumerable: true, get: function () { return testutils_2.DEFAULT_NAME; } });
17
+ Object.defineProperty(exports, "KERNELSPECS", { enumerable: true, get: function () { return testutils_2.KERNELSPECS; } });
18
+ Object.defineProperty(exports, "KERNEL_MODELS", { enumerable: true, get: function () { return testutils_2.KERNEL_MODELS; } });
19
+ Object.defineProperty(exports, "NOTEBOOK_PATHS", { enumerable: true, get: function () { return testutils_2.NOTEBOOK_PATHS; } });
20
+ Object.defineProperty(exports, "SessionConnectionMock", { enumerable: true, get: function () { return testutils_2.SessionConnectionMock; } });
738
21
  //# sourceMappingURL=mock.js.map