mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-10 10:12:34 -05:00
110
extensions/machine-learning/src/test/common/config.test.ts
Normal file
110
extensions/machine-learning/src/test/common/config.test.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { ApiWrapper } from '../../common/apiWrapper';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as should from 'should';
|
||||
import { Config } from '../../configurations/config';
|
||||
import * as utils from '../../common/utils';
|
||||
import * as path from 'path';
|
||||
|
||||
interface TestContext {
|
||||
|
||||
apiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
}
|
||||
|
||||
function createContext(): TestContext {
|
||||
return {
|
||||
apiWrapper: TypeMoq.Mock.ofType(ApiWrapper)
|
||||
};
|
||||
}
|
||||
|
||||
let configData : vscode.WorkspaceConfiguration = {
|
||||
get: () => {},
|
||||
has: () => true,
|
||||
inspect: () => undefined,
|
||||
update: () => {return Promise.resolve();},
|
||||
|
||||
};
|
||||
|
||||
describe('Config', () => {
|
||||
it('getPythonExecutable should default to ADS python location is not configured', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return ''; };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
const expected = utils.getDefaultPythonLocation();
|
||||
const actual = await config.getPythonExecutable(false);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('getPythonExecutable should add python executable name is folder path is configured', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return utils.getUserHome(); };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
const expected = path.join(utils.getUserHome() || '', utils.getPythonExeName());
|
||||
const actual = await config.getPythonExecutable(false);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('getPythonExecutable should not add python executable if already added', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return path.join(utils.getUserHome() || '', utils.getPythonExeName()); };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
const expected = path.join(utils.getUserHome() || '', utils.getPythonExeName());
|
||||
const actual = await config.getPythonExecutable(false);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('getPythonExecutable should not add python executable set to python', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return 'python'; };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
const expected = 'python';
|
||||
const actual = await config.getPythonExecutable(false);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('getPythonExecutable should not add python executable set to python3', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return 'python3'; };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
const expected = 'python3';
|
||||
const actual = await config.getPythonExecutable(false);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('getRExecutable should not add r executable set to r', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return 'r'; };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
const expected = 'r';
|
||||
const actual = await config.getRExecutable(false);
|
||||
should.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('getPythonExecutable should throw error if file does not exist', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return path.join(utils.getUserHome() || '', 'invalidPath'); };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
await should(config.getPythonExecutable(true)).be.rejected();
|
||||
});
|
||||
|
||||
it('getRExecutable should throw error if file does not exist', async function (): Promise<void> {
|
||||
const context = createContext();
|
||||
configData.get = () => { return path.join(utils.getUserHome() || '', 'invalidPath'); };
|
||||
context.apiWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny())).returns(() => configData);
|
||||
let config = new Config('', context.apiWrapper.object);
|
||||
await should(config.getRExecutable(true)).be.rejected();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -53,7 +53,7 @@ describe('ModelPythonClient', () => {
|
||||
testContext.apiWrapper.setup(x => x.startBackgroundOperation(TypeMoq.It.isAny())).returns((operationInfo: azdata.BackgroundOperationInfo) => {
|
||||
operationInfo.operation(testContext.op);
|
||||
});
|
||||
testContext.config.setup(x => x.pythonExecutable).returns(() => 'pythonPath');
|
||||
testContext.config.setup(x => x.getPythonExecutable(true)).returns(() => Promise.resolve('pythonPath'));
|
||||
testContext.processService.setup(x => x.execScripts(TypeMoq.It.isAny(), TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(''));
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('ModelPythonClient', () => {
|
||||
testContext.config.object,
|
||||
testContext.packageManager.object);
|
||||
testContext.packageManager.setup(x => x.installRequiredPythonPackages(TypeMoq.It.isAny())).returns(() => Promise.resolve());
|
||||
testContext.config.setup(x => x.pythonExecutable).returns(() => 'pythonPath');
|
||||
testContext.config.setup(x => x.getPythonExecutable(true)).returns(() => Promise.resolve('pythonPath'));
|
||||
testContext.processService.setup(x => x.execScripts(TypeMoq.It.isAny(), TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(parametersJson));
|
||||
testContext.apiWrapper.setup(x => x.startBackgroundOperation(TypeMoq.It.isAny())).returns((operationInfo: azdata.BackgroundOperationInfo) => {
|
||||
|
||||
@@ -254,8 +254,8 @@ describe('Package Manager', () => {
|
||||
{ name: 'sqlmlutils', fileName: 'sqlmlutils_0.7.1.zip', downloadUrl: 'https://github.com/microsoft/sqlmlutils/blob/master/R/dist/sqlmlutils_0.7.1.zip?raw=true'}
|
||||
]);
|
||||
testContext.httpClient.setup(x => x.download(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve());
|
||||
testContext.config.setup(x => x.pythonExecutable).returns(() => 'python');
|
||||
testContext.config.setup(x => x.rExecutable).returns(() => 'r');
|
||||
testContext.config.setup(x => x.getPythonExecutable(true)).returns(() => Promise.resolve('python'));
|
||||
testContext.config.setup(x => x.getRExecutable(true)).returns(() => Promise.resolve('r'));
|
||||
testContext.config.setup(x => x.rEnabled).returns(() => true);
|
||||
testContext.config.setup(x => x.pythonEnabled).returns(() => true);
|
||||
let packageManager = new PackageManager(
|
||||
|
||||
@@ -386,7 +386,7 @@ describe('SQL Python Package Manager', () => {
|
||||
});
|
||||
|
||||
function createProvider(testContext: TestContext): SqlPythonPackageManageProvider {
|
||||
testContext.config.setup(x => x.pythonExecutable).returns(() => 'python');
|
||||
testContext.config.setup(x => x.getPythonExecutable(true)).returns(() => Promise.resolve('python'));
|
||||
testContext.config.setup(x => x.pythonEnabled).returns(() => true);
|
||||
return new SqlPythonPackageManageProvider(
|
||||
testContext.outputChannel,
|
||||
|
||||
@@ -311,7 +311,7 @@ describe('SQL R Package Manager', () => {
|
||||
});
|
||||
|
||||
function createProvider(testContext: TestContext): SqlRPackageManageProvider {
|
||||
testContext.config.setup(x => x.rExecutable).returns(() => 'r');
|
||||
testContext.config.setup(x => x.getRExecutable(true)).returns(() => Promise.resolve('r'));
|
||||
testContext.config.setup(x => x.rEnabled).returns(() => true);
|
||||
testContext.config.setup(x => x.rPackagesRepository).returns(() => 'http://cran.r-project.org');
|
||||
return new SqlRPackageManageProvider(
|
||||
|
||||
@@ -39,10 +39,12 @@ describe('Dashboard widget', () => {
|
||||
await handler(testContext.view);
|
||||
});
|
||||
|
||||
testContext.apiWrapper.setup(x => x.openExternal(TypeMoq.It.isAny())).returns(() => Promise.resolve(true));
|
||||
|
||||
testContext.predictService.setup(x => x.serverSupportOnnxModel()).returns(() => Promise.resolve(true));
|
||||
const dashboard = new DashboardWidget(testContext.apiWrapper.object, '', testContext.predictService.object);
|
||||
await dashboard.register();
|
||||
testContext.onClick.fire(undefined);
|
||||
testContext.apiWrapper.verify(x => x.executeCommand(TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
||||
testContext.apiWrapper.verify(x => x.openExternal(TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user