|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import assert from 'assert'; |
| 5 | +import * as path from 'path'; |
| 6 | +import * as sinon from 'sinon'; |
| 7 | +import { LogOutputChannel, Uri } from 'vscode'; |
| 8 | +import { PythonEnvironmentApi } from '../../../api'; |
| 9 | +import * as windowApis from '../../../common/window.apis'; |
| 10 | +import * as packageChanges from '../../../managers/common/packageChanges'; |
| 11 | +import { PoetryPackageManager } from '../../../managers/poetry/poetryPackageManager'; |
| 12 | +import { PoetryManager } from '../../../managers/poetry/poetryManager'; |
| 13 | +import * as poetryUtils from '../../../managers/poetry/poetryUtils'; |
| 14 | +import * as runPoetryModule from '../../../managers/poetry/commands/runPoetry'; |
| 15 | +import { createMockPythonEnvironment } from '../../mocks/pythonEnvironment'; |
| 16 | + |
| 17 | +suite('PoetryPackageManager', () => { |
| 18 | + const environment = createMockPythonEnvironment({ |
| 19 | + envPath: path.join(process.cwd(), '.venv'), |
| 20 | + managerId: 'ms-python.python:poetry', |
| 21 | + }); |
| 22 | + let runPoetryStub: sinon.SinonStub; |
| 23 | + let manager: PoetryPackageManager; |
| 24 | + |
| 25 | + setup(() => { |
| 26 | + const api = { |
| 27 | + getPythonProjects: () => [ |
| 28 | + { |
| 29 | + name: 'project', |
| 30 | + uri: Uri.file(path.join(process.cwd(), 'project', 'pyproject.toml')), |
| 31 | + }, |
| 32 | + ], |
| 33 | + } as unknown as PythonEnvironmentApi; |
| 34 | + const log = { |
| 35 | + append: sinon.stub(), |
| 36 | + error: sinon.stub(), |
| 37 | + info: sinon.stub(), |
| 38 | + show: sinon.stub(), |
| 39 | + } as unknown as LogOutputChannel; |
| 40 | + |
| 41 | + sinon.stub(poetryUtils, 'getPoetry').resolves('poetry'); |
| 42 | + sinon.stub(windowApis, 'withProgress').callsFake((_options, task) => task({} as never, {} as never)); |
| 43 | + sinon.stub(packageChanges, 'updatePackagesAndNotify').resolves([]); |
| 44 | + runPoetryStub = sinon.stub(runPoetryModule, 'runPoetry').resolves(''); |
| 45 | + manager = new PoetryPackageManager(api, log, {} as PoetryManager); |
| 46 | + }); |
| 47 | + |
| 48 | + teardown(() => { |
| 49 | + manager.dispose(); |
| 50 | + sinon.restore(); |
| 51 | + }); |
| 52 | + |
| 53 | + test('package management inherits the process working directory', async () => { |
| 54 | + await manager.manage(environment, { install: ['requests'], uninstall: ['flask'] }); |
| 55 | + |
| 56 | + assert.strictEqual(runPoetryStub.callCount, 2); |
| 57 | + assert.strictEqual(runPoetryStub.firstCall.args[1], undefined); |
| 58 | + assert.strictEqual(runPoetryStub.secondCall.args[1], undefined); |
| 59 | + }); |
| 60 | + |
| 61 | + test('direct package listing inherits the process working directory', async () => { |
| 62 | + await manager.getDirectPackageNames(environment); |
| 63 | + |
| 64 | + assert.strictEqual(runPoetryStub.callCount, 1); |
| 65 | + assert.strictEqual(runPoetryStub.firstCall.args[1], undefined); |
| 66 | + }); |
| 67 | +}); |
0 commit comments