Skip to content

Commit 1e3b089

Browse files
committed
used icons in the picklist to display more info
1 parent 3219ddd commit 1e3b089

7 files changed

Lines changed: 68 additions & 30 deletions

File tree

src/client/common/constants.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
export var Command_Set_Interpreter = "python.setInterpreter";
2-
export var Command_Tests_View_UI = "python.viewTests";
3-
export var Command_Tests_Discover = "python.discoverTests";
4-
export var Command_Tests_Run_Failed = "python.runFailedTests";
5-
export var Command_Sort_Imports = "python.sortImports";
6-
export var Command_Tests_Run = "python.runtests";
7-
export var Command_Tests_Stop = "python.stopUnitTests";
8-
export var Command_Tests_ViewOutput = "python.viewTestOutput";
9-
export var Command_Refactor_Extract_Variable = "python.refactorExtractVariable";
10-
export var Command_Refaactor_Extract_Method = "python.refactorExtractMethod";
1+
export var Command_Set_Interpreter = 'python.setInterpreter';
2+
export var Command_Tests_View_UI = 'python.viewTests';
3+
export var Command_Tests_Discover = 'python.discoverTests';
4+
export var Command_Tests_Run_Failed = 'python.runFailedTests';
5+
export var Command_Sort_Imports = 'python.sortImports';
6+
export var Command_Tests_Run = 'python.runtests';
7+
export var Command_Tests_Stop = 'python.stopUnitTests';
8+
export var Command_Tests_ViewOutput = 'python.viewTestOutput';
9+
export var Command_Refactor_Extract_Variable = 'python.refactorExtractVariable';
10+
export var Command_Refaactor_Extract_Method = 'python.refactorExtractMethod';
1111

12-
export var Button_Text_Tests_View_Output = 'View Output';
12+
export var Button_Text_Tests_View_Output = 'View Output';
13+
14+
export var Octicon_Test_Pass = '$(check)';
15+
export var Octicon_Test_Fail = '$(alert)';
16+
export var Octicon_Test_Error = '$(x)';
17+
export var Octicon_Test_Skip = '$(circle-slash)';

