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:
Cory Rivera
2021-03-08 18:05:10 -08:00
committed by GitHub
parent bbdc324f17
commit e2a5859155
6 changed files with 245 additions and 16 deletions

View File

@@ -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 () => {