Skip to content

Commit 67f42f0

Browse files
authored
Use the right version of Python interpreter on Travis when running unit tests (#1319)
Fixes #1318
1 parent 387bb2b commit 67f42f0

16 files changed

+65
-64
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"files.exclude": {
44
"out": true, // set this to true to hide the "out" folder with the compiled JS files
55
"**/*.pyc": true,
6+
"obj": true,
7+
"bin": true,
68
"**/__pycache__": true,
79
"node_modules": true,
810
".vscode-test": true,
@@ -19,4 +21,4 @@
1921
"python.unitTest.promptToConfigure": false,
2022
"python.workspaceSymbols.enabled": false,
2123
"python.formatting.provider": "none"
22-
}
24+
}

news/3 Code Health/1318.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure all unit tests run on Travis use the right Python interpreter.

src/client/terminals/codeExecution/djangoShellCodeExecution.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../comm
1010
import '../../common/extensions';
1111
import { IFileSystem, IPlatformService } from '../../common/platform/types';
1212
import { ITerminalServiceFactory } from '../../common/terminal/types';
13-
import { IConfigurationService } from '../../common/types';
14-
import { IDisposableRegistry } from '../../common/types';
13+
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
1514
import { DjangoContextInitializer } from './djangoContext';
1615
import { TerminalCodeExecutionProvider } from './terminalCodeExecution';
1716

