1
0
Fork 0
mirror of https://github.com/actions/setup-python.git synced 2024-11-25 18:07:44 +00:00
setup-python/__tests__/finder.test.ts

71 lines
2 KiB
TypeScript
Raw Normal View History

2019-06-27 01:12:00 +00:00
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');
const toolDir = path.join(
process.cwd(),
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'tools'
);
const tempDir = path.join(
process.cwd(),
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'temp'
);
process.env['RUNNER_TOOLSDIRECTORY'] = toolDir;
process.env['RUNNER_TEMPDIRECTORY'] = tempDir;
import * as finder from '../src/find-python';
describe('Finder tests', () => {
2019-06-27 15:40:43 +00:00
it('Finds Python if it is installed', async () => {
const pythonDir: string = path.join(toolDir, 'python', '2.0.0', 'x64');
await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await finder.findPythonVersion('2.x', 'x64');
});
2019-06-27 01:12:00 +00:00
2019-06-27 15:40:43 +00:00
it('Errors if Python is not installed', async () => {
// This will throw if it doesn't find it in the cache (because no such version exists)
let thrown = false;
try {
await finder.findPythonVersion('3.x', 'x64');
} catch {
thrown = true;
}
expect(thrown).toBeTruthy();
});
2019-06-27 01:12:00 +00:00
2019-06-27 15:40:43 +00:00
it('Finds PyPy if it is installed', async () => {
const pythonDir: string = path.join(toolDir, 'PyPy', '2.0.0', 'x64');
await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await finder.findPythonVersion('pypy2', 'x64');
});
2019-06-27 01:12:00 +00:00
2019-06-27 15:40:43 +00:00
it('Errors if PyPy is not installed', async () => {
// This will throw if it doesn't find it in the cache (because no such version exists)
let thrown = false;
try {
await finder.findPythonVersion('pypy3', 'x64');
} catch {
thrown = true;
}
expect(thrown).toBeTruthy();
});
2019-06-27 01:12:00 +00:00
});