Skip to content

Commit 7b81f07

Browse files
committed
separators and update api calls
1 parent 28b34dc commit 7b81f07

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/client/testing/testController/controller.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { inject, injectable, named } from 'inversify';
55
import { uniq } from 'lodash';
66
import * as minimatch from 'minimatch';
7+
import * as path from 'path';
78
import {
89
CancellationToken,
910
TestController,
@@ -56,6 +57,7 @@ import { ProjectAdapter } from './common/projectAdapter';
5657
import { getProjectId, createProjectDisplayName } from './common/projectUtils';
5758
import { PythonProject, PythonEnvironment } from '../../envExt/types';
5859
import { getEnvExtApi, useEnvExtension } from '../../envExt/api.internal';
60+
import { isParentPath } from '../../common/platform/fs-paths';
5961

6062
// Types gymnastics to make sure that sendTriggerTelemetry only accepts the correct types.
6163
type EventPropertyType = IEventNamePropertyMapping[EventName.UNITTEST_DISCOVERY_TRIGGER];
@@ -332,9 +334,9 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
332334
const pythonProjects = envExtApi.getPythonProjects();
333335
traceInfo(`[test-by-project] Found ${pythonProjects.length} total Python projects from API`);
334336

335-
// Filter projects to only those in this workspace
337+
// Filter projects to only those in this workspace TODO; check this
336338
const workspaceProjects = pythonProjects.filter((project) =>
337-
project.uri.fsPath.startsWith(workspaceUri.fsPath),
339+
isParentPath(project.uri.fsPath, workspaceUri.fsPath),
338340
);
339341
traceInfo(`[test-by-project] Filtered to ${workspaceProjects.length} projects in workspace`);
340342

@@ -384,11 +386,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
384386
`[test-by-project] Creating project adapter for: ${pythonProject.name} at ${pythonProject.uri.fsPath}`,
385387
);
386388
// Use project URI as the project ID (no hashing needed)
387-
const projectId = getProjectId(pythonProject.uri);
389+
const projectId = pythonProject.uri.fsPath;
388390

389391
// Resolve the Python environment
390392
const envExtApi = await getEnvExtApi();
391-
const pythonEnvironment = await envExtApi.resolveEnvironment(pythonProject.uri);
393+
const pythonEnvironment = await envExtApi.getEnvironment(pythonProject.uri);
392394

393395
if (!pythonEnvironment) {
394396
throw new Error(`Failed to resolve Python environment for project ${pythonProject.uri.fsPath}`);
@@ -461,7 +463,8 @@ export class PythonTestController implements ITestController, IExtensionSingleAc
461463

462464
// Create a mock PythonProject
463465
const pythonProject: PythonProject = {
464-
name: workspaceUri.fsPath.split('/').pop() || 'workspace',
466+
// Do not assume path separators (fsPath is platform-specific).
467+
name: path.basename(workspaceUri.fsPath) || 'workspace',
465468
uri: workspaceUri,
466469
};
467470

src/test/testing/testController/controller.unit.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,14 @@ suite('PythonTestController', () => {
235235

236236
// Should only create adapters for the 2 projects in the workspace.
237237
assert.strictEqual(createProjectAdapterStub.callCount, 2);
238-
assert.strictEqual(createProjectAdapterStub.firstCall.args[0].uri.fsPath, '/workspace/root/p1');
239-
assert.strictEqual(createProjectAdapterStub.secondCall.args[0].uri.fsPath, '/workspace/root/nested/p2');
238+
assert.strictEqual(
239+
createProjectAdapterStub.firstCall.args[0].uri.toString(),
240+
pythonProjects[0].uri.toString(),
241+
);
242+
assert.strictEqual(
243+
createProjectAdapterStub.secondCall.args[0].uri.toString(),
244+
pythonProjects[1].uri.toString(),
245+
);
240246

241247
assert.strictEqual(createDefaultProjectStub.notCalled, true);
242248
assert.deepStrictEqual(projects, createdAdapters);

0 commit comments

Comments
 (0)