forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockPythonService.ts
More file actions
83 lines (70 loc) · 3.09 KB
/
mockPythonService.ts
File metadata and controls
83 lines (70 loc) · 3.09 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import {
ExecutionResult,
IPythonExecutionService,
ObservableExecutionResult,
SpawnOptions
} from '../../client/common/process/types';
import { buildPythonExecInfo } from '../../client/pythonEnvironments/exec';
import { InterpreterInformation, PythonEnvironment } from '../../client/pythonEnvironments/info';
import { MockProcessService } from './mockProcessService';
export class MockPythonService implements IPythonExecutionService {
private interpreter: PythonEnvironment;
private procService: MockProcessService = new MockProcessService();
constructor(interpreter: PythonEnvironment) {
this.interpreter = interpreter;
}
public getInterpreterInformation(): Promise<InterpreterInformation> {
return Promise.resolve(this.interpreter);
}
public getExecutablePath(): Promise<string> {
return Promise.resolve(this.interpreter.path);
}
public isModuleInstalled(_moduleName: string): Promise<boolean> {
return Promise.resolve(false);
}
public execObservable(args: string[], options: SpawnOptions): ObservableExecutionResult<string> {
return this.procService.execObservable(this.interpreter.path, args, options);
}
public execModuleObservable(
moduleName: string,
args: string[],
options: SpawnOptions
): ObservableExecutionResult<string> {
return this.procService.execObservable(this.interpreter.path, ['-m', moduleName, ...args], options);
}
public exec(args: string[], options: SpawnOptions): Promise<ExecutionResult<string>> {
return this.procService.exec(this.interpreter.path, args, options);
}
public execModule(moduleName: string, args: string[], options: SpawnOptions): Promise<ExecutionResult<string>> {
return this.procService.exec(this.interpreter.path, ['-m', moduleName, ...args], options);
}
public addExecResult(args: (string | RegExp)[], result: () => Promise<ExecutionResult<string>>) {
this.procService.addExecResult(this.interpreter.path, args, result);
}
public addExecModuleResult(
moduleName: string,
args: (string | RegExp)[],
result: () => Promise<ExecutionResult<string>>
) {
this.procService.addExecResult(this.interpreter.path, ['-m', moduleName, ...args], result);
}
public addExecObservableResult(args: (string | RegExp)[], result: () => ObservableExecutionResult<string>) {
this.procService.addExecObservableResult(this.interpreter.path, args, result);
}
public addExecModuleObservableResult(
moduleName: string,
args: (string | RegExp)[],
result: () => ObservableExecutionResult<string>
) {
this.procService.addExecObservableResult(this.interpreter.path, ['-m', moduleName, ...args], result);
}
public setDelay(timeout: number | undefined) {
this.procService.setDelay(timeout);
}
public getExecutionInfo(args: string[]) {
return buildPythonExecInfo(this.interpreter.path, args);
}
}