From 2cc70079dc7206e98fedbd1a790a702d0f863703 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 8 Nov 2024 09:39:47 -0800 Subject: [PATCH] add more test and clean up --- src/client/terminals/codeExecution/helper.ts | 1 - .../terminals/codeExecution/helper.test.ts | 37 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 9c1ca3ab1598..49fdd59a00c0 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -120,7 +120,6 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { } // For new _pyrepl for Python3.13 and above, we need to send code via bracketed paste mode. if (object.attach_bracket_paste) { - // return `\u001b[200~${object.normalized.trim()}\u001b[201~`; let trimmedNormalized = object.normalized.replace(/\n$/, ''); if (trimmedNormalized.endsWith(':\n')) { // In case where statement is unfinished via :, truncate so auto-indentation lands nicely. diff --git a/src/test/terminals/codeExecution/helper.test.ts b/src/test/terminals/codeExecution/helper.test.ts index 8a45ed77a922..7a3171ccf836 100644 --- a/src/test/terminals/codeExecution/helper.test.ts +++ b/src/test/terminals/codeExecution/helper.test.ts @@ -36,7 +36,7 @@ import { ICodeExecutionHelper } from '../../../client/terminals/types'; import { PYTHON_PATH } from '../../common'; const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'python_files', 'terminalExec'); -// TODO: tests for 3.13 relevant sequences + suite('Terminal - Code Execution Helper', () => { let activeResourceService: TypeMoq.IMock; let documentManager: TypeMoq.IMock; @@ -53,8 +53,8 @@ suite('Terminal - Code Execution Helper', () => { let jsonParseStub: sinon.SinonStub; const workingPython: PythonEnvironment = { path: PYTHON_PATH, - version: new SemVer('3.13.0'), - sysVersion: '3.13.0', + version: new SemVer('3.6.6-final'), + sysVersion: '1.0.0.0', sysPrefix: 'Python', displayName: 'Python', envType: EnvironmentType.Unknown, @@ -166,6 +166,36 @@ suite('Terminal - Code Execution Helper', () => { jsonParseStub.restore(); }); + test('normalizeLines should not attach bracketed paste for < 3.13', async () => { + jsonParseStub = sinon.stub(JSON, 'parse'); + const mockResult = { + normalized: 'print("Looks like you are not on 3.13")', + attach_bracket_paste: false, + }; + jsonParseStub.returns(mockResult); + + configurationService + .setup((c) => c.getSettings(TypeMoq.It.isAny())) + .returns({ + REPL: { + EnableREPLSmartSend: false, + REPLSmartSend: false, + }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any); + const actualProcessService = new ProcessService(); + processService + .setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .returns((file, args, options) => + actualProcessService.execObservable.apply(actualProcessService, [file, args, options]), + ); + + const result = await helper.normalizeLines('print("Looks like you are not on 3.13")'); + + expect(result).to.equal('print("Looks like you are not on 3.13")'); + jsonParseStub.restore(); + }); + test('normalizeLines should call normalizeSelection.py', async () => { jsonParseStub.restore(); let execArgs = ''; @@ -219,7 +249,6 @@ suite('Terminal - Code Execution Helper', () => { path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_normalized_selection.py`), 'utf8', ); - // python3 -m pythonFiles.tests await ensureCodeIsNormalized(code, expectedCode); }); });