Skip to content

Commit

Permalink
Use the right version of Python interpreter on Travis when running un…
Browse files Browse the repository at this point in the history
…it tests (#1319)

Fixes #1318
  • Loading branch information
DonJayamanne authored Apr 6, 2018
1 parent 387bb2b commit 67f42f0
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"files.exclude": {
"out": true, // set this to true to hide the "out" folder with the compiled JS files
"**/*.pyc": true,
"obj": true,
"bin": true,
"**/__pycache__": true,
"node_modules": true,
".vscode-test": true,
Expand All @@ -19,4 +21,4 @@
"python.unitTest.promptToConfigure": false,
"python.workspaceSymbols.enabled": false,
"python.formatting.provider": "none"
}
}
1 change: 1 addition & 0 deletions news/3 Code Health/1318.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure all unit tests run on Travis use the right Python interpreter.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../comm
import '../../common/extensions';
import { IFileSystem, IPlatformService } from '../../common/platform/types';
import { ITerminalServiceFactory } from '../../common/terminal/types';
import { IConfigurationService } from '../../common/types';
import { IDisposableRegistry } from '../../common/types';
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
import { DjangoContextInitializer } from './djangoContext';
import { TerminalCodeExecutionProvider } from './terminalCodeExecution';

@injectable()
export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvider {
constructor( @inject(ITerminalServiceFactory) terminalServiceFactory: ITerminalServiceFactory,
constructor(@inject(ITerminalServiceFactory) terminalServiceFactory: ITerminalServiceFactory,
@inject(IConfigurationService) configurationService: IConfigurationService,
@inject(IWorkspaceService) workspace: IWorkspaceService,
@inject(IDocumentManager) documentManager: IDocumentManager,
Expand All @@ -30,10 +29,10 @@ export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvi
this.terminalTitle = 'Django Shell';
disposableRegistry.push(new DjangoContextInitializer(documentManager, workspace, fileSystem, commandManager));
}
public getReplCommandArgs(resource?: Uri): { command: string, args: string[] } {
public getReplCommandArgs(resource?: Uri): { command: string; args: string[] } {
const pythonSettings = this.configurationService.getSettings(resource);
const command = this.platformService.isWindows ? pythonSettings.pythonPath.replace(/\\/g, '/') : pythonSettings.pythonPath;
const args = pythonSettings.terminal.launchArgs.slice();
const args = pythonSettings.terminal!.launchArgs.slice();

const workspaceUri = resource ? this.workspace.getWorkspaceFolder(resource) : undefined;
const defaultWorkspace = Array.isArray(this.workspace.workspaceFolders) && this.workspace.workspaceFolders.length > 0 ? this.workspace.workspaceFolders[0].uri.fsPath : '';
Expand Down
4 changes: 2 additions & 2 deletions src/test/common/moduleInstaller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ITerminalService, ITerminalServiceFactory } from '../../client/common/t
import { IConfigurationService, ICurrentProcess, IInstaller, ILogger, IPathUtils, IPersistentStateFactory, IPythonSettings, IsWindows } from '../../client/common/types';
import { ICondaService, IInterpreterLocatorService, IInterpreterService, INTERPRETER_LOCATOR_SERVICE, InterpreterType, PIPENV_SERVICE, PythonInterpreter } from '../../client/interpreter/contracts';
import { IServiceContainer } from '../../client/ioc/types';
import { rootWorkspaceUri } from '../common';
import { PYTHON_PATH, rootWorkspaceUri } from '../common';
import { MockModuleInstaller } from '../mocks/moduleInstaller';
import { MockProcessService } from '../mocks/proc';
import { UnitTestIocContainer } from '../unittests/serviceRegistry';
Expand Down Expand Up @@ -195,7 +195,7 @@ suite('Module Installer', () => {

const interpreter: PythonInterpreter = {
type: InterpreterType.Unknown,
path: 'python'
path: PYTHON_PATH
};
interpreterService.setup(x => x.getActiveInterpreter(TypeMoq.It.isAny())).returns(() => Promise.resolve(interpreter));

Expand Down
4 changes: 2 additions & 2 deletions src/test/debugger/attach.ptvsd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { PythonV2DebugConfigurationProvider } from '../../client/debugger';
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
import { AttachRequestArguments, DebugOptions } from '../../client/debugger/Common/Contracts';
import { IServiceContainer } from '../../client/ioc/types';
import { sleep } from '../common';
import { PYTHON_PATH, sleep } from '../common';
import { initialize, IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { continueDebugging, createDebugAdapter } from './utils';

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

// Send initialize, attach
Expand Down
4 changes: 2 additions & 2 deletions src/test/debugger/attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createDeferred } from '../../client/common/helpers';
import { BufferDecoder } from '../../client/common/process/decoder';
import { ProcessService } from '../../client/common/process/proc';
import { AttachRequestArguments } from '../../client/debugger/Common/Contracts';
import { sleep } from '../common';
import { PYTHON_PATH, sleep } from '../common';
import { initialize, IS_APPVEYOR, IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { DEBUGGER_TIMEOUT } from './common/constants';

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

const expectedOutputs = [
Expand Down
3 changes: 2 additions & 1 deletion src/test/debugger/capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { PTVSD_PATH } from '../../client/debugger/Common/constants';
import { ProtocolParser } from '../../client/debugger/Common/protocolParser';
import { ProtocolMessageWriter } from '../../client/debugger/Common/protocolWriter';
import { PythonDebugger } from '../../client/debugger/mainV2';
import { PYTHON_PATH } from '../common';
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';

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

const connected = createDeferred();
Expand Down
6 changes: 0 additions & 6 deletions src/test/debugger/core/capabilities.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/debugger/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FileSystem } from '../../client/common/platform/fileSystem';
import { PlatformService } from '../../client/common/platform/platformService';
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
import { sleep } from '../common';
import { PYTHON_PATH, sleep } from '../common';
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { DEBUGGER_TIMEOUT } from './common/constants';
import { DebugClientEx } from './debugClient';
Expand Down Expand Up @@ -78,7 +78,7 @@ let testCounter = 0;
cwd: debugFilesPath,
stopOnEntry,
debugOptions: [DebugOptions.RedirectOutput],
pythonPath: 'python',
pythonPath: PYTHON_PATH,
args: [],
env,
envFile: '',
Expand Down
4 changes: 2 additions & 2 deletions src/test/debugger/module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
import { noop } from '../../client/common/core.utils';
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
import { sleep } from '../common';
import { PYTHON_PATH, sleep } from '../common';
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { createDebugAdapter } from './utils';

Expand Down Expand Up @@ -46,7 +46,7 @@ suite(`Module Debugging - Misc tests: ${debuggerType}`, () => {
program: '',
cwd: workspaceDirectory,
debugOptions: [DebugOptions.RedirectOutput],
pythonPath: 'python',
pythonPath: PYTHON_PATH,
args: [],
env,
envFile: '',
Expand Down
3 changes: 2 additions & 1 deletion src/test/debugger/portAndHost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as path from 'path';
import { DebugClient } from 'vscode-debugadapter-testsupport';
import { noop } from '../../client/common/core.utils';
import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts';
import { PYTHON_PATH } from '../common';
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
import { DEBUGGER_TIMEOUT } from './common/constants';

Expand Down Expand Up @@ -50,7 +51,7 @@ const EXPERIMENTAL_DEBUG_ADAPTER = path.join(__dirname, '..', '..', 'client', 'd
cwd: debugFilesPath,
stopOnEntry,
debugOptions: [DebugOptions.RedirectOutput],
pythonPath: 'python',
pythonPath: PYTHON_PATH,
args: [],
envFile: '',
host, port,
Expand Down
9 changes: 5 additions & 4 deletions src/test/interpreters/interpreterVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../client/common/extensions';
import { IProcessService } from '../../client/common/process/types';
import { IInterpreterVersionService } from '../../client/interpreter/contracts';
import { PIP_VERSION_REGEX } from '../../client/interpreter/interpreterVersion';
import { PYTHON_PATH } from '../common';
import { initialize, initializeTest } from '../initialize';
import { UnitTestIocContainer } from '../unittests/serviceRegistry';

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

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

const interpreterVersion = ioc.serviceContainer.get<IInterpreterVersionService>(IInterpreterVersionService);
const pipVersionPromise = interpreterVersion.getPipVersion('python');
const pipVersionPromise = interpreterVersion.getPipVersion(PYTHON_PATH);
// tslint:disable-next-line:no-non-null-assertion
await expect(pipVersionPromise).to.eventually.equal(matches![0].trim());
});
Expand Down
13 changes: 7 additions & 6 deletions src/test/interpreters/virtualEnvManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IBufferDecoder, IProcessService } from '../../client/common/process/typ
import { VirtualEnvironmentManager } from '../../client/interpreter/virtualEnvs';
import { ServiceContainer } from '../../client/ioc/container';
import { ServiceManager } from '../../client/ioc/serviceManager';
import { PYTHON_PATH } from '../common';

suite('Virtual environment manager', () => {
let serviceManager: ServiceManager;
Expand All @@ -22,15 +23,15 @@ suite('Virtual environment manager', () => {
serviceContainer = new ServiceContainer(cont);
});

test('Plain Python environment suffix', async () => await testSuffix(''));
test('Venv environment suffix', async () => await testSuffix('venv'));
test('Virtualenv Python environment suffix', async () => await testSuffix('virtualenv'));
test('Plain Python environment suffix', async () => testSuffix(''));
test('Venv environment suffix', async () => testSuffix('venv'));
test('Virtualenv Python environment suffix', async () => testSuffix('virtualenv'));

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

const venvManager = new VirtualEnvironmentManager(serviceContainer);
process
.setup(x => x.exec('python', TypeMoq.It.isAny()))
.setup(x => x.exec(PYTHON_PATH, TypeMoq.It.isAny()))
.returns(() => Promise.resolve({
stdout: expectedName,
stderr: ''
}));

const name = await venvManager.getEnvironmentName('python');
const name = await venvManager.getEnvironmentName(PYTHON_PATH);
expect(name).to.be.equal(expectedName, 'Virtual envrironment name suffix is incorrect.');
}
});
9 changes: 4 additions & 5 deletions src/test/providers/shebangCodeLenseProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as assert from 'assert';
import * as child_process from 'child_process';
import * as path from 'path';
import * as vscode from 'vscode';
import { CancellationTokenSource } from 'vscode';
import { CancellationTokenSource, TextDocument, workspace } from 'vscode';
import { IS_WINDOWS, PythonSettings } from '../../client/common/configSettings';
import { ShebangCodeLensProvider } from '../../client/interpreter/display/shebangCodeLensProvider';
import { getFirstNonEmptyLineFromMultilineString } from '../../client/interpreter/helpers';
Expand Down Expand Up @@ -91,7 +90,7 @@ suite('Shebang detection', () => {
});

async function openFile(fileName: string) {
return vscode.workspace.openTextDocument(fileName);
return workspace.openTextDocument(fileName);
}
async function getFullyQualifiedPathToInterpreter(pythonPath: string) {
return new Promise<string>(resolve => {
Expand All @@ -101,8 +100,8 @@ suite('Shebang detection', () => {
}).catch(() => undefined);
}

async function setupCodeLens(document: vscode.TextDocument) {
async function setupCodeLens(document: TextDocument) {
const codeLensProvider = new ShebangCodeLensProvider(ioc.serviceContainer);
return await codeLensProvider.provideCodeLenses(document, new CancellationTokenSource().token);
return codeLensProvider.provideCodeLenses(document, new CancellationTokenSource().token);
}
});
5 changes: 3 additions & 2 deletions src/test/terminals/codeExecution/djangoShellCodeExect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ITerminalService, ITerminalServiceFactory } from '../../../client/commo
import { IConfigurationService, IPythonSettings, ITerminalSettings } from '../../../client/common/types';
import { DjangoShellCodeExecutionProvider } from '../../../client/terminals/codeExecution/djangoShellCodeExecution';
import { ICodeExecutionService } from '../../../client/terminals/types';
import { PYTHON_PATH } from '../../common';

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

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

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

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

Expand Down
Loading

0 comments on commit 67f42f0

Please sign in to comment.