src/client/unittest/common/baseTestManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export abstract class BaseTestManager {
6868

6969
if (!ignoreCache && this.tests && this.tests.testFunctions.length > 0) {
7070
this._status = TestStatus.Idle;
71-
this.resetTestResults();
7271
return Promise.resolve(this.tests);
7372
}
7473

@@ -130,7 +129,9 @@ export abstract class BaseTestManager {
130129
if (typeof args === 'object' && args !== null) {
131130
testsToRun = args;
132131
}
133-
this.resetTestResults();
132+
if (runFailedTests === false && testsToRun === null) {
133+
this.resetTestResults();
134+
}
134135
this._status = TestStatus.Running;
135136
this.createCancellationToken();
136137
return this.discoverTests(false, true)

src/client/unittest/common/contracts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export enum TestStatus {
7777
Running,
7878
Fail,
7979
Error,
80-
Skipped
80+
Skipped,
81+
Pass
8182
}
8283
export interface TestsToRun {
8384
testFolder?: TestFolder[];

src/client/unittest/common/xUnitParser.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ export function updateResultsFromXmlLogFile(tests: Tests, outputXmlFile: string,
8585
const xmlClassName = testcase.$.classname.replace(/\(\)/g, '').replace(/\.\./g, '.').replace(/\.\./g, '.').replace(/\.+$/, '');
8686
let result = tests.testFunctions.find(fn => fn.xmlClassName === xmlClassName && fn.testFunction.name === testcase.$.name);
8787
if (!result) {
88-
// oops
88+
// Possible we're dealing with nosetests, where the file name isn't returned to us
89+
// When dealing with nose tests
90+
// It is possible to have a test file named x in two separate test sub directories and have same functions/classes
91+
// And unforutnately xunit log doesn't ouput the filename
92+
93+
// result = tests.testFunctions.find(fn => fn.testFunction.name === testcase.$.name &&
94+
// fn.parentTestSuite && fn.parentTestSuite.name === testcase.$.classname);
95+
8996
// Look for failed file test
9097
let fileTest = testcase.$.file && tests.testFiles.find(file => file.nameToRun === testcase.$.file);
9198
if (fileTest && testcase.error) {
@@ -100,7 +107,7 @@ export function updateResultsFromXmlLogFile(tests: Tests, outputXmlFile: string,
100107
result.testFunction.line = getSafeInt(testcase.$.line, null);
101108
result.testFunction.time = parseFloat(testcase.$.time);
102109
result.testFunction.passed = true;
103-
result.testFunction.status = TestStatus.Idle;
110+
result.testFunction.status = TestStatus.Pass;
104111

105112

106113
if (testcase.failure) {

src/client/unittest/display/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ export class TestResultDisplay {
3030
// Treat errors as a special case, as we generally wouldn't have any errors
3131
const statusText = [];
3232
const toolTip = [];
33+
3334
if (tests.summary.passed > 0) {
34-
statusText.push(`$(check) ${tests.summary.passed}`);
35+
statusText.push(`${constants.Octicon_Test_Pass} ${tests.summary.passed}`);
3536
toolTip.push(`${tests.summary.passed} Passed`);
3637
}
3738
if (tests.summary.failures > 0) {
38-
statusText.push(`$(alert) ${tests.summary.failures}`);
39+
statusText.push(`${constants.Octicon_Test_Fail} ${tests.summary.failures}`);
3940
toolTip.push(`${tests.summary.failures} Failed`);
4041
}
4142
if (tests.summary.errors > 0) {
42-
statusText.push(`$(x) ${tests.summary.errors}`);
43+
statusText.push(`${constants.Octicon_Test_Error} ${tests.summary.errors}`);
4344
toolTip.push(`${tests.summary.errors} Error${tests.summary.errors > 1 ? 's' : ''}`);
4445
}
4546
if (tests.summary.skipped > 0) {
46-
statusText.push(`$(circle-slash) ${tests.summary.skipped}`);
47+
statusText.push(`${constants.Octicon_Test_Skip} ${tests.summary.skipped}`);
4748
toolTip.push(`${tests.summary.skipped} Skipped`);
4849
}
4950
this.statusBar.tooltip = toolTip.length === 0 ? 'No Tests Ran' : toolTip.join(', ') + ' (Tests)';

src/client/unittest/display/picker.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {QuickPickItem, window} from 'vscode';
22
import * as vscode from 'vscode';
3-
import {Tests, TestsToRun, TestFolder, TestFile, TestFunction, TestSuite, FlattenedTestFunction} from '../common/contracts';
3+
import {Tests, TestsToRun, TestFolder, TestFile, TestFunction, TestSuite, FlattenedTestFunction, TestStatus} from '../common/contracts';
44
import {getDiscoveredTests} from '../common/testUtils';
55
import * as constants from '../../common/constants';
66

@@ -9,12 +9,9 @@ export class TestDisplay {
99
}
1010
public displayTestUI() {
1111
const tests = getDiscoveredTests();
12-
displayUI(tests);
12+
window.showQuickPick(buildItems(tests), { matchOnDescription: true, matchOnDetail: true }).then(onItemSelected);
1313
}
1414
}
15-
function displayUI(tests?: Tests) {
16-
window.showQuickPick(buildItems(tests), { matchOnDescription: true, matchOnDetail: true }).then(onItemSelected);
17-
}
1815

1916
enum Type {
2017
RunAll = 0,
@@ -26,31 +23,57 @@ enum Type {
2623
RunMethod = 6,
2724
ViewTestOutput = 7
2825
}
26+
const statusIconMapping = new Map<TestStatus, string>();
27+
statusIconMapping.set(TestStatus.Pass, constants.Octicon_Test_Pass);
28+
statusIconMapping.set(TestStatus.Fail, constants.Octicon_Test_Fail);
29+
statusIconMapping.set(TestStatus.Error, constants.Octicon_Test_Error);
30+
statusIconMapping.set(TestStatus.Skipped, constants.Octicon_Test_Skip);
31+
2932
interface TestItem extends QuickPickItem {
3033
type: Type;
3134
fn?: FlattenedTestFunction;
3235
}
36+
function getSummary(tests?: Tests) {
37+
if (!tests || !tests.summary) {
38+
return '';
39+
}
40+
const statusText = [];
41+
if (tests.summary.passed > 0) {
42+
statusText.push(`${constants.Octicon_Test_Pass} ${tests.summary.passed}`);
43+
}
44+
if (tests.summary.failures > 0) {
45+
statusText.push(`${constants.Octicon_Test_Fail} ${tests.summary.failures}`);
46+
}
47+
if (tests.summary.errors > 0) {
48+
statusText.push(`${constants.Octicon_Test_Error} ${tests.summary.errors}`);
49+
}
50+
if (tests.summary.skipped > 0) {
51+
statusText.push(`${constants.Octicon_Test_Skip} ${tests.summary.skipped}`);
52+
}
53+
return statusText.join(', ').trim();
54+
}
3355
function buildItems(tests?: Tests): TestItem[] {
3456
const items: TestItem[] = [];
3557
items.push({ description: '', label: 'Run All Tests', type: Type.RunAll });
3658
items.push({ description: '', label: 'Rediscover Tests', type: Type.ReDiscover });
37-
items.push({ description: '', label: 'View Test Output', type: Type.ViewTestOutput });
59+
items.push({ description: '', label: 'View Test Output', type: Type.ViewTestOutput, detail: getSummary(tests) });
3860

3961
if (!tests) {
4062
return items;
4163
}
4264

43-
if (tests.testFunctions.some(fn => fn.testFunction.passed === false)) {
44-
items.push({ description: 'Run failed tests only', label: 'Run Failed Tests', type: Type.RunFailed });
65+
if (tests.summary.failures > 0) {
66+
items.push({ description: '', label: 'Run Failed Tests', type: Type.RunFailed, detail: `${constants.Octicon_Test_Fail} ${tests.summary.failures} Failed` });
4567
}
4668

4769
let functionItems: TestItem[] = [];
4870
tests.testFunctions.forEach(fn => {
4971
const classPrefix = fn.parentTestSuite ? fn.parentTestSuite.name + '.' : '';
72+
const icon = statusIconMapping.has(fn.testFunction.status) ? statusIconMapping.get(fn.testFunction.status) + ' ' : '';
5073
functionItems.push({
5174
description: '',
5275
detail: fn.parentTestFile.name,
53-
label: classPrefix + fn.testFunction.name,
76+
label: icon + fn.testFunction.name,
5477
type: Type.RunMethod,
5578
fn: fn
5679
});

src/client/unittest/nosetest/collector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function parseNoseTestModuleCollectionResult(rootDirectory: string, lines: strin
147147
const fnName = path.extname(name).substring(1);
148148
const clsName = path.basename(name, path.extname(name));
149149
const fn: TestFunction = {
150-
name: fnName, nameToRun: `${fileName}:${clsName}.${name}`,
150+
name: fnName, nameToRun: `${fileName}:${clsName}.${fnName}`,
151151
time: 0, functionsFailed: 0, functionsPassed: 0
152152
};
153153

0 commit comments

Comments
 (0)