Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("handles tooltip", done => {
const sent = new Subject();
const received = new Subject();
const mockSocket = Subject.create(sent, received);
const channels = mockSocket;
const cm = {
getCursor: () => ({ line: 0 }),
getValue: () => "map",
indexFromPos: () => 3,
posFromIndex: x => ({ ch: x, line: 0 })
};
const message = createMessage("inspect_request");
const observable = tooltip.tooltipObservable(channels, cm, message);
// Craft the response to their message
const response = createMessage("inspect_reply");
response.content = {
data: [
"[0;31mInit signature:[0m [0mmap[0m[0;34m([0m[0mself[0m[0;34m,[0m [0;34m/[0m[0;34m,[0m [0;34m*[0m[0margs[0m[0;34m,[0m [0;34m**[0m[0mkwargs[0m[0;34m)[0m[0;34m[0m[0m↵[0;31mDocstring:[0m ↵map(func, *iterables) --> map object↵↵Make an iterator that computes the function using arguments from↵each of the iterables. Stops when the shortest iterable is exhausted.↵[0;31mType:[0m type↵"
],
cursor_pos: 3,
detail_level: 0
}; // Likely hokey values
response.parent_header = Object.assign({}, message.header);
// Listen on the Observable
observable.subscribe(
msg => {
const received = new Subject();
const mockSocket = Subject.create(sent, received);
const channels: Channels = mockSocket;
const cm: Doc = ({
getCursor: () => ({ line: 2 }),
getValue: () => "\n\nimport thi",
indexFromPos: () => 12,
posFromIndex: x => ({ ch: x, line: 3 })
} as unknown) as Doc;
const message = createMessage("complete_request");
const observable = complete.codeCompleteObservable(channels, cm, message);
// Craft the response to their message
const response = createMessage("complete_reply");
response.content = {
matches: ["import this"],
cursor_start: 9,
cursor_end: 10
}; // Likely hokey values
response.parent_header = Object.assign({}, message.header);
// Listen on the Observable
observable.subscribe(
msg => {
expect(msg.from).toEqual({ line: 3, ch: 9 });
expect(msg.list[0].text).toEqual("import this");
expect(msg.to).toEqual({ ch: 10, line: 3 });
},
err => {
throw err;
app: {
notificationSystem: { addNotification: jest.fn() }
}
}
};
const action$ = ActionsObservable.of(
actions.sendExecuteRequest({
id: "id",
message: "test",
contentRef: "fakeContentRef"
})
);
const observable = createExecuteCellStream(
action$,
state$.value,
createMessage("execute_request"),
"id",
"fakeContentRef"
);
observable.pipe(toArray()).subscribe(
actions => {
const errors = actions.map(({ payload: { error } }) =>
error.toString()
);
expect(errors).toEqual(["Error: Kernel not connected!"]);
done();
},
err => done.fail(err)
);
});
test("doesnt complete but does push until abort action", done => {
sent.subscribe((msg: JupyterMessage) => {
expect(msg.header.msg_type).toEqual("kernel_info_request");
const response = createMessage("kernel_info_reply" as MessageType);
response.parent_header = msg.header;
response.content = {
status: "ok",
protocol_version: "5.1",
implementation: "ipython",
implementation_version: "6.2.1",
language_info: {
name: "python",
version: "3.6.5",
mimetype: "text/x-python",
codemirror_mode: { name: "ipython", version: 3 },
pygments_lexer: "ipython3",
nbconvert_exporter: "python",
file_extension: ".py"
},
banner:
export const tooltipRequest = (code: string, cursorPos: number) =>
createMessage("inspect_request", {
content: {
code,
cursor_pos: cursorPos,
detail_level: 0
}
});
export function createCommOpenMessage(
comm_id: string,
target_name: string,
data: any = {},
target_module: string
) {
const msg = createMessage("comm_open", {
content: { comm_id, target_name, data }
});
if (target_module) {
msg.content.target_module = target_module;
}
return msg;
}
export function createCommCloseMessage(
parent_header: any,
comm_id: string,
data: any = {}
) {
return createMessage("comm_close", {
content: { comm_id, data },
parent_header
});
}
export const completionRequest = (code: string, cursorPos: number) =>
createMessage("complete_request", {
content: {
code,
cursor_pos: cursorPos
}
});
export function acquireKernelInfo(
channels: Channels,
kernelRef: KernelRef,
contentRef: ContentRef
) {
const message = createMessage("kernel_info_request");
const obs = channels.pipe(
childOf(message),
ofMessageType("kernel_info_reply"),
first(),
mergeMap(msg => {
const c = msg.content;
const l = c.language_info;
const info: KernelInfo = {
protocolVersion: c.protocol_version,
implementation: c.implementation,
implementationVersion: c.implementation_version,
banner: c.banner,
helpLinks: c.help_links,
languageName: l.name,
export function acquireKernelInfo(
channels: Channels,
kernelRef: KernelRef,
contentRef: ContentRef,
state: AppState
) {
const message = createMessage("kernel_info_request");
const obs = channels.pipe(
childOf(message),
ofMessageType("kernel_info_reply"),
first(),
mergeMap(msg => {
const c = msg.content;
const l = c.language_info;
const info: KernelInfo = {
protocolVersion: c.protocol_version,
implementation: c.implementation,
implementationVersion: c.implementation_version,
banner: c.banner,
helpLinks: c.help_links,
languageName: l.name,