Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Added commands for running tests from a test file
  • Loading branch information
Andreas Schlapsi
Andreas Schlapsi committed Nov 9, 2016
commit ee5af5a4a02a057157682cda9034076c6816a8f0
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"onCommand:python.viewTestUI",
"onCommand:python.viewTestOutput",
"onCommand:python.selectAndRunTestMethod",
"onCommand:python.selectAndRunTestFile",
"onCommand:python.runCurrentTestFile",
"onCommand:python.runFailedTests",
"onCommand:python.execSelectionInTerminal",
"onCommand:jupyter.runSelectionLine",
Expand Down Expand Up @@ -128,6 +130,16 @@
"title": "Run Unit Test Method ...",
"category": "Python"
},
{
"command": "python.selectAndRunTestFile",
"title": "Run Unit Test File ...",
"category": "Python"
},
{
"command": "python.runCurrentTestFile",
"title": "Run Current Unit Test File",
"category": "Python"
},
{
"command": "python.runFailedTests",
"title": "Run Failed Unit Tests",
Expand Down
2 changes: 2 additions & 0 deletions src/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export namespace Commands {
export const Tests_Stop = 'python.stopUnitTests';
export const Tests_ViewOutput = 'python.viewTestOutput';
export const Tests_Select_And_Run_Method = 'python.selectAndRunTestMethod';
export const Tests_Select_And_Run_File = 'python.selectAndRunTestFile';
export const Tests_Run_Current_File = 'python.runCurrentTestFile';
export const Refactor_Extract_Variable = 'python.refactorExtractVariable';
export const Refaactor_Extract_Method = 'python.refactorExtractMethod';

Expand Down
36 changes: 36 additions & 0 deletions src/client/unittests/display/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ export class TestDisplay {
}, reject);
});
}
public selectTestFile(rootDirectory: string, tests: Tests): Promise<TestFile> {
return new Promise<TestFile>((resolve, reject) => {
window.showQuickPick(buildItemsForTestFiles(rootDirectory, tests.testFiles), { matchOnDescription: true, matchOnDetail: true })
.then(item => {
if (item && item.testFile) {
return resolve(item.testFile);
}
return reject();
}, reject);
});
}
public displayFunctionTestPickerUI(rootDirectory: string, fileName: string, testFunctions: TestFunction[]) {
const tests = getDiscoveredTests();
if (!tests) {
Expand Down Expand Up @@ -70,6 +81,10 @@ interface TestItem extends QuickPickItem {
type: Type;
fn?: FlattenedTestFunction;
}
interface TestFileItem extends QuickPickItem {
type: Type;
testFile?: TestFile;
}
function getSummary(tests?: Tests) {
if (!tests || !tests.summary) {
return '';
Expand Down Expand Up @@ -145,6 +160,27 @@ function buildItemsForFunctions(rootDirectory: string, tests: FlattenedTestFunct
});
return functionItems;
}
function buildItemsForTestFiles(rootDirectory: string, testFiles: TestFile[]): TestFileItem[] {
let fileItems: TestFileItem[] = testFiles.map(testFile => {
return {
description: '',
detail: path.relative(rootDirectory, testFile.fullPath),
type: Type.RunFile,
label: path.basename(testFile.fullPath),
testFile: testFile
}
})
fileItems.sort((a, b) => {
if (a.detail < b.detail) {
return -1;
}
if (a.detail > b.detail) {
return 1;
}
return 0;
})
return fileItems;
}
function onItemSelected(selection: TestItem) {
if (!selection || typeof selection.type !== 'number') {
return;
Expand Down
35 changes: 35 additions & 0 deletions src/client/unittests/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function registerCommands(): vscode.Disposable[] {
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Ask_To_Stop_Discovery, () => displayStopUI('Stop discovering tests')));
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Ask_To_Stop_Test, () => displayStopUI('Stop running tests')));
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Run_Method, () => selectAndRunTestMethod()));
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Select_And_Run_File, () => selectAndRunTestFile()));
disposables.push(vscode.commands.registerCommand(constants.Commands.Tests_Run_Current_File, () => runCurrentTestFile()));

return disposables;
}
Expand Down Expand Up @@ -101,6 +103,39 @@ function selectAndRunTestMethod() {
}).catch(() => { });
});
}
function selectAndRunTestFile() {
let testManager = getTestRunner();
if (!testManager) {
return displayTestFrameworkError(outChannel);
}
testManager.discoverTests(true, true).then(() => {
const tests = getDiscoveredTests();
testDisplay = testDisplay ? testDisplay : new TestDisplay();
testDisplay.selectTestFile(vscode.workspace.rootPath, tests).then(testFile => {
runTestsImpl({testFile: [testFile]});
}).catch(() => { });
});
}
function runCurrentTestFile() {
if (!vscode.window.activeTextEditor) {
return;
}
const currentFilePath = vscode.window.activeTextEditor.document.fileName;
let testManager = getTestRunner();
if (!testManager) {
return displayTestFrameworkError(outChannel);
}
testManager.discoverTests(true, true).then(() => {
const tests = getDiscoveredTests();
const testFiles = tests.testFiles.filter(testFile => {
return testFile.fullPath == currentFilePath;
});
if (testFiles.length < 1) {
return;
}
runTestsImpl({testFile: [testFiles[0]]});
});
}
function displayStopUI(message: string) {
let testManager = getTestRunner();
if (!testManager) {
Expand Down
13 changes: 3 additions & 10 deletions src/test/pythonFiles/sorting/withconfig/before.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
from third_party import lib0
from third_party import lib1
from third_party import lib2
from third_party import lib3
from third_party import lib4
from third_party import lib5
from third_party import lib6
from third_party import lib7
from third_party import lib8
from third_party import lib9
from third_party import (lib1, lib2, lib3,
lib4, lib5, lib6,
lib7, lib8, lib9)