Skip to content

Commit c23849d

Browse files
committed
modify method to resolve path
1 parent 6156876 commit c23849d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/test/application/importPath/copyImportPathCommand.unit.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { anything, instance, mock, verify, when } from 'ts-mockito';
77
import { expect } from 'chai';
8+
import * as path from 'path';
89
import * as vscode from 'vscode';
910
import { CopyImportPathCommand } from '../../../client/application/importPath/copyImportPathCommand';
1011
import { IClipboard, ICommandManager, IWorkspaceService } from '../../../client/common/application/types';
@@ -45,9 +46,10 @@ suite('Copy Import Path Command', () => {
4546
});
4647

4748
test('execute() – sys.path match takes precedence', async () => {
48-
const absPath = '/home/user/project/src/pkg/module.py';
49+
const projectRoot = path.join(path.sep, 'home', 'user', 'project');
50+
const absPath = path.join(projectRoot, 'src', 'pkg', 'module.py');
4951
const uri = vscode.Uri.file(absPath);
50-
((pythonUtils as unknown) as { getSysPath: () => string[] }).getSysPath = () => ['/home/user/project/src'];
52+
((pythonUtils as unknown) as { getSysPath: () => string[] }).getSysPath = () => [path.join(projectRoot, 'src')];
5153

5254
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined);
5355
((vscode.window as unknown) as { activeTextEditor: { document: { uri: vscode.Uri } } }).activeTextEditor = {
@@ -59,12 +61,13 @@ suite('Copy Import Path Command', () => {
5961
});
6062

6163
test('execute() – workspaceFolder used when no sys.path match', async () => {
62-
const absPath = '/home/user/project/tools/util.py';
64+
const projectRoot = path.join(path.sep, 'home', 'user', 'project');
65+
const absPath = path.join(projectRoot, 'tools', 'util.py');
6366
const uri = vscode.Uri.file(absPath);
6467
((pythonUtils as unknown) as { getSysPath: () => string[] }).getSysPath = () => [];
6568

6669
const wsFolder = {
67-
uri: vscode.Uri.file('/home/user/project'),
70+
uri: vscode.Uri.file(projectRoot),
6871
name: 'project',
6972
index: 0,
7073
} as vscode.WorkspaceFolder;
@@ -78,7 +81,7 @@ suite('Copy Import Path Command', () => {
7881
});
7982

8083
test('execute() – falls back to filename when no matches', async () => {
81-
const absPath = '/tmp/standalone.py';
84+
const absPath = path.join(path.sep, 'tmp', 'standalone.py');
8285
const uri = vscode.Uri.file(absPath);
8386
((pythonUtils as unknown) as { getSysPath: () => string[] }).getSysPath = () => [];
8487
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined);

0 commit comments

Comments
 (0)