Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
debonte committed Apr 5, 2023
1 parent 9b4bfd2 commit ff93cb0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/standalone/intellisense/notebookPythonPathService.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,11 @@ export class NotebookPythonPathService implements IExtensionSingleActivationServ
}

private _getNotebookUriForTextDocumentUri(textDocumentUri: Uri): Uri | undefined {
if (textDocumentUri.scheme !== 'vscode-interactive-input') {
const notebookUri = getNotebookUriFromInputBoxUri(textDocumentUri);
if (!notebookUri) {
return undefined;
}

const inputBoxPrefix = path.sep + 'InteractiveInput-';
const notebookPath = `${textDocumentUri.fsPath.replace(inputBoxPrefix, 'Interactive-')}.interactive`;
const notebookUri = textDocumentUri.with({ scheme: 'vscode-interactive', path: notebookPath });
let result: string | undefined = undefined;
window.tabGroups.all.find((group) => {
group.tabs.find((tab) => {
Expand All @@ -145,3 +143,13 @@ export class NotebookPythonPathService implements IExtensionSingleActivationServ
return result;
}
}

export function getNotebookUriFromInputBoxUri(textDocumentUri: Uri): Uri | undefined {
if (textDocumentUri.scheme !== 'vscode-interactive-input') {
return undefined;
}

const inputBoxPrefix = path.sep + 'InteractiveInput-';
const notebookPath = `${textDocumentUri.fsPath.replace(inputBoxPrefix, 'Interactive-')}.interactive`;
return textDocumentUri.with({ scheme: 'vscode-interactive', path: notebookPath });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { assert } from 'chai';
import { getNotebookUriFromInputBoxUri } from '../../../../standalone/intellisense/notebookPythonPathService.node';
import { Uri } from 'vscode';

suite(`DataScience - VSCode Intellisense Notebook - PythonPath service @lsp`, function () {
test('Not an input box', async () => {
const notebookUri = getNotebookUriFromInputBoxUri(Uri.file('/foo/bar.py'));
assert.notOk(notebookUri);
});
test('Input box', async () => {
const notebookUri = getNotebookUriFromInputBoxUri(Uri.parse('vscode-interactive-input:/InteractiveInput-3'));
assert.ok(notebookUri);
assert.strictEqual(
notebookUri!.toString(),
Uri.from({ scheme: 'vscode-interactive', path: 'Interactive-3.interactive' }).toString()
);
});
});

0 comments on commit ff93cb0

Please sign in to comment.