-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathpythonEnvironment.ts
More file actions
78 lines (73 loc) · 2.66 KB
/
pythonEnvironment.ts
File metadata and controls
78 lines (73 loc) · 2.66 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Uri } from 'vscode';
import { PythonEnvironment } from '../../api';
import { PythonEnvironmentImpl } from '../../internal.api';
/**
* Options for {@link createMockPythonEnvironment}.
*/
export interface MockPythonEnvironmentOptions {
/** Environment name, e.g. `myenv`. Defaults to `test-env`. */
name?: string;
/** Filesystem path for `environmentPath`, `displayPath`, and `sysPrefix`. */
envPath: string;
/** Version string. Defaults to `3.12.0`. */
version?: string;
/** Manager id. Defaults to `ms-python.python:conda`. */
managerId?: string;
/** Environment id. Defaults to `<name>-test`. */
id?: string;
/** Optional description. */
description?: string;
/** Optional display name. Defaults to `<name> (<version>)`. */
displayName?: string;
/** If true, includes an `activation` entry in `execInfo`. */
hasActivation?: boolean;
}
/**
* Create a minimal {@link PythonEnvironment} for use in unit tests.
*
* Shared across manager and view tests so they agree on the shape of a mock
* environment. Only fields that tests commonly need are populated; extend this
* helper if additional fields become required.
*/
export function createMockPythonEnvironment(options: MockPythonEnvironmentOptions): PythonEnvironment {
const {
name = 'test-env',
envPath,
version = '3.12.0',
managerId = 'ms-python.python:conda',
id = `${name}-test`,
description,
displayName = `${name} (${version})`,
hasActivation = false,
} = options;
return new PythonEnvironmentImpl(
{ id, managerId },
{
name,
displayName,
displayPath: envPath,
version,
description,
environmentPath: Uri.file(envPath),
sysPrefix: envPath,
execInfo: {
run: { executable: 'python' },
...(hasActivation && {
activation: [{ executable: envPath.replace('python', 'activate') }],
}),
},
},
);
}
/**
* Positional shorthand for {@link createMockPythonEnvironment} that always
* creates a conda environment (`managerId` = `ms-python.python:conda`).
* Used by conda manager unit tests. Prefer {@link createMockPythonEnvironment}
* for new tests that need to customize additional fields or target a different
* manager.
*/
export function makeMockCondaEnvironment(name: string, envPath: string, version: string = '3.12.0'): PythonEnvironment {
return createMockPythonEnvironment({ name, envPath, version });
}