1817
@injectable()
1918
export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvider {
20-
constructor( @inject(ITerminalServiceFactory) terminalServiceFactory: ITerminalServiceFactory,
19+
constructor(@inject(ITerminalServiceFactory) terminalServiceFactory: ITerminalServiceFactory,
2120
@inject(IConfigurationService) configurationService: IConfigurationService,
2221
@inject(IWorkspaceService) workspace: IWorkspaceService,
2322
@inject(IDocumentManager) documentManager: IDocumentManager,
@@ -30,10 +29,10 @@ export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvi
3029
this.terminalTitle = 'Django Shell';
3130
disposableRegistry.push(new DjangoContextInitializer(documentManager, workspace, fileSystem, commandManager));
3231
}
33-
public getReplCommandArgs(resource?: Uri): { command: string, args: string[] } {
32+
public getReplCommandArgs(resource?: Uri): { command: string; args: string[] } {
3433
const pythonSettings = this.configurationService.getSettings(resource);
3534
const command = this.platformService.isWindows ? pythonSettings.pythonPath.replace(/\\/g, '/') : pythonSettings.pythonPath;
36-
const args = pythonSettings.terminal.launchArgs.slice();
35+
const args = pythonSettings.terminal!.launchArgs.slice();
3736

3837
const workspaceUri = resource ? this.workspace.getWorkspaceFolder(resource) : undefined;
3938
const defaultWorkspace = Array.isArray(this.workspace.workspaceFolders) && this.workspace.workspaceFolders.length > 0 ? this.workspace.workspaceFolders[0].uri.fsPath : '';

src/test/common/moduleInstaller.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ITerminalService, ITerminalServiceFactory } from '../../client/common/t
2121
import { IConfigurationService, ICurrentProcess, IInstaller, ILogger, IPathUtils, IPersistentStateFactory, IPythonSettings, IsWindows } from '../../client/common/types';
2222
import { ICondaService, IInterpreterLocatorService, IInterpreterService, INTERPRETER_LOCATOR_SERVICE, InterpreterType, PIPENV_SERVICE, PythonInterpreter } from '../../client/interpreter/contracts';
2323
import { IServiceContainer } from '../../client/ioc/types';
24-
import { rootWorkspaceUri } from '../common';
24+
import { PYTHON_PATH, rootWorkspaceUri } from '../common';
2525
import { MockModuleInstaller } from '../mocks/moduleInstaller';
2626
import { MockProcessService } from '../mocks/proc';
2727
import { UnitTestIocContainer } from '../unittests/serviceRegistry';
@@ -195,7 +195,7 @@ suite('Module Installer', () => {
195195

196196
const interpreter: PythonInterpreter = {
197197
type: InterpreterType.Unknown,
198-
path: 'python'
198+
path: PYTHON_PATH
199199
};
200200
interpreterService.setup(x => x.getActiveInterpreter(TypeMoq.It.isAny())).returns(() => Promise.resolve(interpreter));
201201

src/test/debugger/attach.ptvsd.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PythonV2DebugConfigurationProvider } from '../../client/debugger';
1919
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
2020
import { AttachRequestArguments, DebugOptions } from '../../client/debugger/Common/Contracts';
2121
import { IServiceContainer } from '../../client/ioc/types';
22-
import { sleep } from '../common';
22+
import { PYTHON_PATH, sleep } from '../common';
2323
import { initialize, IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
2424
import { continueDebugging, createDebugAdapter } from './utils';
2525

@@ -59,7 +59,7 @@ suite('Attach Debugger - Experimental', () => {
5959
// tslint:disable-next-line:no-string-literal
6060
env['PYTHONPATH'] = PTVSD_PATH;
6161
const pythonArgs = ['-m', 'ptvsd', '--server', '--port', `${port}`, '--file', fileToDebug.fileToCommandArgument()];
62-
proc = spawn('python', pythonArgs, { env: env, cwd: path.dirname(fileToDebug) });
62+
proc = spawn(PYTHON_PATH, pythonArgs, { env: env, cwd: path.dirname(fileToDebug) });
6363
await sleep(3000);
6464

6565
// Send initialize, attach

src/test/debugger/attach.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { createDeferred } from '../../client/common/helpers';
1212
import { BufferDecoder } from '../../client/common/process/decoder';
1313
import { ProcessService } from '../../client/common/process/proc';
1414
import { AttachRequestArguments } from '../../client/debugger/Common/Contracts';
15-
import { sleep } from '../common';
15+
import { PYTHON_PATH, sleep } from '../common';
1616
import { initialize, IS_APPVEYOR, IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
1717
import { DEBUGGER_TIMEOUT } from './common/constants';
1818

@@ -67,7 +67,7 @@ suite('Attach Debugger', () => {
6767
// tslint:disable-next-line:no-string-literal
6868
customEnv['PYTHONPATH'] = ptvsdPath;
6969
const procService = new ProcessService(new BufferDecoder());
70-
const result = procService.execObservable('python', [fileToDebug, port.toString()], { env: customEnv, cwd: path.dirname(fileToDebug) });
70+
const result = procService.execObservable(PYTHON_PATH, [fileToDebug, port.toString()], { env: customEnv, cwd: path.dirname(fileToDebug) });
7171
procToKill = result.proc;
7272

7373
const expectedOutputs = [

src/test/debugger/capabilities.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { PTVSD_PATH } from '../../client/debugger/Common/constants';
2020
import { ProtocolParser } from '../../client/debugger/Common/protocolParser';
2121
import { ProtocolMessageWriter } from '../../client/debugger/Common/protocolWriter';
2222
import { PythonDebugger } from '../../client/debugger/mainV2';
23+
import { PYTHON_PATH } from '../common';
2324
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
2425

2526
class Request extends Message implements DebugProtocol.InitializeRequest {
@@ -80,7 +81,7 @@ suite('Debugging - Capabilities', () => {
8081
const port = await getFreePort({ host, port: 3000 });
8182
const env = { ...process.env };
8283
env.PYTHONPATH = PTVSD_PATH;
83-
proc = spawn('python', ['-m', 'ptvsd', '--server', '--port', `${port}`, '--file', fileToDebug], { cwd: path.dirname(fileToDebug), env });
84+
proc = spawn(PYTHON_PATH, ['-m', 'ptvsd', '--server', '--port', `${port}`, '--file', fileToDebug], { cwd: path.dirname(fileToDebug), env });
8485
await sleep(3000);
8586

8687
const connected = createDeferred();

src/test/debugger/core/capabilities.test.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/test/debugger/misc.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { FileSystem } from '../../client/common/platform/fileSystem';
1515
import { PlatformService } from '../../client/common/platform/platformService';
1616
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
1717
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
18-
import { sleep } from '../common';
18+
import { PYTHON_PATH, sleep } from '../common';
1919
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
2020
import { DEBUGGER_TIMEOUT } from './common/constants';
2121
import { DebugClientEx } from './debugClient';
@@ -78,7 +78,7 @@ let testCounter = 0;
7878
cwd: debugFilesPath,
7979
stopOnEntry,
8080
debugOptions: [DebugOptions.RedirectOutput],
81-
pythonPath: 'python',
81+
pythonPath: PYTHON_PATH,
8282
args: [],
8383
env,
8484
envFile: '',

src/test/debugger/module.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
1111
import { noop } from '../../client/common/core.utils';
1212
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
1313
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
14-
import { sleep } from '../common';
14+
import { PYTHON_PATH, sleep } from '../common';
1515
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
1616
import { createDebugAdapter } from './utils';
1717

@@ -46,7 +46,7 @@ suite(`Module Debugging - Misc tests: ${debuggerType}`, () => {
4646
program: '',
4747
cwd: workspaceDirectory,
4848
debugOptions: [DebugOptions.RedirectOutput],
49-
pythonPath: 'python',
49+
pythonPath: PYTHON_PATH,
5050
args: [],
5151
env,
5252
envFile: '',

src/test/debugger/portAndHost.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path';
99
import { DebugClient } from 'vscode-debugadapter-testsupport';
1010
import { noop } from '../../client/common/core.utils';
1111
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
12+
import { PYTHON_PATH } from '../common';
1213
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
1314
import { DEBUGGER_TIMEOUT } from './common/constants';
1415

@@ -50,7 +51,7 @@ const EXPERIMENTAL_DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'd
5051
cwd: debugFilesPath,
5152
stopOnEntry,
5253
debugOptions: [DebugOptions.RedirectOutput],
53-
pythonPath: 'python',
54+
pythonPath: PYTHON_PATH,
5455
args: [],
5556
envFile: '',
5657
host, port,

src/test/interpreters/interpreterVersion.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../../client/common/extensions';
77
import { IProcessService } from '../../client/common/process/types';
88
import { IInterpreterVersionService } from '../../client/interpreter/contracts';
99
import { PIP_VERSION_REGEX } from '../../client/interpreter/interpreterVersion';
10+
import { PYTHON_PATH } from '../common';
1011
import { initialize, initializeTest } from '../initialize';
1112
import { UnitTestIocContainer } from '../unittests/serviceRegistry';
1213

@@ -31,10 +32,10 @@ suite('Interpreters display version', () => {
3132

3233
test('Must return the Python Version', async () => {
3334
const pythonProcess = ioc.serviceContainer.get<IProcessService>(IProcessService);
34-
const output = await pythonProcess.exec('python', ['--version'], { cwd: __dirname, mergeStdOutErr: true });
35+
const output = await pythonProcess.exec(PYTHON_PATH, ['--version'], { cwd: __dirname, mergeStdOutErr: true });
3536
const version = output.stdout.splitLines()[0];
3637
const interpreterVersion = ioc.serviceContainer.get<IInterpreterVersionService>(IInterpreterVersionService);
37-
const pyVersion = await interpreterVersion.getVersion('python', 'DEFAULT_TEST_VALUE');
38+
const pyVersion = await interpreterVersion.getVersion(PYTHON_PATH, 'DEFAULT_TEST_VALUE');
3839
assert.equal(pyVersion, version, 'Incorrect version');
3940
});
4041
test('Must return the default value when Python path is invalid', async () => {
@@ -44,7 +45,7 @@ suite('Interpreters display version', () => {
4445
});
4546
test('Must return the pip Version', async () => {
4647
const pythonProcess = ioc.serviceContainer.get<IProcessService>(IProcessService);
47-
const result = await pythonProcess.exec('python', ['-m', 'pip', '--version'], { cwd: __dirname, mergeStdOutErr: true });
48+
const result = await pythonProcess.exec(PYTHON_PATH, ['-m', 'pip', '--version'], { cwd: __dirname, mergeStdOutErr: true });
4849
const output = result.stdout.splitLines()[0];
4950
// Take the second part, see below example.
5051
// pip 9.0.1 from /Users/donjayamanne/anaconda3/lib/python3.6/site-packages (python 3.6).
@@ -55,7 +56,7 @@ suite('Interpreters display version', () => {
5556
assert.isAtLeast(matches!.length, 1, 'Version number not found');
5657

5758
const interpreterVersion = ioc.serviceContainer.get<IInterpreterVersionService>(IInterpreterVersionService);
58-
const pipVersionPromise = interpreterVersion.getPipVersion('python');
59+
const pipVersionPromise = interpreterVersion.getPipVersion(PYTHON_PATH);
5960
// tslint:disable-next-line:no-non-null-assertion
6061
await expect(pipVersionPromise).to.eventually.equal(matches![0].trim());
6162
});

src/test/interpreters/virtualEnvManager.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IBufferDecoder, IProcessService } from '../../client/common/process/typ
1010
import { VirtualEnvironmentManager } from '../../client/interpreter/virtualEnvs';
1111
import { ServiceContainer } from '../../client/ioc/container';
1212
import { ServiceManager } from '../../client/ioc/serviceManager';
13+
import { PYTHON_PATH } from '../common';
1314

1415
suite('Virtual environment manager', () => {
1516
let serviceManager: ServiceManager;
@@ -22,15 +23,15 @@ suite('Virtual environment manager', () => {
2223
serviceContainer = new ServiceContainer(cont);
2324
});
2425

25-
test('Plain Python environment suffix', async () => await testSuffix(''));
26-
test('Venv environment suffix', async () => await testSuffix('venv'));
27-
test('Virtualenv Python environment suffix', async () => await testSuffix('virtualenv'));
26+
test('Plain Python environment suffix', async () => testSuffix(''));
27+
test('Venv environment suffix', async () => testSuffix('venv'));
28+
test('Virtualenv Python environment suffix', async () => testSuffix('virtualenv'));
2829

2930
test('Run actual virtual env detection code', async () => {
3031
serviceManager.addSingleton<IProcessService>(IProcessService, ProcessService);
3132
serviceManager.addSingleton<IBufferDecoder>(IBufferDecoder, BufferDecoder);
3233
const venvManager = new VirtualEnvironmentManager(serviceContainer);
33-
const name = await venvManager.getEnvironmentName('python');
34+
const name = await venvManager.getEnvironmentName(PYTHON_PATH);
3435
const result = name === '' || name === 'venv' || name === 'virtualenv';
3536
expect(result).to.be.equal(true, 'Running venv detection code failed.');
3637
});
@@ -41,13 +42,13 @@ suite('Virtual environment manager', () => {
4142

4243
const venvManager = new VirtualEnvironmentManager(serviceContainer);
4344
process
44-
.setup(x => x.exec('python', TypeMoq.It.isAny()))
45+
.setup(x => x.exec(PYTHON_PATH, TypeMoq.It.isAny()))
4546
.returns(() => Promise.resolve({
4647
stdout: expectedName,
4748
stderr: ''
4849
}));
4950

50-
const name = await venvManager.getEnvironmentName('python');
51+
const name = await venvManager.getEnvironmentName(PYTHON_PATH);
5152
expect(name).to.be.equal(expectedName, 'Virtual envrironment name suffix is incorrect.');
5253
}
5354
});

src/test/providers/shebangCodeLenseProvider.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as assert from 'assert';
22
import * as child_process from 'child_process';
33
import * as path from 'path';
4-
import * as vscode from 'vscode';
5-
import { CancellationTokenSource } from 'vscode';
4+
import { CancellationTokenSource, TextDocument, workspace } from 'vscode';
65
import { IS_WINDOWS, PythonSettings } from '../../client/common/configSettings';
76
import { ShebangCodeLensProvider } from '../../client/interpreter/display/shebangCodeLensProvider';
87
import { getFirstNonEmptyLineFromMultilineString } from '../../client/interpreter/helpers';
@@ -91,7 +90,7 @@ suite('Shebang detection', () => {
9190
});
9291

9392
async function openFile(fileName: string) {
94-
return vscode.workspace.openTextDocument(fileName);
93+
return workspace.openTextDocument(fileName);
9594
}
9695
async function getFullyQualifiedPathToInterpreter(pythonPath: string) {
9796
return new Promise<string>(resolve => {
@@ -101,8 +100,8 @@ suite('Shebang detection', () => {
101100
}).catch(() => undefined);
102101
}
103102

104-
async function setupCodeLens(document: vscode.TextDocument) {
103+
async function setupCodeLens(document: TextDocument) {
105104
const codeLensProvider = new ShebangCodeLensProvider(ioc.serviceContainer);
106-
return await codeLensProvider.provideCodeLenses(document, new CancellationTokenSource().token);
105+
return codeLensProvider.provideCodeLenses(document, new CancellationTokenSource().token);
107106
}
108107
});

src/test/terminals/codeExecution/djangoShellCodeExect.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ITerminalService, ITerminalServiceFactory } from '../../../client/commo
1313
import { IConfigurationService, IPythonSettings, ITerminalSettings } from '../../../client/common/types';
1414
import { DjangoShellCodeExecutionProvider } from '../../../client/terminals/codeExecution/djangoShellCodeExecution';
1515
import { ICodeExecutionService } from '../../../client/terminals/types';
16+
import { PYTHON_PATH } from '../../common';
1617

1718
// tslint:disable-next-line:max-func-body-length
1819
suite('Terminal - Django Shell Code Execution', () => {
@@ -86,7 +87,7 @@ suite('Terminal - Django Shell Code Execution', () => {
8687
});
8788

8889
test('Ensure python path is returned as is, when building repl args on Windows', async () => {
89-
const pythonPath = 'python';
90+
const pythonPath = PYTHON_PATH;
9091
const terminalArgs = ['-a', 'b', 'c'];
9192
const expectedTerminalArgs = terminalArgs.concat('manage.py', 'shell');
9293

@@ -102,7 +103,7 @@ suite('Terminal - Django Shell Code Execution', () => {
102103
});
103104

104105
test('Ensure python path is returned as is, on non Windows', async () => {
105-
const pythonPath = 'python';
106+
const pythonPath = PYTHON_PATH;
106107
const terminalArgs = ['-a', 'b', 'c'];
107108
const expectedTerminalArgs = terminalArgs.concat('manage.py', 'shell');
108109

0 commit comments

Comments
 (0)