forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
277 lines (250 loc) · 7.73 KB
/
Copy pathtypes.ts
File metadata and controls
277 lines (250 loc) · 7.73 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import {
CancellationToken,
Event,
OutputChannel,
TestController,
TestItem,
TestRun,
TestRunProfileKind,
Uri,
WorkspaceFolder,
} from 'vscode';
import { ITestDebugLauncher, TestDiscoveryOptions } from '../../common/types';
import { IPythonExecutionFactory } from '../../../common/process/types';
import { EnvironmentVariables } from '../../../common/variables/types';
import { Deferred } from '../../../common/utils/async';
export type TestRunInstanceOptions = TestRunOptions & {
exclude?: readonly TestItem[];
debug: boolean;
};
export enum TestDataKinds {
Workspace,
FolderOrFile,
Collection,
Case,
}
export interface TestData {
rawId: string;
runId: string;
id: string;
uri: Uri;
parentId?: string;
kind: TestDataKinds;
}
export const ITestDiscoveryHelper = Symbol('ITestDiscoveryHelper');
export interface ITestDiscoveryHelper {
runTestDiscovery(options: TestDiscoveryOptions): Promise<RawDiscoveredTests[]>;
}
export type TestRefreshOptions = { forceRefresh: boolean };
export const ITestController = Symbol('ITestController');
export interface ITestController {
refreshTestData(resource?: Uri, options?: TestRefreshOptions): Promise<void>;
stopRefreshing(): void;
onRefreshingCompleted: Event<void>;
onRefreshingStarted: Event<void>;
onRunWithoutConfiguration: Event<WorkspaceFolder[]>;
}
export interface ITestRun {
includes: readonly TestItem[];
excludes: readonly TestItem[];
runKind: TestRunProfileKind;
runInstance: TestRun;
}
export const ITestFrameworkController = Symbol('ITestFrameworkController');
export interface ITestFrameworkController {
resolveChildren(testController: TestController, item: TestItem, token?: CancellationToken): Promise<void>;
refreshTestData(testController: TestController, resource?: Uri, token?: CancellationToken): Promise<void>;
runTests(
testRun: ITestRun,
workspace: WorkspaceFolder,
token: CancellationToken,
testController?: TestController,
): Promise<void>;
}
export const ITestsRunner = Symbol('ITestsRunner');
export interface ITestsRunner {
runTests(
testRun: ITestRun,
options: TestRunOptions,
idToRawData: Map<string, TestData>,
testController?: TestController,
): Promise<void>;
}
export type TestRunOptions = {
workspaceFolder: Uri;
cwd: string;
args: string[];
token: CancellationToken;
};
// We expose these here as a convenience and to cut down on churn
// elsewhere in the code.
type RawTestNode = {
id: string;
name: string;
parentid: string;
};
export type RawTestParent = RawTestNode & {
kind: 'folder' | 'file' | 'suite' | 'function' | 'workspace';
};
type RawTestFSNode = RawTestParent & {
kind: 'folder' | 'file';
relpath: string;
};
export type RawTestFolder = RawTestFSNode & {
kind: 'folder';
};
export type RawTestFile = RawTestFSNode & {
kind: 'file';
};
export type RawTestSuite = RawTestParent & {
kind: 'suite';
};
// function-as-a-container is for parameterized ("sub") tests.
export type RawTestFunction = RawTestParent & {
kind: 'function';
};
export type RawTest = RawTestNode & {
source: string;
};
export type RawDiscoveredTests = {
rootid: string;
root: string;
parents: RawTestParent[];
tests: RawTest[];
};
// New test discovery adapter types
export type DataReceivedEvent = {
uuid: string;
data: string;
};
export type TestDiscoveryCommand = {
script: string;
args: string[];
};
export type TestExecutionCommand = {
script: string;
args: string[];
};
export type TestCommandOptions = {
workspaceFolder: Uri;
cwd: string;
command: TestDiscoveryCommand | TestExecutionCommand;
token?: CancellationToken;
outChannel?: OutputChannel;
debugBool?: boolean;
testIds?: string[];
};
export type TestCommandOptionsPytest = {
workspaceFolder: Uri;
cwd: string;
commandStr: string;
token?: CancellationToken;
outChannel?: OutputChannel;
debugBool?: boolean;
testIds?: string[];
env: { [key: string]: string | undefined };
};
/**
* Interface describing the server that will send test commands to the Python side, and process responses.
*
* Consumers will call sendCommand in order to execute Python-related code,
* and will subscribe to the onDataReceived event to wait for the results.
*/
export interface ITestServer {
readonly onDataReceived: Event<DataReceivedEvent>;
readonly onRunDataReceived: Event<DataReceivedEvent>;
readonly onDiscoveryDataReceived: Event<DataReceivedEvent>;
sendCommand(
options: TestCommandOptions,
env: EnvironmentVariables,
runTestIdsPort?: string,
runInstance?: TestRun,
testIds?: string[],
callback?: () => void,
executionFactory?: IPythonExecutionFactory,
): Promise<void>;
serverReady(): Promise<void>;
getPort(): number;
createUUID(cwd: string): string;
deleteUUID(uuid: string): void;
triggerRunDataReceivedEvent(data: DataReceivedEvent): void;
triggerDiscoveryDataReceivedEvent(data: DataReceivedEvent): void;
}
export interface ITestResultResolver {
runIdToVSid: Map<string, string>;
runIdToTestItem: Map<string, TestItem>;
vsIdToRunId: Map<string, string>;
resolveDiscovery(
payload: DiscoveredTestPayload | EOTTestPayload,
deferredTillEOT: Deferred<void>,
token?: CancellationToken,
): void;
resolveExecution(
payload: ExecutionTestPayload | EOTTestPayload,
runInstance: TestRun,
deferredTillEOT: Deferred<void>,
): void;
_resolveDiscovery(payload: DiscoveredTestPayload, token?: CancellationToken): void;
_resolveExecution(payload: ExecutionTestPayload, runInstance: TestRun): void;
}
export interface ITestDiscoveryAdapter {
// ** first line old method signature, second line new method signature
discoverTests(uri: Uri): Promise<DiscoveredTestPayload>;
discoverTests(uri: Uri, executionFactory: IPythonExecutionFactory): Promise<DiscoveredTestPayload>;
}
// interface for execution/runner adapter
export interface ITestExecutionAdapter {
// ** first line old method signature, second line new method signature
runTests(uri: Uri, testIds: string[], debugBool?: boolean): Promise<ExecutionTestPayload>;
runTests(
uri: Uri,
testIds: string[],
debugBool?: boolean,
runInstance?: TestRun,
executionFactory?: IPythonExecutionFactory,
debugLauncher?: ITestDebugLauncher,
): Promise<ExecutionTestPayload>;
}
// Same types as in python_files/unittestadapter/utils.py
export type DiscoveredTestType = 'folder' | 'file' | 'class' | 'test';
export type DiscoveredTestCommon = {
path: string;
name: string;
// Trailing underscore to avoid collision with the 'type' Python keyword.
type_: DiscoveredTestType;
id_: string;
};
export type DiscoveredTestItem = DiscoveredTestCommon & {
lineno: number;
runID: string;
};
export type DiscoveredTestNode = DiscoveredTestCommon & {
children: (DiscoveredTestNode | DiscoveredTestItem)[];
};
export type DiscoveredTestPayload = {
cwd: string;
tests?: DiscoveredTestNode;
status: 'success' | 'error';
error?: string[];
};
export type EOTTestPayload = {
commandType: 'discovery' | 'execution';
eot: boolean;
};
export type ExecutionTestPayload = {
cwd: string;
status: 'success' | 'error';
result?: {
[testRunID: string]: {
test?: string;
outcome?: string;
message?: string;
traceback?: string;
subtest?: string;
};
};
notFound?: string[];
error: string;
};