forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestUtils.ts
More file actions
65 lines (63 loc) · 2.46 KB
/
testUtils.ts
File metadata and controls
65 lines (63 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { injectable } from 'inversify';
import { Uri, workspace } from 'vscode';
import { IApplicationShell } from '../../common/application/types';
import { Product } from '../../common/types';
import { ITestingSettings, TestSettingsPropertyNames } from '../configuration/types';
import { TestProvider } from '../types';
import { ITestsHelper, UnitTestProduct } from './types';
export async function selectTestWorkspace(appShell: IApplicationShell): Promise<Uri | undefined> {
if (!Array.isArray(workspace.workspaceFolders) || workspace.workspaceFolders.length === 0) {
return undefined;
} else if (workspace.workspaceFolders.length === 1) {
return workspace.workspaceFolders[0].uri;
} else {
const workspaceFolder = await appShell.showWorkspaceFolderPick({ placeHolder: 'Select a workspace' });
return workspaceFolder ? workspaceFolder.uri : undefined;
}
}
@injectable()
export class TestsHelper implements ITestsHelper {
public parseProviderName(product: UnitTestProduct): TestProvider {
switch (product) {
case Product.pytest:
return 'pytest';
case Product.unittest:
return 'unittest';
default: {
throw new Error(`Unknown Test Product ${product}`);
}
}
}
public parseProduct(provider: TestProvider): UnitTestProduct {
switch (provider) {
case 'pytest':
return Product.pytest;
case 'unittest':
return Product.unittest;
default: {
throw new Error(`Unknown Test Provider ${provider}`);
}
}
}
public getSettingsPropertyNames(product: UnitTestProduct): TestSettingsPropertyNames {
const id = this.parseProviderName(product);
switch (id) {
case 'pytest': {
return {
argsName: 'pytestArgs' as keyof ITestingSettings,
pathName: 'pytestPath' as keyof ITestingSettings,
enabledName: 'pytestEnabled' as keyof ITestingSettings,
};
}
case 'unittest': {
return {
argsName: 'unittestArgs' as keyof ITestingSettings,
enabledName: 'unittestEnabled' as keyof ITestingSettings,
};
}
default: {
throw new Error(`Unknown Test Provider '${product}'`);
}
}
}
}