Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User python interpreter prescribed by CI #4921

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/4920.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the `Python` interpreter prescribed by CI instead of trying to locate the best possible one.
60 changes: 9 additions & 51 deletions src/test/linters/lint.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
LinterId,
LintMessageSeverity
} from '../../client/linters/types';
import { deleteFile } from '../common';
import { deleteFile, PYTHON_PATH } from '../common';
import {
BaseTestFixture,
getLinterID,
Expand All @@ -50,10 +50,6 @@ import {
throwUnknownProduct
} from './common';

// CI sets "python" to Python 3, but running locally it would be
// Python 2. The env var allos local test execution against Python 3.
const PYTHON = process.env.PVSC_TEST_PYTHON_EXE ? process.env.PVSC_TEST_PYTHON_EXE : 'python';

const workspaceDir = path.join(__dirname, '..', '..', '..', 'src', 'test');
const workspaceUri = Uri.file(workspaceDir);
const pythonFilesDir = path.join(workspaceDir, 'pythonFiles', 'linting');
Expand Down Expand Up @@ -150,7 +146,7 @@ function getMessages(product: Product): ILintMessage[] {
}
case Product.pep8: {
return pep8MessagesToBeReturned;
}
}
case Product.pydocstyle: {
return pydocstyleMessagesToBeReturned;
}
Expand Down Expand Up @@ -187,31 +183,8 @@ async function getInfoForConfig(product: Product) {
};
}

function resolveExecutable(filename: string): string {
if (fs.existsSync(filename)) {
return filename;
}
if (filename.indexOf(path.sep) > -1) {
throw Error(`could not find executable '${filename}'`);
}
const pathSep = process.platform === 'win32' ? ';' : ':';
if (process.platform === 'win32') {
if (!filename.endsWith('.exe')) {
filename += '.exe';
}
}
for (const entry of process.env.PATH!.split(pathSep)) {
const resolved = path.join(entry, filename);
if (fs.existsSync(resolved)) {
return resolved;
}
}
throw Error(`could not find executable '${filename}'`);
}

class TestFixture extends BaseTestFixture {
constructor(
python: string,
printLogs = false
) {
const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(undefined, TypeMoq.MockBehavior.Strict);
Expand All @@ -238,7 +211,7 @@ class TestFixture extends BaseTestFixture {
);

this.pythonSettings.setup(s => s.pythonPath)
.returns(() => python);
.returns(() => PYTHON_PATH);
}

private static newPythonToolExecService(
Expand Down Expand Up @@ -299,15 +272,6 @@ suite('Linting Functional Tests', () => {
// These are integration tests that mock out everything except
// the filesystem and process execution.

let pythonExecutable = '';

function getPython(): string {
if (pythonExecutable === '') {
pythonExecutable = resolveExecutable(PYTHON);
}
return pythonExecutable;
}

// tslint:disable-next-line:no-any
async function testLinterMessages(
fixture: TestFixture,
Expand Down Expand Up @@ -339,34 +303,30 @@ suite('Linting Functional Tests', () => {
}
}
for (const product of LINTERID_BY_PRODUCT.keys()) {
test(getProductName(product), async function() {
test(getProductName(product), async function () {
// tslint:disable-next-line:no-suspicious-comment
// TODO: Add coverage for these linters.
if ([Product.bandit, Product.mypy, Product.pylama, Product.prospector].some(p => p === product)) {
// tslint:disable-next-line:no-invalid-this
this.skip();
}

const fixture = new TestFixture(
getPython()
);
const fixture = new TestFixture();
const messagesToBeReturned = getMessages(product);
await testLinterMessages(fixture, product, fileToLint, messagesToBeReturned);
});
}
for (const product of LINTERID_BY_PRODUCT.keys()) {
// tslint:disable-next-line:max-func-body-length
test(`${getProductName(product)} with config in root`, async function() {
test(`${getProductName(product)} with config in root`, async function () {
// tslint:disable-next-line:no-suspicious-comment
// TODO: Add coverage for these linters.
if ([Product.bandit, Product.mypy, Product.pylama, Product.prospector].some(p => p === product)) {
// tslint:disable-next-line:no-invalid-this
this.skip();
}

const fixture = new TestFixture(
getPython()
);
const fixture = new TestFixture();
if (product === Product.pydocstyle) {
fixture.lintingSettings.pylintUseMinimalCheckers = false;
}
Expand Down Expand Up @@ -411,13 +371,11 @@ suite('Linting Functional Tests', () => {
);

assert.equal(messages.length, messageCountToBeReceived,
'Expected number of lint errors does not match lint error count');
'Expected number of lint errors does not match lint error count');
}
test('Three line output counted as one message', async () => {
const maxErrors = 5;
const fixture = new TestFixture(
getPython()
);
const fixture = new TestFixture();
fixture.lintingSettings.maxNumberOfProblems = maxErrors;
await testLinterMessageCount(
fixture,
Expand Down