Skip to content

Commit

Permalink
Reorder test
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Apr 22, 2021
1 parent 247f2a0 commit 5143735
Showing 1 changed file with 46 additions and 43 deletions.
89 changes: 46 additions & 43 deletions src/test/smoke/datascience.smoke.test.ts
Expand Up @@ -26,7 +26,6 @@ suite('Smoke Tests', () => {
}
api = await initialize();
console.log('api', Object.keys(api));
provider = api.serviceManager.get<IInteractiveWindowProvider>(IInteractiveWindowProvider);
await setAutoSaveDelayInWorkspaceRoot(1);
});
setup(initializeTest);
Expand Down Expand Up @@ -56,48 +55,6 @@ suite('Smoke Tests', () => {
await waitForCondition(checkIfFileHasBeenCreated, timeoutForCellToRun, `"${outputFile}" file not created`);
}

test('Interactive window should always pick up current active interpreter', async function () {
// this.timeout(60_000);
// Make an interactive window
await runCellInInteractiveWindow();
assert.ok(provider?.windows?.length === 1, 'Unexpected number of interactive windows created');
const currentWindow = provider?.windows[0];
console.log(currentWindow, currentWindow);
const interpreterForCurrentWindow = currentWindow?.notebook?.getMatchingInterpreter();
assert.ok(interpreterForCurrentWindow !== undefined, 'Unable to get matching interpreter for current window');

// Now change active interpreter
const interpreterService = api.serviceManager.get<IInterpreterService>(IInterpreterService);
const allInterpreters = await interpreterService.getInterpreters();
assert.ok(allInterpreters.length > 1, 'Not enough interpreters to run interactive window smoke test');
const differentInterpreter = allInterpreters.find((interpreter) => interpreter !== interpreterForCurrentWindow);
const originalSettingValues: (string | undefined)[] = [];
const settingNames = ['python.defaultInterpreterPath', 'python.pythonPath'];
const configuration = vscode.workspace.getConfiguration();
for (const setting of settingNames) {
originalSettingValues.push(configuration.get<string | undefined>(setting));
// Save the original setting so we can restore it
await configuration.update(setting, differentInterpreter?.path);
}
await sleep(1_000); // Wait for the Python extension to respond to the setting change

// Now make another interactive window and confirm it's using the newly selected interpreter
currentWindow.dispose();
await runCellInInteractiveWindow();
const newWindow = provider.windows.find((window) => window !== currentWindow);
const interpreterForNewWindow = newWindow?.notebook?.getMatchingInterpreter();
assert.ok(interpreterForNewWindow !== undefined, 'Unable to get matching interpreter for current window');
assert.ok(
interpreterForNewWindow === differentInterpreter,
'Interactive window not created with newly selected interpreter'
);

// Restore the settings we changed in the middle of this test
settingNames.forEach(async (setting, i) => {
await configuration.update(setting, originalSettingValues[i]);
});
});

test('Random bytes generation', async function () {
// We do have a unit test testing this, however create a smoke test to
// ensure that the bundling of the native node modules worked
Expand Down Expand Up @@ -149,4 +106,50 @@ suite('Smoke Tests', () => {
// Give time for the file to be saved before we shutdown
await sleep(300);
}).timeout(timeoutForCellToRun);

test('Interactive window should always pick up current active interpreter', async function () {
// this.timeout(60_000);
// Make an interactive window
if (!this.api) {
api = await initialize();
}
provider = api.serviceManager.get<IInteractiveWindowProvider>(IInteractiveWindowProvider);
await runCellInInteractiveWindow();
assert.ok(provider?.windows?.length === 1, 'Unexpected number of interactive windows created');
const currentWindow = provider?.windows[0];
console.log(currentWindow, currentWindow);
const interpreterForCurrentWindow = currentWindow?.notebook?.getMatchingInterpreter();
assert.ok(interpreterForCurrentWindow !== undefined, 'Unable to get matching interpreter for current window');

// Now change active interpreter
const interpreterService = api.serviceManager.get<IInterpreterService>(IInterpreterService);
const allInterpreters = await interpreterService.getInterpreters();
assert.ok(allInterpreters.length > 1, 'Not enough interpreters to run interactive window smoke test');
const differentInterpreter = allInterpreters.find((interpreter) => interpreter !== interpreterForCurrentWindow);
const originalSettingValues: (string | undefined)[] = [];
const settingNames = ['python.defaultInterpreterPath', 'python.pythonPath'];
const configuration = vscode.workspace.getConfiguration();
for (const setting of settingNames) {
originalSettingValues.push(configuration.get<string | undefined>(setting));
// Save the original setting so we can restore it
await configuration.update(setting, differentInterpreter?.path);
}
await sleep(1_000); // Wait for the Python extension to respond to the setting change

// Now make another interactive window and confirm it's using the newly selected interpreter
currentWindow.dispose();
await runCellInInteractiveWindow();
const newWindow = provider.windows.find((window) => window !== currentWindow);
const interpreterForNewWindow = newWindow?.notebook?.getMatchingInterpreter();
assert.ok(interpreterForNewWindow !== undefined, 'Unable to get matching interpreter for current window');
assert.ok(
interpreterForNewWindow === differentInterpreter,
'Interactive window not created with newly selected interpreter'
);

// Restore the settings we changed in the middle of this test
settingNames.forEach(async (setting, i) => {
await configuration.update(setting, originalSettingValues[i]);
});
});
});

0 comments on commit 5143735

Please sign in to comment.