mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-08 04:18:19 +02:00
Add and configure ESLint and update configuration for Prettier (#617)
* Add ESLint, update Prettier * Update docs * Update tests * Update licenses * Fix review points
This commit is contained in:
parent
7b9ef6fc5a
commit
ec365b4eba
36 changed files with 3733 additions and 505 deletions
|
@ -5,7 +5,6 @@ import * as exec from '@actions/exec';
|
|||
import * as io from '@actions/io';
|
||||
import {getCacheDistributor} from '../src/cache-distributions/cache-factory';
|
||||
import {State} from '../src/cache-distributions/cache-distributor';
|
||||
import * as constants from '../src/cache-distributions/constants';
|
||||
|
||||
describe('restore-cache', () => {
|
||||
const pipFileLockHash =
|
||||
|
@ -95,7 +94,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
|||
async packageManager => {
|
||||
expect(() =>
|
||||
getCacheDistributor(packageManager, '3.8.12', undefined)
|
||||
).toThrowError(`Caching for '${packageManager}' is not supported`);
|
||||
).toThrow(`Caching for '${packageManager}' is not supported`);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -210,7 +209,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
|||
dependencyFile
|
||||
);
|
||||
|
||||
await expect(cacheDistributor.restoreCache()).rejects.toThrowError(
|
||||
await expect(cacheDistributor.restoreCache()).rejects.toThrow(
|
||||
`No file in ${process.cwd()} matched to [${cacheDependencyPath
|
||||
.split('\n')
|
||||
.join(',')}], make sure you have checked out the target repository`
|
||||
|
@ -229,7 +228,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
|||
pythonVersion,
|
||||
dependencyFile
|
||||
);
|
||||
await expect(cacheDistributor.restoreCache()).resolves;
|
||||
await expect(cacheDistributor.restoreCache()).resolves.not.toThrow();
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -239,16 +238,15 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
|
|||
])(
|
||||
'Should throw an error as there is no default file `pyproject.toml` to use when requirements.txt is not specified',
|
||||
async (packageManager, pythonVersion, dependencyFile) => {
|
||||
jest.mock('../src/cache-distributions/constants', () => ({
|
||||
CACHE_DEPENDENCY_BACKUP_PATH: '**/pyprojecttest.toml'
|
||||
}));
|
||||
|
||||
const cacheDistributor = getCacheDistributor(
|
||||
packageManager,
|
||||
pythonVersion,
|
||||
dependencyFile
|
||||
);
|
||||
await expect(cacheDistributor.restoreCache()).resolves;
|
||||
) as any; // Widening PipCache | PipenvCache | PoetryCache type to any allow us to change private property on the cacheDistributor to test value: "**/pyprojecttest.toml"
|
||||
|
||||
cacheDistributor.cacheDependencyBackupPath = '**/pyprojecttest.toml';
|
||||
|
||||
await expect(cacheDistributor.restoreCache()).rejects.toThrow();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -116,22 +116,6 @@ describe('run', () => {
|
|||
);
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not save cache for pipenv', async () => {
|
||||
inputs['cache'] = 'pipenv';
|
||||
|
||||
await run();
|
||||
|
||||
expect(getInputSpy).toHaveBeenCalled();
|
||||
expect(debugSpy).toHaveBeenCalledWith(
|
||||
`paths for caching are ${__dirname}`
|
||||
);
|
||||
expect(getStateSpy).toHaveBeenCalledTimes(3);
|
||||
expect(infoSpy).toHaveBeenCalledWith(
|
||||
`Cache hit occurred on the primary key ${requirementsHash}, not saving cache.`
|
||||
);
|
||||
expect(setFailedSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('action saves the cache', () => {
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
getPyPyVersionFromPath
|
||||
} from '../src/utils';
|
||||
|
||||
const manifestData = require('./data/pypy.json');
|
||||
import manifestData from './data/pypy.json';
|
||||
|
||||
let architecture: string;
|
||||
|
||||
|
@ -51,7 +51,7 @@ describe('parsePyPyVersion', () => {
|
|||
it.each(['', 'pypy-', 'pypy', 'p', 'notpypy-'])(
|
||||
'throw on invalid input "%s"',
|
||||
input => {
|
||||
expect(() => finder.parsePyPyVersion(input)).toThrowError(
|
||||
expect(() => finder.parsePyPyVersion(input)).toThrow(
|
||||
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy<python-version>' or 'pypy-<python-version>'. See README for examples and documentation."
|
||||
);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ describe('parsePyPyVersion', () => {
|
|||
it.each(['pypy-2', 'pypy-3', 'pypy2', 'pypy3', 'pypy3.x', 'pypy3.8.10'])(
|
||||
'throw on invalid input "%s"',
|
||||
input => {
|
||||
expect(() => finder.parsePyPyVersion(input)).toThrowError(
|
||||
expect(() => finder.parsePyPyVersion(input)).toThrow(
|
||||
"Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation."
|
||||
);
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ describe('findPyPyVersion', () => {
|
|||
false,
|
||||
false
|
||||
)
|
||||
).rejects.toThrowError(
|
||||
).rejects.toThrow(
|
||||
`PyPy version 3.7 (v7.5.x) with arch ${architecture} not found`
|
||||
);
|
||||
});
|
||||
|
@ -453,7 +453,7 @@ describe('findPyPyVersion', () => {
|
|||
spyChmodSync.mockImplementation(() => undefined);
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy3.8', architecture, false, false, false)
|
||||
).rejects.toThrowError();
|
||||
).rejects.toThrow();
|
||||
await expect(
|
||||
finder.findPyPyVersion('pypy3.8', architecture, false, false, true)
|
||||
).resolves.toEqual({
|
||||
|
|
|
@ -24,7 +24,7 @@ import * as core from '@actions/core';
|
|||
import * as finder from '../src/find-python';
|
||||
import * as installer from '../src/install-python';
|
||||
|
||||
const manifestData = require('./data/versions-manifest.json');
|
||||
import manifestData from './data/versions-manifest.json';
|
||||
|
||||
describe('Finder tests', () => {
|
||||
let writeSpy: jest.SpyInstance;
|
||||
|
@ -192,7 +192,7 @@ describe('Finder tests', () => {
|
|||
expect(infoSpy).toHaveBeenCalledWith(
|
||||
'Version 1.2.3 was not found in the local cache'
|
||||
);
|
||||
expect(infoSpy).toBeCalledWith(
|
||||
expect(infoSpy).toHaveBeenCalledWith(
|
||||
'Version 1.2.3 is available for downloading'
|
||||
);
|
||||
expect(installSpy).toHaveBeenCalled();
|
||||
|
@ -252,7 +252,7 @@ describe('Finder tests', () => {
|
|||
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
|
||||
await expect(
|
||||
finder.useCpythonVersion('1.1', 'x64', false, false, false)
|
||||
).rejects.toThrowError();
|
||||
).rejects.toThrow();
|
||||
await expect(
|
||||
finder.useCpythonVersion('1.1', 'x64', false, false, true)
|
||||
).resolves.toEqual({
|
||||
|
@ -262,7 +262,7 @@ describe('Finder tests', () => {
|
|||
// Check 1.1.0 version specifier does not fallback to '1.1.0-beta.2'
|
||||
await expect(
|
||||
finder.useCpythonVersion('1.1.0', 'x64', false, false, true)
|
||||
).rejects.toThrowError();
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('Errors if Python is not installed', async () => {
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
IS_WINDOWS
|
||||
} from '../src/utils';
|
||||
|
||||
const manifestData = require('./data/pypy.json');
|
||||
import manifestData from './data/pypy.json';
|
||||
|
||||
let architecture: string;
|
||||
if (IS_WINDOWS) {
|
||||
|
@ -294,7 +294,7 @@ describe('installPyPy', () => {
|
|||
it('throw if release is not found', async () => {
|
||||
await expect(
|
||||
installer.installPyPy('7.3.3', '3.6.17', architecture, false, undefined)
|
||||
).rejects.toThrowError(
|
||||
).rejects.toThrow(
|
||||
`PyPy version 3.6.17 (7.3.3) with arch ${architecture} not found`
|
||||
);
|
||||
|
||||
|
@ -338,7 +338,7 @@ describe('installPyPy', () => {
|
|||
|
||||
await expect(
|
||||
installer.installPyPy('7.4.x', '3.6.12', architecture, false, undefined)
|
||||
).rejects.toThrowError();
|
||||
).rejects.toThrow();
|
||||
await expect(
|
||||
installer.installPyPy('7.4.x', '3.6.12', architecture, true, undefined)
|
||||
).resolves.toEqual({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue