-
Notifications
You must be signed in to change notification settings - Fork 37
Fix platform-specific default virtualenvs path for Poetry on Windows and macOS #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+160
−12
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import assert from 'assert'; | ||
| import * as path from 'path'; | ||
| import * as sinon from 'sinon'; | ||
| import * as platformUtils from '../../../common/utils/platformUtils'; | ||
| import * as pathUtils from '../../../common/utils/pathUtils'; | ||
| import { getDefaultPoetryVirtualenvsPath } from '../../../managers/poetry/poetryUtils'; | ||
|
|
||
| suite('Poetry Utils - getDefaultPoetryVirtualenvsPath', () => { | ||
| let isWindowsStub: sinon.SinonStub; | ||
| let getUserHomeDirStub: sinon.SinonStub; | ||
| let originalPlatform: PropertyDescriptor | undefined; | ||
| let originalEnv: NodeJS.ProcessEnv; | ||
|
|
||
| setup(() => { | ||
| isWindowsStub = sinon.stub(platformUtils, 'isWindows'); | ||
| getUserHomeDirStub = sinon.stub(pathUtils, 'getUserHomeDir'); | ||
| originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform'); | ||
| originalEnv = { ...process.env }; | ||
| }); | ||
|
|
||
| teardown(() => { | ||
| sinon.restore(); | ||
| if (originalPlatform) { | ||
| Object.defineProperty(process, 'platform', originalPlatform); | ||
| } | ||
| process.env = originalEnv; | ||
| }); | ||
|
|
||
| test('should return Linux path on Linux', () => { | ||
| isWindowsStub.returns(false); | ||
| Object.defineProperty(process, 'platform', { value: 'linux', configurable: true }); | ||
| getUserHomeDirStub.returns('/home/testuser'); | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual(result, path.join('/home/testuser', '.cache', 'pypoetry', 'virtualenvs')); | ||
| }); | ||
|
|
||
| test('should return macOS path on darwin', () => { | ||
| isWindowsStub.returns(false); | ||
| Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true }); | ||
| getUserHomeDirStub.returns('/Users/testuser'); | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual(result, path.join('/Users/testuser', 'Library', 'Caches', 'pypoetry', 'virtualenvs')); | ||
| }); | ||
|
|
||
| test('should return LOCALAPPDATA path on Windows when LOCALAPPDATA is set', () => { | ||
| isWindowsStub.returns(true); | ||
| process.env.LOCALAPPDATA = 'C:\\Users\\testuser\\AppData\\Local'; | ||
| process.env.APPDATA = 'C:\\Users\\testuser\\AppData\\Roaming'; | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual( | ||
| result, | ||
| path.join('C:\\Users\\testuser\\AppData\\Local', 'pypoetry', 'Cache', 'virtualenvs'), | ||
| ); | ||
| }); | ||
|
|
||
| test('should fall back to APPDATA on Windows when LOCALAPPDATA is not set', () => { | ||
| isWindowsStub.returns(true); | ||
| delete process.env.LOCALAPPDATA; | ||
| process.env.APPDATA = 'C:\\Users\\testuser\\AppData\\Roaming'; | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual( | ||
| result, | ||
| path.join('C:\\Users\\testuser\\AppData\\Roaming', 'pypoetry', 'Cache', 'virtualenvs'), | ||
| ); | ||
| }); | ||
|
|
||
| test('should return undefined on Windows when neither LOCALAPPDATA nor APPDATA is set', () => { | ||
| isWindowsStub.returns(true); | ||
| delete process.env.LOCALAPPDATA; | ||
| delete process.env.APPDATA; | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual(result, undefined); | ||
| }); | ||
|
|
||
| test('should return undefined when home directory is empty string on non-Windows', () => { | ||
| isWindowsStub.returns(false); | ||
| Object.defineProperty(process, 'platform', { value: 'linux', configurable: true }); | ||
| getUserHomeDirStub.returns(''); | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual(result, undefined); | ||
| }); | ||
|
|
||
| test('should return undefined when home directory is undefined on non-Windows', () => { | ||
| isWindowsStub.returns(false); | ||
| Object.defineProperty(process, 'platform', { value: 'linux', configurable: true }); | ||
| getUserHomeDirStub.returns(undefined); | ||
|
|
||
| const result = getDefaultPoetryVirtualenvsPath(); | ||
|
|
||
| assert.strictEqual(result, undefined); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also testing when
getUserHomeDir()returnsundefined(not just empty string''), since that's also a possible return value from that function.@copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for
getUserHomeDir()returningundefinedin 7b16f74.