mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Remove ApiWrapper from notebook extension (#11224)
* Remove ApiWrapper in notebook extension * delete file * Remove copyrights
This commit is contained in:
@@ -11,7 +11,6 @@ import * as fileServices from 'fs';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as loc from '../common/localizedConstants';
|
||||
import { IJupyterBookToc, IJupyterBookSection } from '../contracts/content';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
|
||||
|
||||
const fsPromises = fileServices.promises;
|
||||
@@ -22,7 +21,6 @@ export class BookModel {
|
||||
private _tableOfContentsPath: string;
|
||||
|
||||
private _errorMessage: string;
|
||||
private apiWrapper: ApiWrapper = new ApiWrapper();
|
||||
|
||||
constructor(
|
||||
public readonly bookPath: string,
|
||||
@@ -130,7 +128,7 @@ export class BookModel {
|
||||
this._bookItems.push(book);
|
||||
} catch (e) {
|
||||
this._errorMessage = loc.readBookError(this.bookPath, e instanceof Error ? e.message : e);
|
||||
this.apiWrapper.showErrorMessage(this._errorMessage);
|
||||
vscode.window.showErrorMessage(this._errorMessage);
|
||||
}
|
||||
}
|
||||
return this._bookItems;
|
||||
@@ -216,7 +214,7 @@ export class BookModel {
|
||||
notebooks.push(markdown);
|
||||
} else {
|
||||
this._errorMessage = loc.missingFileError(sections[i].title);
|
||||
this.apiWrapper.showErrorMessage(this._errorMessage);
|
||||
vscode.window.showErrorMessage(this._errorMessage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -15,7 +15,6 @@ import { BookModel } from './bookModel';
|
||||
import { Deferred } from '../common/promise';
|
||||
import { IBookTrustManager, BookTrustManager } from './bookTrustManager';
|
||||
import * as loc from '../common/localizedConstants';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as glob from 'fast-glob';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { debounce } from '../common/utils';
|
||||
@@ -43,14 +42,14 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
public books: BookModel[];
|
||||
public currentBook: BookModel;
|
||||
|
||||
constructor(private _apiWrapper: ApiWrapper, workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext, openAsUntitled: boolean, view: string, public providerId: string) {
|
||||
constructor(workspaceFolders: vscode.WorkspaceFolder[], extensionContext: vscode.ExtensionContext, openAsUntitled: boolean, view: string, public providerId: string) {
|
||||
this._openAsUntitled = openAsUntitled;
|
||||
this._extensionContext = extensionContext;
|
||||
this.books = [];
|
||||
this.initialize(workspaceFolders).catch(e => console.error(e));
|
||||
this.viewId = view;
|
||||
this.prompter = new CodeAdapter();
|
||||
this._bookTrustManager = new BookTrustManager(this.books, _apiWrapper);
|
||||
this._bookTrustManager = new BookTrustManager(this.books);
|
||||
|
||||
this._extensionContext.subscriptions.push(azdata.nb.registerNavigationProvider(this));
|
||||
}
|
||||
@@ -83,7 +82,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
if (bookPathToTrust) {
|
||||
let trustChanged = this._bookTrustManager.setBookAsTrusted(bookPathToTrust);
|
||||
if (trustChanged) {
|
||||
let notebookDocuments = this._apiWrapper.getNotebookDocuments();
|
||||
let notebookDocuments = azdata.nb.notebookDocuments;
|
||||
if (notebookDocuments) {
|
||||
// update trust state of opened items
|
||||
notebookDocuments.forEach(document => {
|
||||
@@ -93,9 +92,9 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
});
|
||||
}
|
||||
this._apiWrapper.showInfoMessage(loc.msgBookTrusted);
|
||||
vscode.window.showInformationMessage(loc.msgBookTrusted);
|
||||
} else {
|
||||
this._apiWrapper.showInfoMessage(loc.msgBookAlreadyTrusted);
|
||||
vscode.window.showInformationMessage(loc.msgBookAlreadyTrusted);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +177,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
if (!this.currentBook) {
|
||||
this.currentBook = book;
|
||||
}
|
||||
this._bookViewer = this._apiWrapper.createTreeView(this.viewId, { showCollapseAll: true, treeDataProvider: this });
|
||||
this._bookViewer = vscode.window.createTreeView(this.viewId, { showCollapseAll: true, treeDataProvider: this });
|
||||
this._bookViewer.onDidChangeVisibility(e => {
|
||||
let openDocument = azdata.nb.activeNotebookEditor;
|
||||
let notebookPath = openDocument?.document.uri;
|
||||
@@ -236,7 +235,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
let notebookPath: string;
|
||||
// If no uri is passed in, try to use the current active notebook editor
|
||||
if (!uri) {
|
||||
let openDocument = this._apiWrapper.getActiveNotebookEditor();
|
||||
let openDocument = azdata.nb.activeNotebookEditor;
|
||||
if (openDocument) {
|
||||
notebookPath = openDocument.document.uri.fsPath;
|
||||
}
|
||||
@@ -514,7 +513,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
type: confirm,
|
||||
message: loc.confirmReplace,
|
||||
default: false
|
||||
}, this._apiWrapper);
|
||||
});
|
||||
}
|
||||
|
||||
getNavigation(uri: vscode.Uri): Thenable<azdata.nb.NavigationResult> {
|
||||
|
||||
@@ -7,7 +7,6 @@ import * as vscode from 'vscode';
|
||||
import * as constants from './../common/constants';
|
||||
import { BookTreeItem } from './bookTreeItem';
|
||||
import { BookModel } from './bookModel';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
|
||||
export interface IBookTrustManager {
|
||||
isNotebookTrustedByDefault(notebookUri: string): boolean;
|
||||
@@ -20,7 +19,7 @@ enum TrustBookOperation {
|
||||
}
|
||||
|
||||
export class BookTrustManager implements IBookTrustManager {
|
||||
constructor(private books: BookModel[], private apiWrapper: ApiWrapper) { }
|
||||
constructor(private books: BookModel[]) { }
|
||||
|
||||
isNotebookTrustedByDefault(notebookUri: string): boolean {
|
||||
let normalizedNotebookUri: string = path.normalize(notebookUri);
|
||||
@@ -38,7 +37,7 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
let bookPathsInConfig: string[] = this.getTrustedBookPathsInConfig();
|
||||
|
||||
if (this.hasWorkspaceFolders()) {
|
||||
let workspaceFolders = this.apiWrapper.getWorkspaceFolders();
|
||||
let workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
|
||||
trustablePaths = bookPathsInConfig
|
||||
.map(trustableBookPath => workspaceFolders
|
||||
@@ -63,21 +62,21 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
}
|
||||
|
||||
getTrustedBookPathsInConfig(): string[] {
|
||||
let config: vscode.WorkspaceConfiguration = this.apiWrapper.getConfiguration(constants.notebookConfigKey);
|
||||
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
let trustedBookDirectories: string[] = config.get(constants.trustedBooksConfigKey);
|
||||
|
||||
return trustedBookDirectories;
|
||||
}
|
||||
|
||||
setTrustedBookPathsInConfig(bookPaths: string[]) {
|
||||
let config: vscode.WorkspaceConfiguration = this.apiWrapper.getConfiguration(constants.notebookConfigKey);
|
||||
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
let storeInWorspace: boolean = this.hasWorkspaceFolders();
|
||||
|
||||
config.update(constants.trustedBooksConfigKey, bookPaths, storeInWorspace ? false : vscode.ConfigurationTarget.Global);
|
||||
}
|
||||
|
||||
hasWorkspaceFolders(): boolean {
|
||||
let workspaceFolders = this.apiWrapper.getWorkspaceFolders();
|
||||
let workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
return workspaceFolders && workspaceFolders.length > 0;
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ export class BookTrustManager implements IBookTrustManager {
|
||||
let bookPathToChange: string = path.join(bookPath, path.sep);
|
||||
|
||||
if (this.hasWorkspaceFolders()) {
|
||||
let workspaceFolders = this.apiWrapper.getWorkspaceFolders();
|
||||
let workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
let matchingWorkspaceFolder: vscode.WorkspaceFolder = workspaceFolders
|
||||
.find(ws => bookPathToChange.startsWith(path.normalize(ws.uri.fsPath)));
|
||||
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
/**
|
||||
* Wrapper class to act as a facade over VSCode and Data APIs and allow us to test / mock callbacks into
|
||||
* this API from our code
|
||||
*/
|
||||
export class ApiWrapper {
|
||||
public getWorkspaceFolders(): vscode.WorkspaceFolder[] {
|
||||
return [].concat(vscode.workspace.workspaceFolders || []);
|
||||
}
|
||||
|
||||
public createOutputChannel(name: string): vscode.OutputChannel {
|
||||
return vscode.window.createOutputChannel(name);
|
||||
}
|
||||
|
||||
public createTerminalWithOptions(options: vscode.TerminalOptions): vscode.Terminal {
|
||||
return vscode.window.createTerminal(options);
|
||||
}
|
||||
|
||||
public getCurrentConnection(): Thenable<azdata.connection.ConnectionProfile> {
|
||||
return azdata.connection.getCurrentConnection();
|
||||
}
|
||||
|
||||
public getWorkspacePathFromUri(uri: vscode.Uri): string | undefined {
|
||||
let workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
|
||||
return workspaceFolder ? workspaceFolder.uri.fsPath : undefined;
|
||||
}
|
||||
|
||||
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
|
||||
return vscode.commands.registerCommand(command, callback, thisArg);
|
||||
}
|
||||
|
||||
public registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
|
||||
return vscode.languages.registerCompletionItemProvider(selector, provider, ...triggerCharacters);
|
||||
}
|
||||
|
||||
public registerTaskHandler(taskId: string, handler: (profile: azdata.IConnectionProfile) => void): void {
|
||||
azdata.tasks.registerTask(taskId, handler);
|
||||
}
|
||||
|
||||
public showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
||||
return vscode.window.showErrorMessage(message, ...items);
|
||||
}
|
||||
|
||||
public showInfoMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
||||
return vscode.window.showInformationMessage(message, ...items);
|
||||
}
|
||||
|
||||
public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined> {
|
||||
return vscode.window.showOpenDialog(options);
|
||||
}
|
||||
|
||||
public startBackgroundOperation(operationInfo: azdata.BackgroundOperationInfo): void {
|
||||
azdata.tasks.startBackgroundOperation(operationInfo);
|
||||
}
|
||||
|
||||
public getNotebookDocuments() {
|
||||
return azdata.nb.notebookDocuments;
|
||||
}
|
||||
|
||||
public getActiveNotebookEditor(): azdata.nb.NotebookEditor {
|
||||
return azdata.nb.activeNotebookEditor;
|
||||
}
|
||||
|
||||
public showNotebookDocument(uri: vscode.Uri, showOptions?: azdata.nb.NotebookShowOptions): Thenable<azdata.nb.NotebookEditor> {
|
||||
return azdata.nb.showNotebookDocument(uri, showOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a extensionName
|
||||
* @param extensionName The string name of the extension to get the configuration for
|
||||
* @param resource The optional URI, as a URI object or a string, to use to get resource-scoped configurations
|
||||
*/
|
||||
public getConfiguration(extensionName?: string, resource?: vscode.Uri | string): vscode.WorkspaceConfiguration {
|
||||
if (typeof resource === 'string') {
|
||||
try {
|
||||
resource = this.parseUri(resource);
|
||||
} catch (e) {
|
||||
resource = undefined;
|
||||
}
|
||||
} else if (!resource) {
|
||||
// Fix to avoid adding lots of errors to debug console. Expects a valid resource or null, not undefined
|
||||
resource = null;
|
||||
}
|
||||
return vscode.workspace.getConfiguration(extensionName, resource as vscode.Uri);
|
||||
}
|
||||
|
||||
public parseUri(uri: string): vscode.Uri {
|
||||
return vscode.Uri.parse(uri);
|
||||
}
|
||||
|
||||
public createTreeView<T>(viewId: string, options: vscode.TreeViewOptions<T>): vscode.TreeView<T> {
|
||||
return vscode.window.createTreeView(viewId, options);
|
||||
}
|
||||
|
||||
public showQuickPick(items: string[] | Thenable<string[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<string | undefined> {
|
||||
return vscode.window.showQuickPick(items, options, token);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { ApiWrapper } from './apiWrapper';
|
||||
import { NotebookUtils } from './notebookUtils';
|
||||
|
||||
/**
|
||||
@@ -14,8 +13,7 @@ export class AppContext {
|
||||
|
||||
public readonly notebookUtils: NotebookUtils;
|
||||
|
||||
constructor(public readonly extensionContext: vscode.ExtensionContext, public readonly apiWrapper: ApiWrapper) {
|
||||
this.apiWrapper = apiWrapper || new ApiWrapper();
|
||||
this.notebookUtils = new NotebookUtils(apiWrapper);
|
||||
constructor(public readonly extensionContext: vscode.ExtensionContext) {
|
||||
this.notebookUtils = new NotebookUtils();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as os from 'os';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { getErrorMessage, isEditorTitleFree } from '../common/utils';
|
||||
import { ApiWrapper } from './apiWrapper';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -18,7 +17,7 @@ const noNotebookVisible = localize('noNotebookVisible', "No notebook editor is a
|
||||
|
||||
export class NotebookUtils {
|
||||
|
||||
constructor(private _apiWrapper: ApiWrapper) { }
|
||||
constructor() { }
|
||||
|
||||
public async newNotebook(connectionProfile?: azdata.IConnectionProfile): Promise<azdata.nb.NotebookEditor> {
|
||||
const title = this.findNextUntitledEditorName();
|
||||
@@ -51,59 +50,59 @@ export class NotebookUtils {
|
||||
let filter: { [key: string]: Array<string> } = {};
|
||||
// TODO support querying valid notebook file types
|
||||
filter[localize('notebookFiles', "Notebooks")] = ['ipynb'];
|
||||
let file = await this._apiWrapper.showOpenDialog({
|
||||
let file = await vscode.window.showOpenDialog({
|
||||
filters: filter
|
||||
});
|
||||
if (file && file.length > 0) {
|
||||
await azdata.nb.showNotebookDocument(file[0]);
|
||||
}
|
||||
} catch (err) {
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async runActiveCell(): Promise<void> {
|
||||
try {
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
if (notebook) {
|
||||
await notebook.runCell();
|
||||
} else {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async clearActiveCellOutput(): Promise<void> {
|
||||
try {
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
if (notebook) {
|
||||
await notebook.clearOutput();
|
||||
} else {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async runAllCells(startCell?: azdata.nb.NotebookCell, endCell?: azdata.nb.NotebookCell): Promise<void> {
|
||||
try {
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
if (notebook) {
|
||||
await notebook.runAllCells(startCell, endCell);
|
||||
} else {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async addCell(cellType: azdata.nb.CellType): Promise<void> {
|
||||
try {
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
if (notebook) {
|
||||
await notebook.edit((editBuilder: azdata.nb.NotebookEditorEdit) => {
|
||||
// TODO should prompt and handle cell placement
|
||||
@@ -116,7 +115,7 @@ export class NotebookUtils {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ export class NotebookUtils {
|
||||
let title = this.findNextUntitledEditorName();
|
||||
let untitledUri = vscode.Uri.parse(`untitled:${title}`);
|
||||
|
||||
let editor = await this._apiWrapper.showNotebookDocument(untitledUri, {
|
||||
let editor = await azdata.nb.showNotebookDocument(untitledUri, {
|
||||
connectionProfile: oeContext ? oeContext.connectionProfile : undefined,
|
||||
providerId: JUPYTER_NOTEBOOK_PROVIDER,
|
||||
preview: false,
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { ConfigurePythonModel, ConfigurePythonWizard } from './configurePythonWizard';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
|
||||
export abstract class BasePage {
|
||||
|
||||
constructor(protected readonly apiWrapper: ApiWrapper,
|
||||
protected readonly instance: ConfigurePythonWizard,
|
||||
constructor(protected readonly instance: ConfigurePythonWizard,
|
||||
protected readonly wizardPage: azdata.window.WizardPage,
|
||||
protected readonly model: ConfigurePythonModel,
|
||||
protected readonly view: azdata.ModelView) {
|
||||
|
||||
@@ -236,7 +236,7 @@ export class ConfigurePathPage extends BasePage {
|
||||
openLabel: this.SelectFileLabel
|
||||
};
|
||||
|
||||
let fileUris: vscode.Uri[] = await this.apiWrapper.showOpenDialog(options);
|
||||
let fileUris: vscode.Uri[] = await vscode.window.showOpenDialog(options);
|
||||
if (fileUris?.length > 0 && fileUris[0]) {
|
||||
let existingValues = <azdata.CategoryValue[]>this.pythonLocationDropdown.values;
|
||||
let filePath = fileUris[0].fsPath;
|
||||
|
||||
@@ -10,7 +10,6 @@ import { promises as fs } from 'fs';
|
||||
import * as utils from '../../common/utils';
|
||||
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { PythonPathLookup, PythonPathInfo } from '../pythonPathLookup';
|
||||
|
||||
@@ -39,7 +38,7 @@ export class ConfigurePythonDialog {
|
||||
private pythonPathsPromise: Promise<PythonPathInfo[]>;
|
||||
private usingCustomPath: boolean;
|
||||
|
||||
constructor(private apiWrapper: ApiWrapper, private jupyterInstallation: JupyterServerInstallation) {
|
||||
constructor(private jupyterInstallation: JupyterServerInstallation) {
|
||||
this.setupComplete = new Deferred<void>();
|
||||
this.pythonPathsPromise = (new PythonPathLookup()).getSuggestions();
|
||||
this.usingCustomPath = false;
|
||||
@@ -108,7 +107,7 @@ export class ConfigurePythonDialog {
|
||||
}
|
||||
});
|
||||
|
||||
let useExistingPython = JupyterServerInstallation.getExistingPythonSetting(this.apiWrapper);
|
||||
let useExistingPython = JupyterServerInstallation.getExistingPythonSetting();
|
||||
this.createInstallRadioButtons(view.modelBuilder, useExistingPython);
|
||||
|
||||
let formModel = view.modelBuilder.formContainer()
|
||||
@@ -271,7 +270,7 @@ export class ConfigurePythonDialog {
|
||||
openLabel: this.SelectFileLabel
|
||||
};
|
||||
|
||||
let fileUris: vscode.Uri[] = await this.apiWrapper.showOpenDialog(options);
|
||||
let fileUris: vscode.Uri[] = await vscode.window.showOpenDialog(options);
|
||||
if (fileUris && fileUris[0]) {
|
||||
let existingValues = <azdata.CategoryValue[]>this.pythonLocationDropdown.values;
|
||||
let filePath = fileUris[0].fsPath;
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as utils from '../../common/utils';
|
||||
import { promises as fs } from 'fs';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { PythonPathInfo, PythonPathLookup } from '../pythonPathLookup';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -37,7 +36,7 @@ export class ConfigurePythonWizard {
|
||||
private _setupComplete: Deferred<void>;
|
||||
private pythonPathsPromise: Promise<PythonPathInfo[]>;
|
||||
|
||||
constructor(private apiWrapper: ApiWrapper, private jupyterInstallation: JupyterServerInstallation) {
|
||||
constructor(private jupyterInstallation: JupyterServerInstallation) {
|
||||
this._setupComplete = new Deferred<void>();
|
||||
this.pythonPathsPromise = (new PythonPathLookup()).getSuggestions();
|
||||
}
|
||||
@@ -55,8 +54,8 @@ export class ConfigurePythonWizard {
|
||||
kernelName: kernelName,
|
||||
pythonPathsPromise: this.pythonPathsPromise,
|
||||
installation: this.jupyterInstallation,
|
||||
pythonLocation: JupyterServerInstallation.getPythonPathSetting(this.apiWrapper),
|
||||
useExistingPython: JupyterServerInstallation.getExistingPythonSetting(this.apiWrapper)
|
||||
pythonLocation: JupyterServerInstallation.getPythonPathSetting(),
|
||||
useExistingPython: JupyterServerInstallation.getExistingPythonSetting()
|
||||
};
|
||||
|
||||
let pages: Map<number, BasePage> = new Map<number, BasePage>();
|
||||
@@ -72,14 +71,14 @@ export class ConfigurePythonWizard {
|
||||
let page1 = azdata.window.createWizardPage(localize('configurePython.page1Name', "Install Dependencies"));
|
||||
|
||||
page0.registerContent(async (view) => {
|
||||
let configurePathPage = new ConfigurePathPage(this.apiWrapper, this, page0, this.model, view);
|
||||
let configurePathPage = new ConfigurePathPage(this, page0, this.model, view);
|
||||
pages.set(0, configurePathPage);
|
||||
await configurePathPage.initialize();
|
||||
await configurePathPage.onPageEnter();
|
||||
});
|
||||
|
||||
page1.registerContent(async (view) => {
|
||||
let pickPackagesPage = new PickPackagesPage(this.apiWrapper, this, page1, this.model, view);
|
||||
let pickPackagesPage = new PickPackagesPage(this, page1, this.model, view);
|
||||
pages.set(1, pickPackagesPage);
|
||||
await pickPackagesPage.initialize();
|
||||
});
|
||||
|
||||
@@ -190,7 +190,7 @@ export class AddNewPackageTab {
|
||||
"Installing {0} {1}",
|
||||
packageName,
|
||||
packageVersion);
|
||||
this.jupyterInstallation.apiWrapper.startBackgroundOperation({
|
||||
azdata.tasks.startBackgroundOperation({
|
||||
displayName: taskName,
|
||||
description: taskName,
|
||||
isCancelable: false,
|
||||
|
||||
@@ -225,7 +225,7 @@ export class InstalledPackagesTab {
|
||||
type: confirm,
|
||||
message: localize('managePackages.confirmUninstall', "Are you sure you want to uninstall the specified packages?"),
|
||||
default: false
|
||||
}, this.jupyterInstallation?.apiWrapper);
|
||||
});
|
||||
|
||||
if (doUninstall) {
|
||||
try {
|
||||
@@ -244,7 +244,7 @@ export class InstalledPackagesTab {
|
||||
"Uninstalling {0}",
|
||||
packagesStr);
|
||||
|
||||
this.jupyterInstallation.apiWrapper.startBackgroundOperation({
|
||||
azdata.tasks.startBackgroundOperation({
|
||||
displayName: taskName,
|
||||
description: taskName,
|
||||
isCancelable: false,
|
||||
|
||||
@@ -10,7 +10,6 @@ import * as path from 'path';
|
||||
|
||||
import { JupyterController } from './jupyter/jupyterController';
|
||||
import { AppContext } from './common/appContext';
|
||||
import { ApiWrapper } from './common/apiWrapper';
|
||||
import { IExtensionApi, IPackageManageProvider } from './types';
|
||||
import { CellType } from './contracts/content';
|
||||
import { NotebookUriHandler } from './protocol/notebookUriHandler';
|
||||
@@ -25,7 +24,7 @@ let controller: JupyterController;
|
||||
type ChooseCellType = { label: string, id: CellType };
|
||||
|
||||
export async function activate(extensionContext: vscode.ExtensionContext): Promise<IExtensionApi> {
|
||||
const appContext = new AppContext(extensionContext, new ApiWrapper());
|
||||
const appContext = new AppContext(extensionContext);
|
||||
const createBookPath: string = path.posix.join(extensionContext.extensionPath, 'resources', 'notebooks', 'JupyterBooksCreate.ipynb');
|
||||
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openBook', (bookPath: string, openAsUntitled: boolean, urlToOpen?: string) => openAsUntitled ? providedBookTreeViewProvider.openBook(bookPath, urlToOpen, true) : bookTreeViewProvider.openBook(bookPath, urlToOpen, true)));
|
||||
extensionContext.subscriptions.push(vscode.commands.registerCommand('bookTreeView.openNotebook', (resource) => bookTreeViewProvider.openNotebook(resource)));
|
||||
@@ -117,9 +116,9 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi
|
||||
}
|
||||
|
||||
let workspaceFolders = vscode.workspace.workspaceFolders?.slice() ?? [];
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, workspaceFolders, extensionContext, false, BOOKS_VIEWID, NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(workspaceFolders, extensionContext, false, BOOKS_VIEWID, NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
const providedBookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], extensionContext, true, PROVIDED_BOOKS_VIEWID, NavigationProviders.ProvidedBooksNavigator);
|
||||
const providedBookTreeViewProvider = new BookTreeViewProvider([], extensionContext, true, PROVIDED_BOOKS_VIEWID, NavigationProviders.ProvidedBooksNavigator);
|
||||
await providedBookTreeViewProvider.initialized;
|
||||
|
||||
azdata.nb.onDidChangeActiveNotebookEditor(e => {
|
||||
|
||||
@@ -46,13 +46,12 @@ describe('Notebook Extension Python Installation', function () {
|
||||
|
||||
it('Verify Python Installation', async function () {
|
||||
should(installComplete).be.true('Python setup did not complete.');
|
||||
let apiWrapper = jupyterController.jupyterInstallation.apiWrapper;
|
||||
let jupyterPath = JupyterServerInstallation.getPythonInstallPath(apiWrapper);
|
||||
let jupyterPath = JupyterServerInstallation.getPythonInstallPath();
|
||||
|
||||
console.log(`Expected python path: '${pythonInstallDir}'; actual: '${jupyterPath}'`);
|
||||
should(jupyterPath).be.equal(pythonInstallDir);
|
||||
should(JupyterServerInstallation.isPythonInstalled(apiWrapper)).be.true();
|
||||
should(JupyterServerInstallation.getExistingPythonSetting(apiWrapper)).be.false();
|
||||
should(JupyterServerInstallation.isPythonInstalled()).be.true();
|
||||
should(JupyterServerInstallation.getExistingPythonSetting()).be.false();
|
||||
});
|
||||
|
||||
it('Use Existing Python Installation', async function () {
|
||||
@@ -68,17 +67,16 @@ describe('Notebook Extension Python Installation', function () {
|
||||
console.log('Start Existing Python Installation');
|
||||
let existingPythonPath = path.join(pythonInstallDir, pythonBundleVersion);
|
||||
await install.startInstallProcess(false, { installPath: existingPythonPath, existingPython: true });
|
||||
let apiWrapper = install.apiWrapper;
|
||||
should(JupyterServerInstallation.isPythonInstalled(apiWrapper)).be.true();
|
||||
should(JupyterServerInstallation.getPythonInstallPath(apiWrapper)).be.equal(existingPythonPath);
|
||||
should(JupyterServerInstallation.getExistingPythonSetting(apiWrapper)).be.true();
|
||||
should(JupyterServerInstallation.isPythonInstalled()).be.true();
|
||||
should(JupyterServerInstallation.getPythonInstallPath()).be.equal(existingPythonPath);
|
||||
should(JupyterServerInstallation.getExistingPythonSetting()).be.true();
|
||||
|
||||
// Redo "new" install to restore original settings.
|
||||
// The actual install should get skipped since it already exists.
|
||||
await install.startInstallProcess(false, { installPath: pythonInstallDir, existingPython: false });
|
||||
should(JupyterServerInstallation.isPythonInstalled(apiWrapper)).be.true();
|
||||
should(JupyterServerInstallation.getPythonInstallPath(apiWrapper)).be.equal(pythonInstallDir);
|
||||
should(JupyterServerInstallation.getExistingPythonSetting(apiWrapper)).be.false();
|
||||
should(JupyterServerInstallation.isPythonInstalled()).be.true();
|
||||
should(JupyterServerInstallation.getPythonInstallPath()).be.equal(pythonInstallDir);
|
||||
should(JupyterServerInstallation.getExistingPythonSetting()).be.false();
|
||||
console.log('Existing Python Installation is done');
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import * as utils from '../common/utils';
|
||||
import { IPrompter, IQuestion, confirm } from '../prompts/question';
|
||||
|
||||
import { AppContext } from '../common/appContext';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { LocalJupyterServerManager, ServerInstanceFactory } from './jupyterServerManager';
|
||||
import { NotebookCompletionItemProvider } from '../intellisense/completionItemProvider';
|
||||
import { JupyterNotebookProvider } from './jupyterNotebookProvider';
|
||||
@@ -46,11 +45,7 @@ export class JupyterController implements vscode.Disposable {
|
||||
|
||||
constructor(private appContext: AppContext) {
|
||||
this.prompter = new CodeAdapter();
|
||||
this.outputChannel = this.appContext.apiWrapper.createOutputChannel(constants.extensionOutputChannel);
|
||||
}
|
||||
|
||||
private get apiWrapper(): ApiWrapper {
|
||||
return this.appContext.apiWrapper;
|
||||
this.outputChannel = vscode.window.createOutputChannel(constants.extensionOutputChannel);
|
||||
}
|
||||
|
||||
public get extensionContext(): vscode.ExtensionContext {
|
||||
@@ -69,33 +64,32 @@ export class JupyterController implements vscode.Disposable {
|
||||
public async activate(): Promise<boolean> {
|
||||
this._jupyterInstallation = new JupyterServerInstallation(
|
||||
this.extensionContext.extensionPath,
|
||||
this.outputChannel,
|
||||
this.apiWrapper);
|
||||
this.outputChannel);
|
||||
await this._jupyterInstallation.configurePackagePaths();
|
||||
|
||||
// Add command/task handlers
|
||||
this.apiWrapper.registerTaskHandler(constants.jupyterOpenNotebookTask, (profile: azdata.IConnectionProfile) => {
|
||||
azdata.tasks.registerTask(constants.jupyterOpenNotebookTask, (profile: azdata.IConnectionProfile) => {
|
||||
return this.handleOpenNotebookTask(profile);
|
||||
});
|
||||
this.apiWrapper.registerTaskHandler(constants.jupyterNewNotebookTask, (profile: azdata.IConnectionProfile) => {
|
||||
azdata.tasks.registerTask(constants.jupyterNewNotebookTask, (profile: azdata.IConnectionProfile) => {
|
||||
return this.saveProfileAndCreateNotebook(profile);
|
||||
});
|
||||
this.apiWrapper.registerCommand(constants.jupyterNewNotebookCommand, (explorerContext: azdata.ObjectExplorerContext) => {
|
||||
vscode.commands.registerCommand(constants.jupyterNewNotebookCommand, (explorerContext: azdata.ObjectExplorerContext) => {
|
||||
return this.saveProfileAndCreateNotebook(explorerContext ? explorerContext.connectionProfile : undefined);
|
||||
});
|
||||
this.apiWrapper.registerCommand(constants.jupyterAnalyzeCommand, (explorerContext: azdata.ObjectExplorerContext) => {
|
||||
vscode.commands.registerCommand(constants.jupyterAnalyzeCommand, (explorerContext: azdata.ObjectExplorerContext) => {
|
||||
return this.saveProfileAndAnalyzeNotebook(explorerContext);
|
||||
});
|
||||
|
||||
this.apiWrapper.registerCommand(constants.jupyterReinstallDependenciesCommand, () => { return this.handleDependenciesReinstallation(); });
|
||||
this.apiWrapper.registerCommand(constants.jupyterManagePackages, async (args) => { return this.doManagePackages(args); });
|
||||
this.apiWrapper.registerCommand(constants.jupyterConfigurePython, () => { return this.doConfigurePython(this._jupyterInstallation); });
|
||||
vscode.commands.registerCommand(constants.jupyterReinstallDependenciesCommand, () => { return this.handleDependenciesReinstallation(); });
|
||||
vscode.commands.registerCommand(constants.jupyterManagePackages, async (args) => { return this.doManagePackages(args); });
|
||||
vscode.commands.registerCommand(constants.jupyterConfigurePython, () => { return this.doConfigurePython(this._jupyterInstallation); });
|
||||
|
||||
let supportedFileFilter: vscode.DocumentFilter[] = [
|
||||
{ scheme: 'untitled', language: '*' }
|
||||
];
|
||||
this.registerNotebookProvider();
|
||||
this.extensionContext.subscriptions.push(this.apiWrapper.registerCompletionItemProvider(supportedFileFilter, new NotebookCompletionItemProvider(this._notebookProvider)));
|
||||
this.extensionContext.subscriptions.push(vscode.languages.registerCompletionItemProvider(supportedFileFilter, new NotebookCompletionItemProvider(this._notebookProvider)));
|
||||
|
||||
this.registerDefaultPackageManageProviders();
|
||||
return true;
|
||||
@@ -106,7 +100,6 @@ export class JupyterController implements vscode.Disposable {
|
||||
documentPath: documentUri.fsPath,
|
||||
jupyterInstallation: this._jupyterInstallation,
|
||||
extensionContext: this.extensionContext,
|
||||
apiWrapper: this.apiWrapper,
|
||||
factory: this._serverInstanceFactory
|
||||
}));
|
||||
azdata.nb.registerNotebookProvider(this._notebookProvider);
|
||||
@@ -127,14 +120,14 @@ export class JupyterController implements vscode.Disposable {
|
||||
|
||||
// EVENT HANDLERS //////////////////////////////////////////////////////
|
||||
public async getDefaultConnection(): Promise<azdata.connection.ConnectionProfile> {
|
||||
return await this.apiWrapper.getCurrentConnection();
|
||||
return await azdata.connection.getCurrentConnection();
|
||||
}
|
||||
|
||||
private async handleOpenNotebookTask(profile: azdata.IConnectionProfile): Promise<void> {
|
||||
let notebookFileTypeName = localize('notebookFileType', "Notebooks");
|
||||
let filter: { [key: string]: Array<string> } = {};
|
||||
filter[notebookFileTypeName] = ['ipynb'];
|
||||
let uris = await this.apiWrapper.showOpenDialog({
|
||||
let uris = await vscode.window.showOpenDialog({
|
||||
filters: filter,
|
||||
canSelectFiles: true,
|
||||
canSelectMany: false
|
||||
@@ -144,7 +137,7 @@ export class JupyterController implements vscode.Disposable {
|
||||
// Verify this is a .ipynb file since this isn't actually filtered on Mac/Linux
|
||||
if (path.extname(fileUri.fsPath) !== '.ipynb') {
|
||||
// in the future might want additional supported types
|
||||
this.apiWrapper.showErrorMessage(localize('unsupportedFileType', "Only .ipynb Notebooks are supported"));
|
||||
vscode.window.showErrorMessage(localize('unsupportedFileType', "Only .ipynb Notebooks are supported"));
|
||||
} else {
|
||||
await azdata.nb.showNotebookDocument(fileUri, {
|
||||
connectionProfile: profile,
|
||||
@@ -195,7 +188,7 @@ export class JupyterController implements vscode.Disposable {
|
||||
await this._jupyterInstallation.startInstallProcess(true);
|
||||
}
|
||||
} catch (err) {
|
||||
this.apiWrapper.showErrorMessage(utils.getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +198,7 @@ export class JupyterController implements vscode.Disposable {
|
||||
type: confirm,
|
||||
message: localize('confirmReinstall', "Are you sure you want to reinstall?"),
|
||||
default: true
|
||||
}, this.apiWrapper);
|
||||
});
|
||||
}
|
||||
|
||||
public async doManagePackages(options?: ManagePackageDialogOptions): Promise<void> {
|
||||
@@ -223,7 +216,7 @@ export class JupyterController implements vscode.Disposable {
|
||||
packagesDialog.showDialog();
|
||||
} catch (error) {
|
||||
let message = utils.getErrorMessage(error);
|
||||
this.apiWrapper.showErrorMessage(message);
|
||||
vscode.window.showErrorMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,17 +249,17 @@ export class JupyterController implements vscode.Disposable {
|
||||
|
||||
public doConfigurePython(jupyterInstaller: JupyterServerInstallation): void {
|
||||
if (jupyterInstaller.previewFeaturesEnabled) {
|
||||
let pythonWizard = new ConfigurePythonWizard(this.apiWrapper, jupyterInstaller);
|
||||
let pythonWizard = new ConfigurePythonWizard(jupyterInstaller);
|
||||
pythonWizard.start().catch((err: any) => {
|
||||
this.apiWrapper.showErrorMessage(utils.getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
});
|
||||
pythonWizard.setupComplete.catch((err: any) => {
|
||||
this.apiWrapper.showErrorMessage(utils.getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
});
|
||||
} else {
|
||||
let pythonDialog = new ConfigurePythonDialog(this.apiWrapper, jupyterInstaller);
|
||||
let pythonDialog = new ConfigurePythonDialog(jupyterInstaller);
|
||||
pythonDialog.showDialog().catch((err: any) => {
|
||||
this.apiWrapper.showErrorMessage(utils.getErrorMessage(err));
|
||||
vscode.window.showErrorMessage(utils.getErrorMessage(err));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ import * as vscode from 'vscode';
|
||||
import { ServerConnection, SessionManager } from '@jupyterlab/services';
|
||||
|
||||
import { JupyterSessionManager } from './jupyterSessionManager';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { LocalJupyterServerManager } from './jupyterServerManager';
|
||||
|
||||
export class JupyterNotebookManager implements nb.NotebookManager, vscode.Disposable {
|
||||
protected _serverSettings: ServerConnection.ISettings;
|
||||
private _sessionManager: JupyterSessionManager;
|
||||
|
||||
constructor(private _serverManager: LocalJupyterServerManager, sessionManager?: JupyterSessionManager, private apiWrapper: ApiWrapper = new ApiWrapper()) {
|
||||
constructor(private _serverManager: LocalJupyterServerManager, sessionManager?: JupyterSessionManager) {
|
||||
let pythonEnvVarPath = this._serverManager && this._serverManager.jupyterServerInstallation && this._serverManager.jupyterServerInstallation.pythonEnvVarPath;
|
||||
this._sessionManager = sessionManager || new JupyterSessionManager(pythonEnvVarPath);
|
||||
this._serverManager.onServerStarted(() => {
|
||||
@@ -49,7 +48,7 @@ export class JupyterNotebookManager implements nb.NotebookManager, vscode.Dispos
|
||||
this._sessionManager.shutdownAll().then(() => this._sessionManager.dispose());
|
||||
}
|
||||
if (this._serverManager) {
|
||||
this._serverManager.stopServer().then(success => undefined, error => this.apiWrapper.showErrorMessage(error));
|
||||
this._serverManager.stopServer().then(success => undefined, error => vscode.window.showErrorMessage(error));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as request from 'request';
|
||||
import * as zip from 'adm-zip';
|
||||
import * as tar from 'tar';
|
||||
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as constants from '../common/constants';
|
||||
import * as utils from '../common/utils';
|
||||
import { Deferred } from '../common/promise';
|
||||
@@ -62,7 +61,6 @@ export interface IJupyterServerInstallation {
|
||||
installPythonPackage(backgroundOperation: azdata.BackgroundOperation, usingExistingPython: boolean, pythonInstallationPath: string, outputChannel: vscode.OutputChannel): Promise<void>;
|
||||
}
|
||||
export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
public apiWrapper: ApiWrapper;
|
||||
public extensionPath: string;
|
||||
public pythonBinPath: string;
|
||||
public outputChannel: vscode.OutputChannel;
|
||||
@@ -114,10 +112,9 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
|
||||
private readonly _runningOnSAW: boolean;
|
||||
|
||||
constructor(extensionPath: string, outputChannel: vscode.OutputChannel, apiWrapper: ApiWrapper) {
|
||||
constructor(extensionPath: string, outputChannel: vscode.OutputChannel) {
|
||||
this.extensionPath = extensionPath;
|
||||
this.outputChannel = outputChannel;
|
||||
this.apiWrapper = apiWrapper;
|
||||
|
||||
this._runningOnSAW = vscode.env.appName.toLowerCase().indexOf('saw') > 0;
|
||||
vscode.commands.executeCommand(constants.BuiltInCommands.SetContext, 'notebook:runningOnSAW', this._runningOnSAW);
|
||||
@@ -126,8 +123,8 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
this._pythonInstallationPath = `${vscode.env.appRoot}\\ads-python`;
|
||||
this._usingExistingPython = true;
|
||||
} else {
|
||||
this._pythonInstallationPath = JupyterServerInstallation.getPythonInstallPath(this.apiWrapper);
|
||||
this._usingExistingPython = JupyterServerInstallation.getExistingPythonSetting(this.apiWrapper);
|
||||
this._pythonInstallationPath = JupyterServerInstallation.getPythonInstallPath();
|
||||
this._usingExistingPython = JupyterServerInstallation.getExistingPythonSetting();
|
||||
}
|
||||
this._usingConda = false;
|
||||
this._installInProgress = false;
|
||||
@@ -427,7 +424,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
}
|
||||
|
||||
if (this._installInProgress) {
|
||||
this.apiWrapper.showInfoMessage(msgWaitingForInstall);
|
||||
vscode.window.showInformationMessage(msgWaitingForInstall);
|
||||
return this._installCompletion.promise;
|
||||
}
|
||||
|
||||
@@ -438,14 +435,14 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
this._usingExistingPython = installSettings.existingPython;
|
||||
await this.configurePackagePaths();
|
||||
|
||||
this.apiWrapper.startBackgroundOperation({
|
||||
azdata.tasks.startBackgroundOperation({
|
||||
displayName: msgTaskName,
|
||||
description: msgTaskName,
|
||||
isCancelable: false,
|
||||
operation: op => {
|
||||
this.installDependencies(op, forceInstall, installSettings.specificPackages)
|
||||
.then(async () => {
|
||||
let notebookConfig = this.apiWrapper.getConfiguration(constants.notebookConfigKey);
|
||||
let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
await notebookConfig.update(constants.pythonPathConfigKey, this._pythonInstallationPath, vscode.ConfigurationTarget.Global);
|
||||
await notebookConfig.update(constants.existingPythonConfigKey, this._usingExistingPython, vscode.ConfigurationTarget.Global);
|
||||
await this.configurePackagePaths();
|
||||
@@ -472,21 +469,21 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (this._installInProgress) {
|
||||
this.apiWrapper.showInfoMessage(msgWaitingForInstall);
|
||||
vscode.window.showInformationMessage(msgWaitingForInstall);
|
||||
return this._installCompletion.promise;
|
||||
}
|
||||
|
||||
let isPythonInstalled = JupyterServerInstallation.isPythonInstalled(this.apiWrapper);
|
||||
let isPythonInstalled = JupyterServerInstallation.isPythonInstalled();
|
||||
let areRequiredPackagesInstalled = await this.areRequiredPackagesInstalled(kernelDisplayName);
|
||||
if (!isPythonInstalled || !areRequiredPackagesInstalled) {
|
||||
if (this.previewFeaturesEnabled) {
|
||||
let pythonWizard = new ConfigurePythonWizard(this.apiWrapper, this);
|
||||
let pythonWizard = new ConfigurePythonWizard(this);
|
||||
await pythonWizard.start(kernelDisplayName, true);
|
||||
return pythonWizard.setupComplete.then(() => {
|
||||
this._kernelSetupCache.set(kernelDisplayName, true);
|
||||
});
|
||||
} else {
|
||||
let pythonDialog = new ConfigurePythonDialog(this.apiWrapper, this);
|
||||
let pythonDialog = new ConfigurePythonDialog(this);
|
||||
return pythonDialog.showDialog(true);
|
||||
}
|
||||
}
|
||||
@@ -500,7 +497,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (this._installInProgress) {
|
||||
this.apiWrapper.showInfoMessage(msgWaitingForInstall);
|
||||
vscode.window.showInformationMessage(msgWaitingForInstall);
|
||||
return this._installCompletion.promise;
|
||||
}
|
||||
|
||||
@@ -607,7 +604,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
type: confirm,
|
||||
message: localize('confirmPackageUpgrade', "Some required python packages need to be installed. Would you like to install them now?"),
|
||||
default: true
|
||||
}, this.apiWrapper);
|
||||
});
|
||||
if (!doUpgrade) {
|
||||
throw new Error(localize('configurePython.packageInstallDeclined', "Package installation was declined."));
|
||||
}
|
||||
@@ -637,7 +634,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
packagesStr);
|
||||
|
||||
let backgroundTaskComplete = new Deferred<void>();
|
||||
this.apiWrapper.startBackgroundOperation({
|
||||
azdata.tasks.startBackgroundOperation({
|
||||
displayName: taskName,
|
||||
description: taskName,
|
||||
isCancelable: false,
|
||||
@@ -667,7 +664,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
if (!fs.existsSync(pythonExePath)) {
|
||||
return [];
|
||||
}
|
||||
} else if (!JupyterServerInstallation.isPythonInstalled(this.apiWrapper)) {
|
||||
} else if (!JupyterServerInstallation.isPythonInstalled()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -801,16 +798,15 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
|
||||
/**
|
||||
* Checks if a python executable exists at the "notebook.pythonPath" defined in the user's settings.
|
||||
* @param apiWrapper An ApiWrapper to use when retrieving user settings info.
|
||||
*/
|
||||
public static isPythonInstalled(apiWrapper: ApiWrapper): boolean {
|
||||
public static isPythonInstalled(): boolean {
|
||||
// Don't use _pythonExecutable here, since it could be populated with a default value
|
||||
let pathSetting = JupyterServerInstallation.getPythonPathSetting(apiWrapper);
|
||||
let pathSetting = JupyterServerInstallation.getPythonPathSetting();
|
||||
if (!pathSetting) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let useExistingInstall = JupyterServerInstallation.getExistingPythonSetting(apiWrapper);
|
||||
let useExistingInstall = JupyterServerInstallation.getExistingPythonSetting();
|
||||
let pythonExe = JupyterServerInstallation.getPythonExePath(pathSetting, useExistingInstall);
|
||||
// eslint-disable-next-line no-sync
|
||||
return fs.existsSync(pythonExe);
|
||||
@@ -819,34 +815,29 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
/**
|
||||
* Returns the Python installation path defined in "notebook.pythonPath" in the user's settings.
|
||||
* Returns a default path if the setting is not defined.
|
||||
* @param apiWrapper An ApiWrapper to use when retrieving user settings info.
|
||||
*/
|
||||
public static getPythonInstallPath(apiWrapper: ApiWrapper): string {
|
||||
let userPath = JupyterServerInstallation.getPythonPathSetting(apiWrapper);
|
||||
public static getPythonInstallPath(): string {
|
||||
let userPath = JupyterServerInstallation.getPythonPathSetting();
|
||||
return userPath ? userPath : JupyterServerInstallation.DefaultPythonLocation;
|
||||
}
|
||||
|
||||
public static getExistingPythonSetting(apiWrapper: ApiWrapper): boolean {
|
||||
public static getExistingPythonSetting(): boolean {
|
||||
let useExistingPython = false;
|
||||
if (apiWrapper) {
|
||||
let notebookConfig = apiWrapper.getConfiguration(constants.notebookConfigKey);
|
||||
if (notebookConfig) {
|
||||
useExistingPython = !!notebookConfig[constants.existingPythonConfigKey];
|
||||
}
|
||||
let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
if (notebookConfig) {
|
||||
useExistingPython = !!notebookConfig[constants.existingPythonConfigKey];
|
||||
}
|
||||
return useExistingPython;
|
||||
}
|
||||
|
||||
public static getPythonPathSetting(apiWrapper: ApiWrapper): string {
|
||||
public static getPythonPathSetting(): string {
|
||||
let path = undefined;
|
||||
if (apiWrapper) {
|
||||
let notebookConfig = apiWrapper.getConfiguration(constants.notebookConfigKey);
|
||||
if (notebookConfig) {
|
||||
let configPythonPath = notebookConfig[constants.pythonPathConfigKey];
|
||||
// eslint-disable-next-line no-sync
|
||||
if (configPythonPath && fs.existsSync(configPythonPath)) {
|
||||
path = configPythonPath;
|
||||
}
|
||||
let notebookConfig = vscode.workspace.getConfiguration(constants.notebookConfigKey);
|
||||
if (notebookConfig) {
|
||||
let configPythonPath = notebookConfig[constants.pythonPathConfigKey];
|
||||
// eslint-disable-next-line no-sync
|
||||
if (configPythonPath && fs.existsSync(configPythonPath)) {
|
||||
path = configPythonPath;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
@@ -888,7 +879,7 @@ export class JupyterServerInstallation implements IJupyterServerInstallation {
|
||||
}
|
||||
|
||||
public get previewFeaturesEnabled(): boolean {
|
||||
return this.apiWrapper.getConfiguration('workbench').get('enablePreviewFeatures');
|
||||
return vscode.workspace.getConfiguration('workbench').get('enablePreviewFeatures');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { ServerConnection } from '@jupyterlab/services';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { JupyterServerInstallation } from './jupyterServerInstallation';
|
||||
import * as utils from '../common/utils';
|
||||
import { IServerInstance } from './common';
|
||||
@@ -21,18 +20,15 @@ export interface IServerManagerOptions {
|
||||
documentPath: string;
|
||||
jupyterInstallation: JupyterServerInstallation;
|
||||
extensionContext: vscode.ExtensionContext;
|
||||
apiWrapper?: ApiWrapper;
|
||||
factory?: ServerInstanceFactory;
|
||||
}
|
||||
export class LocalJupyterServerManager implements nb.ServerManager, vscode.Disposable {
|
||||
private _serverSettings: Partial<ServerConnection.ISettings>;
|
||||
private _onServerStarted = new vscode.EventEmitter<void>();
|
||||
private _instanceOptions: IInstanceOptions;
|
||||
private _apiWrapper: ApiWrapper;
|
||||
private _jupyterServer: IServerInstance;
|
||||
factory: ServerInstanceFactory;
|
||||
constructor(private options: IServerManagerOptions) {
|
||||
this._apiWrapper = options.apiWrapper || new ApiWrapper();
|
||||
this.factory = options.factory || new ServerInstanceFactory();
|
||||
}
|
||||
|
||||
@@ -74,7 +70,7 @@ export class LocalJupyterServerManager implements nb.ServerManager, vscode.Dispo
|
||||
public dispose(): void {
|
||||
this.stopServer().catch(err => {
|
||||
let msg = utils.getErrorMessage(err);
|
||||
this._apiWrapper.showErrorMessage(localize('shutdownError', "Shutdown of Notebook server failed: {0}", msg));
|
||||
vscode.window.showErrorMessage(localize('shutdownError', "Shutdown of Notebook server failed: {0}", msg));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,7 +120,7 @@ export class LocalJupyterServerManager implements nb.ServerManager, vscode.Dispo
|
||||
// /path2/nb2.ipynb
|
||||
// /path2/nb3.ipynb
|
||||
// ... will result in 2 notebook servers being started, one for /path1/ and one for /path2/
|
||||
let notebookDir = this._apiWrapper.getWorkspacePathFromUri(vscode.Uri.file(this.documentPath));
|
||||
let notebookDir = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(this.documentPath))?.uri.fsPath;
|
||||
if (!notebookDir) {
|
||||
let docDir;
|
||||
// If a folder is passed in for documentPath, use the folder instead of calling dirname
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
import PromptFactory from './factory';
|
||||
import EscapeException from './escapeException';
|
||||
import { IQuestion, IPrompter } from './question';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
// Supports simple pattern for prompting for user input and acting on this
|
||||
export default class CodeAdapter implements IPrompter {
|
||||
|
||||
public promptSingle<T>(question: IQuestion, apiWrapper?: ApiWrapper): Promise<T> {
|
||||
public promptSingle<T>(question: IQuestion): Promise<T> {
|
||||
let questions: IQuestion[] = [question];
|
||||
return this.prompt(questions, apiWrapper).then((answers: { [key: string]: T }) => {
|
||||
return this.prompt(questions).then((answers: { [key: string]: T }) => {
|
||||
if (answers) {
|
||||
let response: T = answers[question.name];
|
||||
return response || undefined;
|
||||
@@ -20,7 +20,7 @@ export default class CodeAdapter implements IPrompter {
|
||||
});
|
||||
}
|
||||
|
||||
public prompt<T>(questions: IQuestion[], apiWrapper = new ApiWrapper()): Promise<{ [key: string]: T }> {
|
||||
public prompt<T>(questions: IQuestion[]): Promise<{ [key: string]: T }> {
|
||||
let answers: { [key: string]: T } = {};
|
||||
|
||||
// Collapse multiple questions into a set of prompt steps
|
||||
@@ -36,7 +36,7 @@ export default class CodeAdapter implements IPrompter {
|
||||
// }
|
||||
|
||||
if (!question.shouldPrompt || question.shouldPrompt(answers) === true) {
|
||||
return prompt.render(apiWrapper).then((result: any) => {
|
||||
return prompt.render().then((result: any) => {
|
||||
answers[question.name] = result;
|
||||
|
||||
if (question.onAnswered) {
|
||||
@@ -54,7 +54,7 @@ export default class CodeAdapter implements IPrompter {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
apiWrapper.showErrorMessage(err.message);
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
|
||||
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
|
||||
|
||||
import Prompt from './prompt';
|
||||
import LocalizedConstants = require('../common/localizedConstants');
|
||||
import EscapeException from './escapeException';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export default class ConfirmPrompt extends Prompt {
|
||||
|
||||
@@ -14,7 +12,7 @@ export default class ConfirmPrompt extends Prompt {
|
||||
super(question);
|
||||
}
|
||||
|
||||
public render(apiWrapper: ApiWrapper): any {
|
||||
public render(): any {
|
||||
let choices: { [id: string]: boolean } = {};
|
||||
choices[LocalizedConstants.msgYes] = true;
|
||||
choices[LocalizedConstants.msgNo] = false;
|
||||
@@ -22,7 +20,7 @@ export default class ConfirmPrompt extends Prompt {
|
||||
let options = this.defaultQuickPickOptions;
|
||||
options.placeHolder = this._question.message;
|
||||
|
||||
return apiWrapper.showQuickPick(Object.keys(choices), options)
|
||||
return vscode.window.showQuickPick(Object.keys(choices), options)
|
||||
.then(result => {
|
||||
if (result === undefined) {
|
||||
throw new EscapeException();
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
'use strict';
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export default require('error-ex')('EscapeException');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
|
||||
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
// This code is originally from https://github.com/DonJayamanne/bowerVSCode
|
||||
// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE
|
||||
|
||||
import { InputBoxOptions, QuickPickOptions } from 'vscode';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
|
||||
abstract class Prompt {
|
||||
|
||||
@@ -16,7 +13,7 @@ abstract class Prompt {
|
||||
this._ignoreFocusOut = ignoreFocusOut ? ignoreFocusOut : false;
|
||||
}
|
||||
|
||||
public abstract render(apiWrapper: ApiWrapper): any;
|
||||
public abstract render(): any;
|
||||
|
||||
protected get defaultQuickPickOptions(): QuickPickOptions {
|
||||
return {
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import vscode = require('vscode');
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export const confirm = 'confirm';
|
||||
|
||||
@@ -48,14 +47,14 @@ export interface IQuestionHandler {
|
||||
}
|
||||
|
||||
export interface IPrompter {
|
||||
promptSingle<T>(question: IQuestion, apiWrapper?: ApiWrapper): Promise<T>;
|
||||
promptSingle<T>(question: IQuestion): Promise<T>;
|
||||
/**
|
||||
* Prompts for multiple questions
|
||||
*
|
||||
* @returns Map of question IDs to results, or undefined if
|
||||
* the user canceled the question session
|
||||
*/
|
||||
prompt<T>(questions: IQuestion[], apiWrapper?: ApiWrapper): Promise<{ [questionId: string]: any }>;
|
||||
prompt<T>(questions: IQuestion[]): Promise<{ [questionId: string]: any }>;
|
||||
}
|
||||
|
||||
export interface IPromptCallback {
|
||||
|
||||
@@ -15,8 +15,6 @@ import { BookTreeItem, BookTreeItemType } from '../../book/bookTreeItem';
|
||||
import { promisify } from 'util';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
import { exists } from '../../common/utils';
|
||||
import { AppContext } from '../../common/appContext';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { BookModel } from '../../book/bookModel';
|
||||
import { BookTrustManager } from '../../book/bookTrustManager';
|
||||
import { NavigationProviders } from '../../common/constants';
|
||||
@@ -56,7 +54,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let expectedMarkdown: IExpectedBookItem;
|
||||
let expectedExternalLink: IExpectedBookItem;
|
||||
let expectedBook: IExpectedBookItem;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
@@ -103,7 +100,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
sections: [expectedNotebook1, expectedMarkdown, expectedExternalLink],
|
||||
title: 'Test Book'
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
|
||||
await fs.mkdir(rootFolderPath);
|
||||
await fs.mkdir(bookFolderPath);
|
||||
@@ -116,11 +112,10 @@ describe('BookTreeViewProviderTests', function () {
|
||||
await fs.writeFile(notebook2File, '');
|
||||
await fs.writeFile(notebook3File, '');
|
||||
await fs.writeFile(markdownFile, '');
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should initialize correctly with empty workspace array', async () => {
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
});
|
||||
|
||||
@@ -130,7 +125,7 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
});
|
||||
|
||||
@@ -145,7 +140,7 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [book, nonBook], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider([book, nonBook], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
should(bookTreeViewProvider.books.length).equal(1, 'Expected book was not initialized');
|
||||
});
|
||||
@@ -162,8 +157,8 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
providedbookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, true, 'providedBooksView', NavigationProviders.ProvidedBooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
providedbookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, true, 'providedBooksView', NavigationProviders.ProvidedBooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
await Promise.race([providedbookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('ProvidedBooksTreeViewProvider did not initialize in time'); })]);
|
||||
@@ -202,7 +197,7 @@ describe('BookTreeViewProviderTests', function () {
|
||||
|
||||
it('bookTreeViewProvider should set notebooks trusted to true on trustBook', async () => {
|
||||
let notebook1Path = path.join(rootFolderPath, 'Book', 'content', 'notebook1.ipynb');
|
||||
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books, appContext.apiWrapper);
|
||||
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books);
|
||||
let isTrusted = bookTrustManager.isNotebookTrustedByDefault(vscode.Uri.file(notebook1Path).fsPath);
|
||||
should(isTrusted).equal(false, 'Notebook should not be trusted by default');
|
||||
|
||||
@@ -280,7 +275,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let tableOfContentsFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -297,11 +291,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should ignore toc.yml files not in _data folder', async () => {
|
||||
@@ -324,7 +316,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let tocFile: string;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -340,11 +331,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should show error message if config.yml file not found', async () => {
|
||||
@@ -372,7 +361,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let expectedNotebook2: IExpectedBookItem;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -400,11 +388,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should show error if notebook or markdown file is missing', async function (): Promise<void> {
|
||||
@@ -426,7 +412,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let rootFolderPath: string;
|
||||
let tableOfContentsFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -443,11 +428,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
await fs.writeFile(notebook2File, '');
|
||||
|
||||
const mockExtensionContext = new MockExtensionContext();
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should add book and initialize book on openBook', async () => {
|
||||
@@ -502,7 +485,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let standaloneNotebookTitle: string;
|
||||
let standaloneNotebookFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookFolderTest_${uuid.v4()}`);
|
||||
@@ -527,11 +509,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
await fs.writeFile(standaloneNotebookFile, '');
|
||||
|
||||
const mockExtensionContext = new MockExtensionContext();
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should include books and notebooks when opening parent folder', async () => {
|
||||
|
||||
@@ -9,9 +9,9 @@ import * as TypeMoq from 'typemoq';
|
||||
import * as constants from '../../common/constants';
|
||||
import { IBookTrustManager, BookTrustManager } from '../../book/bookTrustManager';
|
||||
import { BookTreeItem, BookTreeItemFormat, BookTreeItemType } from '../../book/bookTreeItem';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { WorkspaceConfiguration, ConfigurationTarget } from 'vscode';
|
||||
import * as vscode from 'vscode';
|
||||
import { BookModel } from '../../book/bookModel';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
describe('BookTrustManagerTests', function () {
|
||||
|
||||
@@ -20,36 +20,36 @@ describe('BookTrustManagerTests', function () {
|
||||
let trustedSubFolders: string[];
|
||||
let books: BookModel[];
|
||||
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
trustedSubFolders = ['/SubFolder/'];
|
||||
|
||||
// Mock Workspace Configuration
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<WorkspaceConfiguration> = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<vscode.WorkspaceConfiguration> = TypeMoq.Mock.ofType<vscode.WorkspaceConfiguration>();
|
||||
workspaceConfigurtionMock.setup(config => config.get(TypeMoq.It.isValue(constants.trustedBooksConfigKey))).returns(() => [].concat(trustedSubFolders));
|
||||
workspaceConfigurtionMock.setup(config => config.update(TypeMoq.It.isValue(constants.trustedBooksConfigKey), TypeMoq.It.isAny(), TypeMoq.It.isValue(false))).returns((key: string, newValues: string[]) => {
|
||||
trustedSubFolders.splice(0, trustedSubFolders.length, ...newValues); // Replace
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
// Mock Api Wrapper
|
||||
let apiWrapperMock: TypeMoq.IMock<ApiWrapper> = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
|
||||
apiWrapperMock.setup(api => api.getWorkspaceFolders()).returns(() => [
|
||||
{
|
||||
// @ts-ignore - Don't need all URI properties for this tests
|
||||
sinon.replaceGetter(vscode.workspace, 'workspaceFolders', () => {
|
||||
return <vscode.WorkspaceFolder[]>[{
|
||||
uri: {
|
||||
fsPath: '/temp/'
|
||||
},
|
||||
},
|
||||
{
|
||||
// @ts-ignore - Don't need all URI properties for this tests
|
||||
uri: {
|
||||
fsPath: '/temp2/'
|
||||
}
|
||||
},
|
||||
]);
|
||||
];
|
||||
});
|
||||
|
||||
apiWrapperMock.setup(api => api.getConfiguration(TypeMoq.It.isValue(constants.notebookConfigKey))).returns(() => workspaceConfigurtionMock.object);
|
||||
sinon.stub(vscode.workspace, 'getConfiguration').returns(workspaceConfigurtionMock.object);
|
||||
|
||||
// Mock Book Data
|
||||
let bookTreeItemFormat1: BookTreeItemFormat = {
|
||||
@@ -108,24 +108,24 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
let bookModel1Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel1Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat1, undefined), new BookTreeItem(bookTreeItemFormat2, undefined)]);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content','sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content','sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder2','content','sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
let bookModel2Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel2Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat3, undefined)]);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp2','SubFolder','content','sample','notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp2', 'SubFolder', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
books = [bookModel1Mock.object, bookModel2Mock.object];
|
||||
|
||||
bookTrustManager = new BookTrustManager(books, apiWrapperMock.object);
|
||||
bookTrustManager = new BookTrustManager(books);
|
||||
});
|
||||
|
||||
it('should trust notebooks in a trusted book within a workspace', async () => {
|
||||
let notebookUri1 = path.join(path.sep,'temp','SubFolder','content','sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep,'temp','SubFolder','content','sample', 'notebook2.ipynb');
|
||||
let notebookUri1 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb');
|
||||
|
||||
let isNotebook1Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri1);
|
||||
let isNotebook2Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri2);
|
||||
@@ -136,14 +136,14 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook in an untrusted book within a workspace', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.false('Notebook should be trusted');
|
||||
});
|
||||
|
||||
it('should trust notebook after book has been trusted within a workspace', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
|
||||
@@ -157,7 +157,7 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook when untrusting a book within a workspace', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.true('Notebook should be trusted');
|
||||
@@ -195,19 +195,13 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock Workspace Configuration
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<WorkspaceConfiguration> = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<vscode.WorkspaceConfiguration> = TypeMoq.Mock.ofType<vscode.WorkspaceConfiguration>();
|
||||
workspaceConfigurtionMock.setup(config => config.get(TypeMoq.It.isValue(constants.trustedBooksConfigKey))).returns(() => [].concat(trustedFolders));
|
||||
workspaceConfigurtionMock.setup(config => config.update(TypeMoq.It.isValue(constants.trustedBooksConfigKey), TypeMoq.It.isAny(), TypeMoq.It.isValue(ConfigurationTarget.Global))).returns((key: string, newValues: string[], target: ConfigurationTarget) => {
|
||||
workspaceConfigurtionMock.setup(config => config.update(TypeMoq.It.isValue(constants.trustedBooksConfigKey), TypeMoq.It.isAny(), TypeMoq.It.isValue(vscode.ConfigurationTarget.Global))).returns((key: string, newValues: string[], target: vscode.ConfigurationTarget) => {
|
||||
trustedFolders.splice(0, trustedFolders.length, ...newValues); // Replace
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
|
||||
// Mock Api Wrapper
|
||||
let apiWrapperMock: TypeMoq.IMock<ApiWrapper> = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
|
||||
apiWrapperMock.setup(api => api.getWorkspaceFolders()).returns(() => []);
|
||||
apiWrapperMock.setup(api => api.getConfiguration(TypeMoq.It.isValue(constants.notebookConfigKey))).returns(() => workspaceConfigurtionMock.object);
|
||||
let bookTreeItemFormat1: BookTreeItemFormat = {
|
||||
contentPath: undefined,
|
||||
root: '/temp/SubFolder/',
|
||||
@@ -250,26 +244,26 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
let bookModel1Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel1Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat1, undefined)]);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
let bookModel2Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel2Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat2, undefined)]);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
books = [bookModel1Mock.object, bookModel2Mock.object];
|
||||
|
||||
bookTrustManager = new BookTrustManager(books, apiWrapperMock.object);
|
||||
bookTrustManager = new BookTrustManager(books);
|
||||
});
|
||||
|
||||
it('should trust notebooks in a trusted book in a folder', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/');
|
||||
|
||||
let notebookUri1 = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook2.ipynb');
|
||||
let notebookUri1 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb');
|
||||
|
||||
let isNotebook1Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri1);
|
||||
let isNotebook2Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri2);
|
||||
@@ -280,14 +274,14 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook in an untrusted book in a folder', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.false('Notebook should be trusted');
|
||||
});
|
||||
|
||||
it('should trust notebook after book has been added to a folder', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample','notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
|
||||
@@ -301,7 +295,7 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
it('should NOT trust a notebook when untrusting a book in folder', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/');
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.true('Notebook should be trusted');
|
||||
@@ -323,7 +317,7 @@ describe('BookTrustManagerTests', function () {
|
||||
it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/');
|
||||
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notInToc.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notInToc.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.false('Notebook should NOT be trusted');
|
||||
|
||||
@@ -8,25 +8,24 @@ import { NotebookUtils } from '../../common/notebookUtils';
|
||||
import * as should from 'should';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as uuid from 'uuid';
|
||||
import { promises as fs } from 'fs';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { tryDeleteFile } from './testUtils';
|
||||
import { CellTypes } from '../../contracts/content';
|
||||
|
||||
describe('notebookUtils Tests', function (): void {
|
||||
let notebookUtils: NotebookUtils;
|
||||
let apiWrapperMock: TypeMoq.IMock<ApiWrapper>;
|
||||
let notebookUtils: NotebookUtils = new NotebookUtils();
|
||||
let showErrorMessageSpy: sinon.SinonSpy;
|
||||
|
||||
this.beforeAll(async function(): Promise<void> {
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
beforeEach(function(): void {
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
});
|
||||
|
||||
beforeEach(function (): void {
|
||||
apiWrapperMock = TypeMoq.Mock.ofInstance(new ApiWrapper());
|
||||
notebookUtils = new NotebookUtils(apiWrapperMock.object);
|
||||
afterEach(function(): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
this.afterAll(async function (): Promise<void> {
|
||||
@@ -74,7 +73,7 @@ describe('notebookUtils Tests', function (): void {
|
||||
const notebookUri = vscode.Uri.file(notebookPath);
|
||||
try {
|
||||
await fs.writeFile(notebookPath, '');
|
||||
apiWrapperMock.setup(x => x.showOpenDialog(TypeMoq.It.isAny())).returns(() => Promise.resolve([notebookUri]));
|
||||
sinon.stub(vscode.window, 'showOpenDialog').returns(Promise.resolve([notebookUri]));
|
||||
await notebookUtils.openNotebook();
|
||||
should(azdata.nb.notebookDocuments.find(doc => doc.fileName === notebookUri.fsPath)).not.be.undefined();
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
@@ -84,88 +83,86 @@ describe('notebookUtils Tests', function (): void {
|
||||
});
|
||||
|
||||
it('shows error if unexpected error is thrown', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.showOpenDialog(TypeMoq.It.isAny())).throws(new Error('Unexpected error'));
|
||||
apiWrapperMock.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns(() => Promise.resolve(''));
|
||||
sinon.stub(vscode.window, 'showOpenDialog').throws(new Error('Unexpected error'));
|
||||
await notebookUtils.openNotebook();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
});
|
||||
});
|
||||
|
||||
describe('runActiveCell', function () {
|
||||
it('shows error when no notebook visible', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
await notebookUtils.runActiveCell();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible', async function (): Promise<void> {
|
||||
let mockNotebookEditor = TypeMoq.Mock.ofType<azdata.nb.NotebookEditor>();
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => mockNotebookEditor.object);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => mockNotebookEditor.object);
|
||||
await notebookUtils.runActiveCell();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
mockNotebookEditor.verify(x => x.runCell(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearActiveCellOutput', function () {
|
||||
it('shows error when no notebook visible', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.clearActiveCellOutput();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible', async function (): Promise<void> {
|
||||
let mockNotebookEditor = TypeMoq.Mock.ofType<azdata.nb.NotebookEditor>();
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => mockNotebookEditor.object);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => mockNotebookEditor.object);
|
||||
await notebookUtils.clearActiveCellOutput();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
mockNotebookEditor.verify(x => x.clearOutput(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
describe('runAllCells', function () {
|
||||
it('shows error when no notebook visible', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.runAllCells();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible', async function (): Promise<void> {
|
||||
let mockNotebookEditor = TypeMoq.Mock.ofType<azdata.nb.NotebookEditor>();
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => mockNotebookEditor.object);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => mockNotebookEditor.object);
|
||||
await notebookUtils.runAllCells();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
mockNotebookEditor.verify(x => x.runAllCells(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
describe('addCell', function () {
|
||||
it('shows error when no notebook visible for code cell', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.addCell('code');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('shows error when no notebook visible for markdown cell', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.addCell('markdown');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible for code cell', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
await notebookUtils.addCell('code');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
|
||||
should(notebookEditor.document.cells.length).equal(1);
|
||||
should(notebookEditor.document.cells[0].contents.cell_type).equal(CellTypes.Code);
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible for markdown cell', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
await notebookUtils.addCell('markdown');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
|
||||
should(notebookEditor.document.cells.length).equal(1);
|
||||
should(notebookEditor.document.cells[0].contents.cell_type).equal(CellTypes.Markdown);
|
||||
});
|
||||
@@ -174,8 +171,8 @@ describe('notebookUtils Tests', function (): void {
|
||||
describe('analyzeNotebook', function () {
|
||||
it('creates cell when oeContext exists', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
apiWrapperMock.setup(x => x.showNotebookDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(notebookEditor));
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
sinon.stub(azdata.nb, 'showNotebookDocument').returns(Promise.resolve(notebookEditor));
|
||||
const oeContext: azdata.ObjectExplorerContext = {
|
||||
connectionProfile: undefined,
|
||||
isConnectionNode: true,
|
||||
@@ -197,8 +194,8 @@ describe('notebookUtils Tests', function (): void {
|
||||
|
||||
it('does not create new cell when oeContext does not exist', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
apiWrapperMock.setup(x => x.showNotebookDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(notebookEditor));
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
sinon.stub(azdata.nb, 'showNotebookDocument').returns(Promise.resolve(notebookEditor));
|
||||
await notebookUtils.analyzeNotebook();
|
||||
should(notebookEditor.document.cells.length).equal(0, 'No cells should exist');
|
||||
});
|
||||
|
||||
@@ -3,47 +3,51 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as should from 'should';
|
||||
import * as sinon from 'sinon';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { IPrompter, confirm, IQuestion } from '../../prompts/question';
|
||||
import CodeAdapter from '../../prompts/adapter';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
|
||||
|
||||
describe('Prompt', () => {
|
||||
|
||||
let prompter: IPrompter;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
|
||||
let showErrorMessageSpy: sinon.SinonSpy;
|
||||
|
||||
before(function () {
|
||||
prompter = new CodeAdapter();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockApiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny()));
|
||||
beforeEach(function(): void {
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should not find prompt for invalid question type', async function (): Promise<void> {
|
||||
const showQuickPickSpy = sinon.spy(vscode.window, 'showQuickPick');
|
||||
await prompter.promptSingle<boolean>(<IQuestion>{
|
||||
type: 'invalidType',
|
||||
message: 'sample message',
|
||||
default: false
|
||||
}, mockApiWrapper.object);
|
||||
mockApiWrapper.verify(s => s.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
mockApiWrapper.verify(s => s.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
});
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
should(showQuickPickSpy.notCalled).be.true('showQuickPick should never have been called');
|
||||
});
|
||||
|
||||
it('Should find prompt for confirm type', async function (): Promise<void> {
|
||||
mockApiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve('Yes'));
|
||||
const quickPickSpy = sinon.stub(vscode.window, 'showQuickPick').returns(Promise.resolve('Yes') as any);
|
||||
await prompter.promptSingle<boolean>(<IQuestion>{
|
||||
type: confirm,
|
||||
message: 'sample message',
|
||||
default: false
|
||||
}, mockApiWrapper.object);
|
||||
mockApiWrapper.verify(s => s.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
mockApiWrapper.verify(s => s.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
|
||||
should(quickPickSpy.calledOnce).be.true('showQuickPick should have been called once');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { ConfigurePythonWizard, ConfigurePythonModel } from '../dialog/configurePython/configurePythonWizard';
|
||||
import { JupyterServerInstallation } from '../jupyter/jupyterServerInstallation';
|
||||
import { ConfigurePathPage } from '../dialog/configurePython/configurePathPage';
|
||||
@@ -16,7 +15,6 @@ import { TestContext, createViewContext, TestButton } from './common';
|
||||
import { EventEmitter } from 'vscode';
|
||||
|
||||
describe('Configure Python Wizard', function () {
|
||||
let apiWrapper: ApiWrapper = new ApiWrapper();
|
||||
let testWizard: ConfigurePythonWizard;
|
||||
let viewContext: TestContext;
|
||||
let testInstallation: JupyterServerInstallation;
|
||||
@@ -45,21 +43,21 @@ describe('Configure Python Wizard', function () {
|
||||
// These wizard tests are disabled due to errors with disposable objects
|
||||
//
|
||||
// it('Start wizard test', async () => {
|
||||
// let wizard = new ConfigurePythonWizard(apiWrapper, testInstallation);
|
||||
// let wizard = new ConfigurePythonWizard(testInstallation);
|
||||
// await wizard.start();
|
||||
// await wizard.close();
|
||||
// await should(wizard.setupComplete).be.resolved();
|
||||
// });
|
||||
|
||||
// it('Reject setup on cancel test', async () => {
|
||||
// let wizard = new ConfigurePythonWizard(apiWrapper, testInstallation);
|
||||
// let wizard = new ConfigurePythonWizard(testInstallation);
|
||||
// await wizard.start(undefined, true);
|
||||
// await wizard.close();
|
||||
// await should(wizard.setupComplete).be.rejected();
|
||||
// });
|
||||
|
||||
// it('Error message test', async () => {
|
||||
// let wizard = new ConfigurePythonWizard(apiWrapper, testInstallation);
|
||||
// let wizard = new ConfigurePythonWizard(testInstallation);
|
||||
// await wizard.start();
|
||||
|
||||
// should(wizard.wizard.message).be.undefined();
|
||||
@@ -86,7 +84,7 @@ describe('Configure Python Wizard', function () {
|
||||
};
|
||||
|
||||
let page = azdata.window.createWizardPage('Page 1');
|
||||
let configurePathPage = new ConfigurePathPage(apiWrapper, testWizard, page, model, viewContext.view);
|
||||
let configurePathPage = new ConfigurePathPage(testWizard, page, model, viewContext.view);
|
||||
|
||||
should(await configurePathPage.initialize()).be.true();
|
||||
|
||||
@@ -108,7 +106,7 @@ describe('Configure Python Wizard', function () {
|
||||
};
|
||||
|
||||
let page = azdata.window.createWizardPage('Page 2');
|
||||
let pickPackagesPage = new PickPackagesPage(apiWrapper, testWizard, page, model, viewContext.view);
|
||||
let pickPackagesPage = new PickPackagesPage(testWizard, page, model, viewContext.view);
|
||||
|
||||
should(await pickPackagesPage.initialize()).be.true();
|
||||
|
||||
@@ -132,7 +130,7 @@ describe('Configure Python Wizard', function () {
|
||||
};
|
||||
|
||||
let page = azdata.window.createWizardPage('Page 2');
|
||||
let pickPackagesPage = new PickPackagesPage(apiWrapper, testWizard, page, model, viewContext.view);
|
||||
let pickPackagesPage = new PickPackagesPage(testWizard, page, model, viewContext.view);
|
||||
|
||||
should(await pickPackagesPage.initialize()).be.true();
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as should from 'should';
|
||||
import { ManagePackagesDialog } from '../../dialog/managePackages/managePackagesDialog';
|
||||
import { ManagePackagesDialogModel } from '../../dialog/managePackages/managePackagesDialogModel';
|
||||
import { IPackageManageProvider, IPackageLocation } from '../../types';
|
||||
import { LocalCondaPackageManageProvider } from '../../jupyter/localCondaPackageManageProvider';
|
||||
import { InstalledPackagesTab } from '../../dialog/managePackages/installedPackagesTab';
|
||||
import should = require('should');
|
||||
|
||||
interface TestContext {
|
||||
view: azdata.ModelView;
|
||||
|
||||
@@ -19,7 +19,7 @@ interface TestContext {
|
||||
describe('Manage Packages', () => {
|
||||
let jupyterServerInstallation: JupyterServerInstallation;
|
||||
beforeEach(() => {
|
||||
jupyterServerInstallation = new JupyterServerInstallation(undefined, undefined, undefined);
|
||||
jupyterServerInstallation = new JupyterServerInstallation(undefined, undefined);
|
||||
});
|
||||
|
||||
it('Should throw exception given undefined providers', async function (): Promise<void> {
|
||||
|
||||
@@ -11,7 +11,6 @@ import * as TypeMoq from 'typemoq';
|
||||
import { NotebookCompletionItemProvider } from '../../intellisense/completionItemProvider';
|
||||
import { JupyterNotebookProvider } from '../../jupyter/jupyterNotebookProvider';
|
||||
import { NotebookUtils } from '../../common/notebookUtils';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { JupyterNotebookManager } from '../../jupyter/jupyterNotebookManager';
|
||||
import { JupyterSessionManager, JupyterSession } from '../../jupyter/jupyterSessionManager';
|
||||
import { LocalJupyterServerManager } from '../../jupyter/jupyterServerManager';
|
||||
@@ -22,7 +21,6 @@ describe('Completion Item Provider', function () {
|
||||
let notebookProviderMock: TypeMoq.IMock<JupyterNotebookProvider>;
|
||||
let notebookUtils: NotebookUtils;
|
||||
let notebookManager: JupyterNotebookManager;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockSessionManager: TypeMoq.IMock<JupyterSessionManager>;
|
||||
let mockServerManager: TypeMoq.IMock<LocalJupyterServerManager>;
|
||||
let mockJupyterSession: TypeMoq.IMock<JupyterSession>;
|
||||
@@ -31,8 +29,7 @@ describe('Completion Item Provider', function () {
|
||||
let token: vscode.CancellationToken;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
notebookUtils = new NotebookUtils(new ApiWrapper());
|
||||
notebookUtils = new NotebookUtils();
|
||||
mockServerManager = TypeMoq.Mock.ofType<LocalJupyterServerManager>();
|
||||
testEvent = new vscode.EventEmitter();
|
||||
token = {
|
||||
@@ -47,7 +44,7 @@ describe('Completion Item Provider', function () {
|
||||
mockSessionManager = TypeMoq.Mock.ofType<JupyterSessionManager>();
|
||||
mockJupyterSession = TypeMoq.Mock.ofType<JupyterSession>();
|
||||
kernel = new TestKernel(true, true);
|
||||
notebookManager = new JupyterNotebookManager(mockServerManager.object, mockSessionManager.object, mockApiWrapper.object);
|
||||
notebookManager = new JupyterNotebookManager(mockServerManager.object, mockSessionManager.object);
|
||||
notebookProviderMock = TypeMoq.Mock.ofType<JupyterNotebookProvider>();
|
||||
notebookProviderMock.setup(n => n.getNotebookManager(TypeMoq.It.isAny())).returns(() => Promise.resolve(notebookManager));
|
||||
completionItemProvider = new NotebookCompletionItemProvider(notebookProviderMock.object);
|
||||
|
||||
@@ -7,8 +7,8 @@ import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { AppContext } from '../../common/appContext';
|
||||
import { JupyterController } from '../../jupyter/jupyterController';
|
||||
import { LocalPipPackageManageProvider } from '../../jupyter/localPipPackageManageProvider';
|
||||
@@ -16,24 +16,24 @@ import { MockExtensionContext } from '../common/stubs';
|
||||
import { NotebookUtils } from '../../common/notebookUtils';
|
||||
|
||||
describe('Jupyter Controller', function () {
|
||||
let mockExtensionContext: vscode.ExtensionContext;
|
||||
let appContext: AppContext;
|
||||
let mockExtensionContext: vscode.ExtensionContext = new MockExtensionContext();
|
||||
let appContext = new AppContext(mockExtensionContext);
|
||||
let controller: JupyterController;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let connection: azdata.connection.ConnectionProfile;
|
||||
|
||||
this.beforeAll(() => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
connection = new azdata.connection.ConnectionProfile();
|
||||
});
|
||||
let connection: azdata.connection.ConnectionProfile = new azdata.connection.ConnectionProfile();
|
||||
let showErrorMessageSpy: sinon.SinonSpy;
|
||||
|
||||
this.beforeEach(() => {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockApiWrapper.setup(x => x.getCurrentConnection()).returns(() => { return Promise.resolve(connection); });
|
||||
appContext = new AppContext(mockExtensionContext, mockApiWrapper.object);
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
sinon.stub(azdata.connection, 'getCurrentConnection').returns(Promise.resolve(connection));
|
||||
sinon.stub(azdata.tasks, 'registerTask');
|
||||
sinon.stub(vscode.commands, 'registerCommand');
|
||||
controller = new JupyterController(appContext);
|
||||
});
|
||||
|
||||
this.afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('should activate new JupyterController successfully', async () => {
|
||||
should(controller.extensionContext).deepEqual(appContext.extensionContext, 'Extension context should be passed through');
|
||||
should(controller.jupyterInstallation).equal(undefined, 'JupyterInstallation should be undefined before controller activation');
|
||||
@@ -65,13 +65,13 @@ describe('Jupyter Controller', function () {
|
||||
|
||||
it('should show error message for doManagePackages before activation', async () => {
|
||||
await controller.doManagePackages();
|
||||
mockApiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called');
|
||||
});
|
||||
|
||||
it('should not show error message for doManagePackages after activation', async () => {
|
||||
await controller.activate();
|
||||
await controller.doManagePackages();
|
||||
mockApiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not be called');
|
||||
});
|
||||
|
||||
it('Returns expected values from notebook provider', async () => {
|
||||
@@ -85,7 +85,7 @@ describe('Jupyter Controller', function () {
|
||||
|
||||
it('Returns notebook manager for real notebook editor', async () => {
|
||||
await controller.activate();
|
||||
let notebookUtils = new NotebookUtils(mockApiWrapper.object);
|
||||
let notebookUtils = new NotebookUtils();
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
let notebookManager = await controller.notebookProvider.getNotebookManager(notebookEditor.document.uri);
|
||||
should(controller.notebookProvider.notebookManagerCount).equal(1);
|
||||
|
||||
@@ -12,7 +12,6 @@ import 'mocha';
|
||||
import { LocalJupyterServerManager, ServerInstanceFactory, IServerManagerOptions } from '../../jupyter/jupyterServerManager';
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
import { JupyterSessionManager } from '../../jupyter/jupyterSessionManager';
|
||||
import { JupyterNotebookManager } from '../../jupyter/jupyterNotebookManager';
|
||||
@@ -28,15 +27,11 @@ describe('Jupyter Notebook Manager', function (): void {
|
||||
let sessionManager: JupyterSessionManager;
|
||||
let notebookManager: JupyterNotebookManager;
|
||||
let deferredInstall: Deferred<void>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockExtensionContext: MockExtensionContext;
|
||||
let mockFactory: TypeMoq.IMock<ServerInstanceFactory>;
|
||||
let serverManagerOptions: IServerManagerOptions;
|
||||
beforeEach(() => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper);
|
||||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny()));
|
||||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined);
|
||||
mockFactory = TypeMoq.Mock.ofType(ServerInstanceFactory);
|
||||
|
||||
deferredInstall = new Deferred<void>();
|
||||
@@ -48,7 +43,6 @@ describe('Jupyter Notebook Manager', function (): void {
|
||||
documentPath: expectedPath,
|
||||
jupyterInstallation: mockInstall.object,
|
||||
extensionContext: mockExtensionContext,
|
||||
apiWrapper: mockApiWrapper.object,
|
||||
factory: mockFactory.object
|
||||
};
|
||||
serverManager = new LocalJupyterServerManager(serverManagerOptions);
|
||||
@@ -90,7 +84,7 @@ describe('Jupyter Notebook Manager', function (): void {
|
||||
it('Session and server managers should be shutdown/stopped on dispose', async function(): Promise<void> {
|
||||
let sessionManager = TypeMoq.Mock.ofType<JupyterSessionManager>();
|
||||
let serverManager = TypeMoq.Mock.ofType<LocalJupyterServerManager>();
|
||||
notebookManager = new JupyterNotebookManager(serverManager.object, sessionManager.object, mockApiWrapper.object);
|
||||
notebookManager = new JupyterNotebookManager(serverManager.object, sessionManager.object);
|
||||
sessionManager.setup(s => s.shutdownAll()).returns(() => new Promise((resolve) => resolve()));
|
||||
serverManager.setup(s => s.stopServer()).returns(() => new Promise((resolve) => resolve()));
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { ChildProcess } from 'child_process';
|
||||
import 'mocha';
|
||||
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { ApiWrapper } from '../..//common/apiWrapper';
|
||||
import { PerFolderServerInstance, ServerInstanceUtils } from '../../jupyter/serverInstance';
|
||||
import { MockOutputChannel } from '../common/stubs';
|
||||
import * as testUtils from '../common/testUtils';
|
||||
@@ -25,14 +24,10 @@ describe('Jupyter server instance', function (): void {
|
||||
let expectedPath = 'mydir/notebook.ipynb';
|
||||
let mockInstall: TypeMoq.IMock<JupyterServerInstallation>;
|
||||
let mockOutputChannel: TypeMoq.IMock<MockOutputChannel>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockUtils: TypeMoq.IMock<ServerInstanceUtils>;
|
||||
let serverInstance: PerFolderServerInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper);
|
||||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny()));
|
||||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined);
|
||||
mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation, undefined, undefined, '/root');
|
||||
mockOutputChannel = TypeMoq.Mock.ofType(MockOutputChannel);
|
||||
mockInstall.setup(i => i.outputChannel).returns(() => mockOutputChannel.object);
|
||||
|
||||
@@ -13,7 +13,6 @@ import { JupyterServerInstanceStub } from '../common';
|
||||
import { LocalJupyterServerManager, ServerInstanceFactory } from '../../jupyter/jupyterServerManager';
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import * as testUtils from '../common/testUtils';
|
||||
import { IServerInstance } from '../../jupyter/common';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
@@ -26,14 +25,10 @@ describe('Local Jupyter Server Manager', function (): void {
|
||||
let expectedPath = 'my/notebook.ipynb';
|
||||
let serverManager: LocalJupyterServerManager;
|
||||
let deferredInstall: Deferred<void>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockExtensionContext: MockExtensionContext;
|
||||
let mockFactory: TypeMoq.IMock<ServerInstanceFactory>;
|
||||
beforeEach(() => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper);
|
||||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny()));
|
||||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined);
|
||||
mockFactory = TypeMoq.Mock.ofType(ServerInstanceFactory);
|
||||
|
||||
deferredInstall = new Deferred<void>();
|
||||
@@ -45,7 +40,6 @@ describe('Local Jupyter Server Manager', function (): void {
|
||||
documentPath: expectedPath,
|
||||
jupyterInstallation: mockInstall.object,
|
||||
extensionContext: mockExtensionContext,
|
||||
apiWrapper: mockApiWrapper.object,
|
||||
factory: mockFactory.object
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user