mirror of
https://github.com/actions/setup-python
synced 2025-04-05 06:49:43 +00:00
Add support for .tool-versions file in setup-python (#1043)
* add support for .tool-versions file * update regex * optimize code * update test-python.yml for .tool-versions * fix format-check errors * fix formatting in test-python.yml * Fix test-python.yml error * workflow update with latest versions * update test cases * fix lint issue
This commit is contained in:
@ -15,7 +15,8 @@ import {
|
||||
getNextPageUrl,
|
||||
isGhes,
|
||||
IS_WINDOWS,
|
||||
getDownloadFileName
|
||||
getDownloadFileName,
|
||||
getVersionInputFromToolVersions
|
||||
} from '../src/utils';
|
||||
|
||||
jest.mock('@actions/cache');
|
||||
@ -139,6 +140,82 @@ describe('Version from file test', () => {
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([]);
|
||||
}
|
||||
);
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python 3.9.10\nnodejs 16';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.9.10']);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions with comment',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = '# python 3.8\npython 3.9';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.9']);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions with whitespace',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = ' python 3.10 ';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.10']);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions with v prefix',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python v3.9.10';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.9.10']);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions with pypy version',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python pypy3.10-7.3.14';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['pypy3.10-7.3.14']);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions with alpha Releases',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python 3.14.0a5t';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.14.0a5t']);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([getVersionInputFromToolVersions])(
|
||||
'Version from .tool-versions with dev suffix',
|
||||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python 3.14t-dev';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.14t-dev']);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('getNextPageUrl', () => {
|
||||
|
Reference in New Issue
Block a user