mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Only include package versions in Manage Packages dialog if they're supported for the user's version of Python (#14584)
This commit is contained in:
@@ -78,6 +78,22 @@ describe('Utils Tests', function () {
|
||||
it('correctly compares version with only minor version difference', () => {
|
||||
should(utils.comparePackageVersions(version1Revision, version1)).equal(1);
|
||||
});
|
||||
|
||||
it('equivalent versions with wildcard characters', () => {
|
||||
should(utils.comparePackageVersions('1.*.3', '1.5.3')).equal(0);
|
||||
});
|
||||
|
||||
it('lower version with wildcard characters', () => {
|
||||
should(utils.comparePackageVersions('1.4.*', '1.5.3')).equal(-1);
|
||||
});
|
||||
|
||||
it('higher version with wildcard characters', () => {
|
||||
should(utils.comparePackageVersions('4.5.6', '3.*')).equal(1);
|
||||
});
|
||||
|
||||
it('all wildcard strings should be equal', () => {
|
||||
should(utils.comparePackageVersions('*.*', '*.*.*')).equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sortPackageVersions', () => {
|
||||
@@ -139,6 +155,103 @@ describe('Utils Tests', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPackageSupported', () => {
|
||||
it('Constraints have no version specifier', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['3.6.*', '3.*'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
|
||||
versionConstraints = ['3.5.*', '3.5'];
|
||||
result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.false();
|
||||
});
|
||||
|
||||
it('Package is valid for version constraints', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['>=3.5,!=3.2,!=3.4.*'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Version constraints string has lots of spaces', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['>= 3.5, != 3.2, != 3.4.*'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Strictly greater or less than comparisons', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['> 3.5, > 3.4.*', '< 3.8'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Strict equality', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['== 3.6', '== 3.6.*'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Package is valid for first set of constraints, but not the second', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['>=3.5, !=3.2, !=3.4.*', '!=3.6, >=3.5'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Package is valid for second set of constraints, but not the first', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['!=3.6, >=3.5', '>=3.5, !=3.2, !=3.4.*'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Package is not valid for constraints', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['>=3.4, !=3.6, >=3.5'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.false();
|
||||
});
|
||||
|
||||
it('Package is not valid for several sets of constraints', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['>=3.7', '!=3.6, >=3.5', '>=3.8'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.false();
|
||||
});
|
||||
|
||||
it('Constraints are all empty strings', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints = ['', '', ''];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Constraints are all undefined', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints: string[] = [undefined, undefined, undefined];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Constraints are a bunch of commas', async function (): Promise<void> {
|
||||
let pythonVersion = '3.6';
|
||||
let versionConstraints: string[] = [',,,', ',,,,', ', , , , , , ,'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
|
||||
it('Installed python version is an empty string', async function (): Promise<void> {
|
||||
let pythonVersion = '';
|
||||
let versionConstraints = ['>=3.7', '!=3.6, >=3.5', '>=3.8'];
|
||||
let result = await utils.isPackageSupported(pythonVersion, versionConstraints);
|
||||
should(result).be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe('executeBufferedCommand', () => {
|
||||
|
||||
it('runs successfully', async () => {
|
||||
|
||||
@@ -14,7 +14,7 @@ import { IPyPiClient, PyPiClient } from '../../jupyter/pypiClient';
|
||||
|
||||
interface TestContext {
|
||||
serverInstallation: IJupyterServerInstallation;
|
||||
piPyClient: IPyPiClient;
|
||||
pyPiClient: IPyPiClient;
|
||||
}
|
||||
|
||||
describe('Manage Package Providers', () => {
|
||||
@@ -29,7 +29,7 @@ describe('Manage Package Providers', () => {
|
||||
it('Pip should return valid package target', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
let serverInstallation = createJupyterServerInstallation(testContext);
|
||||
let client = createPipyClient(testContext);
|
||||
let client = createPypiClient(testContext);
|
||||
let provider = new LocalPipPackageManageProvider(serverInstallation.object, client.object);
|
||||
should.deepEqual(provider.packageTarget, { location: constants.localhostName, packageType: constants.PythonPkgType.Pip });
|
||||
});
|
||||
@@ -46,7 +46,7 @@ describe('Manage Package Providers', () => {
|
||||
return Promise.resolve(packages);
|
||||
};
|
||||
let serverInstallation = createJupyterServerInstallation(testContext);
|
||||
let client = createPipyClient(testContext);
|
||||
let client = createPypiClient(testContext);
|
||||
let provider = new LocalPipPackageManageProvider(serverInstallation.object, client.object);
|
||||
|
||||
should.deepEqual(await provider.listPackages(), packages);
|
||||
@@ -79,7 +79,7 @@ describe('Manage Package Providers', () => {
|
||||
];
|
||||
let testContext = createContext();
|
||||
let serverInstallation = createJupyterServerInstallation(testContext);
|
||||
let client = createPipyClient(testContext);
|
||||
let client = createPypiClient(testContext);
|
||||
let provider = new LocalPipPackageManageProvider(serverInstallation.object, client.object);
|
||||
|
||||
await provider.installPackages(packages, true);
|
||||
@@ -110,7 +110,7 @@ describe('Manage Package Providers', () => {
|
||||
];
|
||||
let testContext = createContext();
|
||||
let serverInstallation = createJupyterServerInstallation(testContext);
|
||||
let client = createPipyClient(testContext);
|
||||
let client = createPypiClient(testContext);
|
||||
let provider = new LocalPipPackageManageProvider(serverInstallation.object, client.object);
|
||||
|
||||
await provider.uninstallPackages(packages);
|
||||
@@ -143,7 +143,7 @@ describe('Manage Package Providers', () => {
|
||||
it('Pip canUseProvider should return true', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
let serverInstallation = createJupyterServerInstallation(testContext);
|
||||
let client = createPipyClient(testContext);
|
||||
let client = createPypiClient(testContext);
|
||||
let provider = new LocalPipPackageManageProvider(serverInstallation.object, client.object);
|
||||
|
||||
should.equal(await provider.canUseProvider(), true);
|
||||
@@ -151,11 +151,11 @@ describe('Manage Package Providers', () => {
|
||||
|
||||
it('Pip getPackageOverview should return package info successfully', async function (): Promise<void> {
|
||||
let testContext = createContext();
|
||||
testContext.piPyClient.fetchPypiPackage = (packageName) => {
|
||||
testContext.pyPiClient.fetchPypiPackage = (packageName) => {
|
||||
return Promise.resolve(`{"info":{"summary":"package summary"}, "releases":{"0.0.1":[{"comment_text":""}], "0.0.2":[{"comment_text":""}]}}`);
|
||||
};
|
||||
let serverInstallation = createJupyterServerInstallation(testContext);
|
||||
let client = createPipyClient(testContext);
|
||||
let client = createPypiClient(testContext);
|
||||
let provider = new LocalPipPackageManageProvider(serverInstallation.object, client.object);
|
||||
|
||||
await should(provider.getPackageOverview('name')).resolvedWith({
|
||||
@@ -215,9 +215,10 @@ describe('Manage Package Providers', () => {
|
||||
getCondaExePath: () => { return ''; },
|
||||
pythonExecutable: '',
|
||||
pythonInstallationPath: '',
|
||||
usingConda: false
|
||||
usingConda: false,
|
||||
installedPythonVersion: '',
|
||||
},
|
||||
piPyClient: {
|
||||
pyPiClient: {
|
||||
fetchPypiPackage: (packageName) => { return Promise.resolve(); }
|
||||
}
|
||||
};
|
||||
@@ -236,10 +237,10 @@ describe('Manage Package Providers', () => {
|
||||
return mockInstance;
|
||||
}
|
||||
|
||||
function createPipyClient(testContext: TestContext): TypeMoq.IMock<IPyPiClient> {
|
||||
function createPypiClient(testContext: TestContext): TypeMoq.IMock<IPyPiClient> {
|
||||
let mockInstance = TypeMoq.Mock.ofType(PyPiClient);
|
||||
mockInstance.setup(x => x.fetchPypiPackage(TypeMoq.It.isAny())).returns((packageName) =>
|
||||
testContext.piPyClient.fetchPypiPackage(packageName));
|
||||
testContext.pyPiClient.fetchPypiPackage(packageName));
|
||||
return mockInstance;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user