Skip to content

Commit 38527d6

Browse files
authored
Resolve >= 3.13 failing REPL CI tests (#24775)
Resolves: #24773
1 parent 803704e commit 38527d6

File tree

2 files changed

+90
-83
lines changed

2 files changed

+90
-83
lines changed

src/test/terminals/codeExecution/helper.test.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import { IServiceContainer } from '../../../client/ioc/types';
3333
import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info';
3434
import { CodeExecutionHelper } from '../../../client/terminals/codeExecution/helper';
3535
import { ICodeExecutionHelper } from '../../../client/terminals/types';
36-
import { PYTHON_PATH } from '../../common';
36+
import { PYTHON_PATH, getPythonSemVer } from '../../common';
3737
import { ReplType } from '../../../client/repl/types';
3838

3939
const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'python_files', 'terminalExec');
4040

41-
suite('Terminal - Code Execution Helper', () => {
41+
suite('Terminal - Code Execution Helper', async () => {
4242
let activeResourceService: TypeMoq.IMock<IActiveResourceService>;
4343
let documentManager: TypeMoq.IMock<IDocumentManager>;
4444
let applicationShell: TypeMoq.IMock<IApplicationShell>;
@@ -234,25 +234,28 @@ suite('Terminal - Code Execution Helper', () => {
234234
expect(normalizedCode).to.be.equal(normalizedExpected);
235235
}
236236

237-
['', '1', '2', '3', '4', '5', '6', '7', '8'].forEach((fileNameSuffix) => {
238-
test(`Ensure code is normalized (Sample${fileNameSuffix})`, async () => {
239-
configurationService
240-
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
241-
.returns({
242-
REPL: {
243-
EnableREPLSmartSend: false,
244-
REPLSmartSend: false,
245-
},
246-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
247-
} as any);
248-
const code = await fs.readFile(path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_raw.py`), 'utf8');
249-
const expectedCode = await fs.readFile(
250-
path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_normalized_selection.py`),
251-
'utf8',
252-
);
253-
await ensureCodeIsNormalized(code, expectedCode);
237+
const pythonTestVersion = await getPythonSemVer();
238+
if (pythonTestVersion && pythonTestVersion.minor < 13) {
239+
['', '1', '2', '3', '4', '5', '6', '7', '8'].forEach((fileNameSuffix) => {
240+
test(`Ensure code is normalized (Sample${fileNameSuffix}) - Python < 3.13`, async () => {
241+
configurationService
242+
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
243+
.returns({
244+
REPL: {
245+
EnableREPLSmartSend: false,
246+
REPLSmartSend: false,
247+
},
248+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
249+
} as any);
250+
const code = await fs.readFile(path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_raw.py`), 'utf8');
251+
const expectedCode = await fs.readFile(
252+
path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_normalized_selection.py`),
253+
'utf8',
254+
);
255+
await ensureCodeIsNormalized(code, expectedCode);
256+
});
254257
});
255-
});
258+
}
256259

257260
test("Display message if there's no active file", async () => {
258261
documentManager.setup((doc) => doc.activeTextEditor).returns(() => undefined);

src/test/terminals/codeExecution/smartSend.test.ts

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import { IServiceContainer } from '../../../client/ioc/types';
2121
import { ICodeExecutionHelper } from '../../../client/terminals/types';
2222
import { Commands, EXTENSION_ROOT_DIR } from '../../../client/common/constants';
2323
import { EnvironmentType, PythonEnvironment } from '../../../client/pythonEnvironments/info';
24-
import { PYTHON_PATH } from '../../common';
24+
import { PYTHON_PATH, getPythonSemVer } from '../../common';
2525
import { Architecture } from '../../../client/common/utils/platform';
2626
import { ProcessService } from '../../../client/common/process/proc';
2727
import { l10n } from '../../mocks/vsc';
2828
import { ReplType } from '../../../client/repl/types';
2929

3030
const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'python_files', 'terminalExec');
3131

32-
suite('REPL - Smart Send', () => {
32+
suite('REPL - Smart Send', async () => {
3333
let documentManager: TypeMoq.IMock<IDocumentManager>;
3434
let applicationShell: TypeMoq.IMock<IApplicationShell>;
3535

@@ -168,67 +168,71 @@ suite('REPL - Smart Send', () => {
168168
commandManager.verifyAll();
169169
});
170170

171-
test('Smart send should perform smart selection and move cursor', async () => {
172-
configurationService
173-
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
174-
.returns({
175-
REPL: {
176-
REPLSmartSend: true,
177-
},
178-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
179-
} as any);
180-
181-
const activeEditor = TypeMoq.Mock.ofType<TextEditor>();
182-
const firstIndexPosition = new Position(0, 0);
183-
const selection = TypeMoq.Mock.ofType<Selection>();
184-
const wholeFileContent = await fs.readFile(path.join(TEST_FILES_PATH, `sample_smart_selection.py`), 'utf8');
185-
186-
selection.setup((s) => s.anchor).returns(() => firstIndexPosition);
187-
selection.setup((s) => s.active).returns(() => firstIndexPosition);
188-
selection.setup((s) => s.isEmpty).returns(() => true);
189-
activeEditor.setup((e) => e.selection).returns(() => selection.object);
190-
191-
documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object);
192-
document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent);
193-
const actualProcessService = new ProcessService();
194-
195-
const { execObservable } = actualProcessService;
196-
197-
processService
198-
.setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
199-
.returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options]));
200-
201-
const actualSmartOutput = await codeExecutionHelper.normalizeLines(
202-
'my_dict = {',
203-
ReplType.terminal,
204-
wholeFileContent,
205-
);
206-
207-
// my_dict = { <----- smart shift+enter here
208-
// "key1": "value1",
209-
// "key2": "value2"
210-
// } <---- cursor should be here afterwards, hence offset 3
211-
commandManager
212-
.setup((c) => c.executeCommand('cursorMove', TypeMoq.It.isAny()))
213-
.callback((_, arg2) => {
214-
assert.deepEqual(arg2, {
215-
to: 'down',
216-
by: 'line',
217-
value: 3,
218-
});
219-
return Promise.resolve();
220-
})
221-
.verifiable(TypeMoq.Times.once());
222-
223-
commandManager
224-
.setup((c) => c.executeCommand('cursorEnd'))
225-
.returns(() => Promise.resolve())
226-
.verifiable(TypeMoq.Times.once());
227-
228-
const expectedSmartOutput = 'my_dict = {\n "key1": "value1",\n "key2": "value2"\n}\n';
229-
expect(actualSmartOutput).to.be.equal(expectedSmartOutput);
230-
commandManager.verifyAll();
231-
});
171+
const pythonTestVersion = await getPythonSemVer();
172+
173+
if (pythonTestVersion && pythonTestVersion.minor < 13) {
174+
test('Smart send should perform smart selection and move cursor - Python < 3.13', async () => {
175+
configurationService
176+
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
177+
.returns({
178+
REPL: {
179+
REPLSmartSend: true,
180+
},
181+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
182+
} as any);
183+
184+
const activeEditor = TypeMoq.Mock.ofType<TextEditor>();
185+
const firstIndexPosition = new Position(0, 0);
186+
const selection = TypeMoq.Mock.ofType<Selection>();
187+
const wholeFileContent = await fs.readFile(path.join(TEST_FILES_PATH, `sample_smart_selection.py`), 'utf8');
188+
189+
selection.setup((s) => s.anchor).returns(() => firstIndexPosition);
190+
selection.setup((s) => s.active).returns(() => firstIndexPosition);
191+
selection.setup((s) => s.isEmpty).returns(() => true);
192+
activeEditor.setup((e) => e.selection).returns(() => selection.object);
193+
194+
documentManager.setup((d) => d.activeTextEditor).returns(() => activeEditor.object);
195+
document.setup((d) => d.getText(TypeMoq.It.isAny())).returns(() => wholeFileContent);
196+
const actualProcessService = new ProcessService();
197+
198+
const { execObservable } = actualProcessService;
199+
200+
processService
201+
.setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
202+
.returns((file, args, options) => execObservable.apply(actualProcessService, [file, args, options]));
203+
204+
const actualSmartOutput = await codeExecutionHelper.normalizeLines(
205+
'my_dict = {',
206+
ReplType.terminal,
207+
wholeFileContent,
208+
);
209+
210+
// my_dict = { <----- smart shift+enter here
211+
// "key1": "value1",
212+
// "key2": "value2"
213+
// } <---- cursor should be here afterwards, hence offset 3
214+
commandManager
215+
.setup((c) => c.executeCommand('cursorMove', TypeMoq.It.isAny()))
216+
.callback((_, arg2) => {
217+
assert.deepEqual(arg2, {
218+
to: 'down',
219+
by: 'line',
220+
value: 3,
221+
});
222+
return Promise.resolve();
223+
})
224+
.verifiable(TypeMoq.Times.once());
225+
226+
commandManager
227+
.setup((c) => c.executeCommand('cursorEnd'))
228+
.returns(() => Promise.resolve())
229+
.verifiable(TypeMoq.Times.once());
230+
231+
const expectedSmartOutput = 'my_dict = {\n "key1": "value1",\n "key2": "value2"\n}\n';
232+
expect(actualSmartOutput).to.be.equal(expectedSmartOutput);
233+
commandManager.verifyAll();
234+
});
235+
}
232236

233237
// Do not perform smart selection when there is explicit selection
234238
test('Smart send should not perform smart selection when there is explicit selection', async () => {

0 commit comments

Comments
 (0)