2020-12-11 12:29:43 +00:00
|
|
|
import { envMock, exec, mockExecSequence } from '../../../test/exec-util';
|
2020-07-18 08:03:05 +00:00
|
|
|
import { env, getName } from '../../../test/util';
|
2019-07-25 06:17:19 +00:00
|
|
|
import {
|
2019-03-17 14:54:31 +00:00
|
|
|
getPythonAlias,
|
2020-05-01 16:03:48 +00:00
|
|
|
parsePythonVersion,
|
2019-03-17 14:54:31 +00:00
|
|
|
pythonVersions,
|
2020-05-01 16:03:48 +00:00
|
|
|
resetModule,
|
2020-02-05 00:14:31 +00:00
|
|
|
} from './extract';
|
2018-11-15 17:42:01 +00:00
|
|
|
|
2020-01-10 14:18:41 +00:00
|
|
|
jest.mock('child_process');
|
2020-02-05 00:14:31 +00:00
|
|
|
jest.mock('../../util/exec/env');
|
2020-01-02 15:30:40 +00:00
|
|
|
|
2020-07-18 08:03:05 +00:00
|
|
|
describe(getName(__filename), () => {
|
2019-05-24 13:01:07 +00:00
|
|
|
beforeEach(() => {
|
2019-12-20 07:51:20 +00:00
|
|
|
jest.resetAllMocks();
|
2019-05-24 13:01:07 +00:00
|
|
|
jest.resetModules();
|
2019-12-20 07:51:20 +00:00
|
|
|
resetModule();
|
2020-01-02 15:30:40 +00:00
|
|
|
|
2020-01-10 14:18:41 +00:00
|
|
|
env.getChildProcessEnv.mockReturnValue(envMock.basic);
|
2019-05-24 13:01:07 +00:00
|
|
|
});
|
2019-03-17 14:54:31 +00:00
|
|
|
describe('parsePythonVersion', () => {
|
|
|
|
it('returns major and minor version numbers', () => {
|
|
|
|
expect(parsePythonVersion('Python 2.7.15rc1')).toEqual([2, 7]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('getPythonAlias', () => {
|
|
|
|
it('returns the python alias to use', async () => {
|
2020-01-02 15:30:40 +00:00
|
|
|
const execSnapshots = mockExecSequence(exec, [
|
|
|
|
{ stdout: '', stderr: 'Python 2.7.17\\n' },
|
|
|
|
new Error(),
|
|
|
|
{ stdout: 'Python 3.8.0\\n', stderr: '' },
|
|
|
|
]);
|
2019-12-20 07:51:20 +00:00
|
|
|
const result = await getPythonAlias();
|
2020-05-18 12:33:44 +00:00
|
|
|
expect(pythonVersions).toContain(result);
|
2019-12-20 07:51:20 +00:00
|
|
|
expect(result).toMatchSnapshot();
|
2020-07-18 08:03:05 +00:00
|
|
|
expect(await getPythonAlias()).toEqual(result);
|
2020-01-02 15:30:40 +00:00
|
|
|
expect(execSnapshots).toMatchSnapshot();
|
2020-07-18 08:03:05 +00:00
|
|
|
expect(execSnapshots).toHaveLength(3);
|
2018-11-15 17:42:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|