Skip to content
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: 0 additions & 1 deletion news/2 Fixes/6303.md

This file was deleted.

6 changes: 2 additions & 4 deletions src/client/testing/codeLenses/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as vscode from 'vscode';
import { IServiceContainer } from '../../../client/ioc/types';
import { PYTHON } from '../../common/constants';
import { ITestCollectionStorageService } from '../common/types';
import { TestFileCodeLensProvider } from './testFiles';

export function activateCodeLenses(
onDidChange: vscode.EventEmitter<void>,
symbolProvider: vscode.DocumentSymbolProvider,
testCollectionStorage: ITestCollectionStorageService,
serviceContainer: IServiceContainer
testCollectionStorage: ITestCollectionStorageService
): vscode.Disposable {
const disposables: vscode.Disposable[] = [];
const codeLensProvider = new TestFileCodeLensProvider(onDidChange, symbolProvider, testCollectionStorage, serviceContainer);
const codeLensProvider = new TestFileCodeLensProvider(onDidChange, symbolProvider, testCollectionStorage);
disposables.push(vscode.languages.registerCodeLensProvider(PYTHON, codeLensProvider));

return {
Expand Down
28 changes: 8 additions & 20 deletions src/client/testing/codeLenses/testFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

// tslint:disable:no-object-literal-type-assertion

import { CancellationToken, CancellationTokenSource, CodeLens, CodeLensProvider, DocumentSymbolProvider, Event, EventEmitter, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri } from 'vscode';
import { IWorkspaceService } from '../../../client/common/application/types';
import { IFileSystem } from '../../../client/common/platform/types';
import { IServiceContainer } from '../../../client/ioc/types';
import { CancellationToken, CancellationTokenSource, CodeLens, CodeLensProvider, DocumentSymbolProvider, Event, EventEmitter, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, workspace } from 'vscode';
import * as constants from '../../common/constants';
import { CommandSource } from '../common/constants';
import { ITestCollectionStorageService, TestFile, TestFunction, TestStatus, TestsToRun, TestSuite } from '../common/types';
Expand All @@ -16,23 +13,18 @@ type FunctionsAndSuites = {
};

export class TestFileCodeLensProvider implements CodeLensProvider {
private workspaceService: IWorkspaceService;
private fileSystem: IFileSystem;
// tslint:disable-next-line:variable-name
constructor(private _onDidChange: EventEmitter<void>,
private symbolProvider: DocumentSymbolProvider,
private testCollectionStorage: ITestCollectionStorageService,
serviceContainer: IServiceContainer) {
this.workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
this.fileSystem = serviceContainer.get<IFileSystem>(IFileSystem);
private testCollectionStorage: ITestCollectionStorageService) {
}

get onDidChangeCodeLenses(): Event<void> {
return this._onDidChange.event;
}

public async provideCodeLenses(document: TextDocument, token: CancellationToken) {
const wkspace = this.workspaceService.getWorkspaceFolder(document.uri);
const wkspace = workspace.getWorkspaceFolder(document.uri);
if (!wkspace) {
return [];
}
Expand Down Expand Up @@ -60,20 +52,16 @@ export class TestFileCodeLensProvider implements CodeLensProvider {
return Promise.resolve(codeLens);
}

public getTestFileWhichNeedsCodeLens(document: TextDocument): TestFile | undefined {
const wkspace = this.workspaceService.getWorkspaceFolder(document.uri);
private async getCodeLenses(document: TextDocument, token: CancellationToken, symbolProvider: DocumentSymbolProvider) {
const wkspace = workspace.getWorkspaceFolder(document.uri);
if (!wkspace) {
return;
return [];
}
const tests = this.testCollectionStorage.getTests(wkspace.uri);
if (!tests) {
return;
return [];
}
return tests.testFiles.find(item => this.fileSystem.arePathsSame(item.fullPath, document.uri.fsPath));
}

private async getCodeLenses(document: TextDocument, token: CancellationToken, symbolProvider: DocumentSymbolProvider) {
const file = this.getTestFileWhichNeedsCodeLens(document);
const file = tests.testFiles.find(item => item.fullPath === document.uri.fsPath);
if (!file) {
return [];
}
Expand Down
27 changes: 3 additions & 24 deletions src/client/testing/common/services/discoveredTestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ import * as path from 'path';
import { Uri } from 'vscode';
import { IWorkspaceService } from '../../../common/application/types';
import { traceError } from '../../../common/logger';
import { IFileSystem } from '../../../common/platform/types';
import { TestDataItem } from '../../types';
import { getParentFile, getParentSuite, getTestType } from '../testUtils';
import { FlattenedTestFunction, FlattenedTestSuite, SubtestParent, TestFile, TestFolder, TestFunction, Tests, TestSuite, TestType } from '../types';
import { DiscoveredTests, ITestDiscoveredTestParser, TestContainer, TestItem } from './types';

@injectable()
export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
constructor(
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IFileSystem) private readonly fileSystem: IFileSystem
) { }
constructor(@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService) { }
public parse(resource: Uri, discoveredTests: DiscoveredTests[]): Tests {
const tests: Tests = {
rootTestFolders: [],
Expand All @@ -38,14 +34,8 @@ export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {

// If the root is the workspace folder, then ignore that.
for (const data of discoveredTests) {
// For now we only check the current workspace.
const root = this.findRoot(data.root, [workspace.uri.fsPath]);
if (!root) {
// For now we only support tests from the workspace.
continue;
}
const rootFolder = {
name: root, folders: [], time: 0,
name: data.root, folders: [], time: 0,
testFiles: [], resource: resource, nameToRun: data.rootid
};
tests.rootTestFolders.push(rootFolder);
Expand All @@ -68,7 +58,7 @@ export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
* @param {Tests} tests
* @memberof TestsDiscovery
*/
public buildChildren(rootFolder: TestFolder, parent: TestDataItem, discoveredTests: DiscoveredTests, tests: Tests) {
protected buildChildren(rootFolder: TestFolder, parent: TestDataItem, discoveredTests: DiscoveredTests, tests: Tests) {
const parentType = getTestType(parent);
switch (parentType) {
case TestType.testFolder: {
Expand Down Expand Up @@ -203,17 +193,6 @@ export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
parent.functions.push(...functions);
tests.testFunctions.push(...functions.map(func => createFlattenedParameterizedFunction(tests, func, parent)));
}

/**
* Returns the vscode recognized file paths which matches the pytest data test root
*/
private findRoot(raw: string, roots: string[]): string | undefined {
for (const root of roots) {
if (this.fileSystem.arePathsSame(raw, root)) {
return root;
}
}
}
}

function createTestFolder(root: TestFolder, item: TestContainer): TestFolder {
Expand Down
2 changes: 1 addition & 1 deletion src/client/testing/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class UnitTestManagementService implements ITestManagementService, Dispos
}
});
this.disposableRegistry.push(handler);
this.disposableRegistry.push(activateCodeLenses(event, symbolProvider, testCollectionStorage, this.serviceContainer));
this.disposableRegistry.push(activateCodeLenses(event, symbolProvider, testCollectionStorage));
}

@captureTelemetry(EventName.UNITTEST_CONFIGURE, undefined, false)
Expand Down
158 changes: 0 additions & 158 deletions src/test/testing/codeLenses/testFiles.unit.test.ts

This file was deleted.

Loading