From 73952bbe2479fd97cb619531f09d11a8eca253b1 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 6 Nov 2024 20:05:04 -0800 Subject: [PATCH] added and got test WORKING --- .../terminals/codeExecution/helper.test.ts | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/test/terminals/codeExecution/helper.test.ts b/src/test/terminals/codeExecution/helper.test.ts index 64694ee2c6d9..8a45ed77a922 100644 --- a/src/test/terminals/codeExecution/helper.test.ts +++ b/src/test/terminals/codeExecution/helper.test.ts @@ -8,6 +8,7 @@ import * as path from 'path'; import { SemVer } from 'semver'; import * as TypeMoq from 'typemoq'; import { Position, Range, Selection, TextDocument, TextEditor, TextLine, Uri } from 'vscode'; +import * as sinon from 'sinon'; import * as fs from '../../../client/common/platform/fs-paths'; import { IActiveResourceService, @@ -49,10 +50,11 @@ suite('Terminal - Code Execution Helper', () => { let workspaceService: TypeMoq.IMock; let configurationService: TypeMoq.IMock; let pythonSettings: TypeMoq.IMock; + let jsonParseStub: sinon.SinonStub; const workingPython: PythonEnvironment = { path: PYTHON_PATH, - version: new SemVer('3.6.6-final'), - sysVersion: '1.0.0.0', + version: new SemVer('3.13.0'), + sysVersion: '3.13.0', sysPrefix: 'Python', displayName: 'Python', envType: EnvironmentType.Unknown, @@ -134,7 +136,38 @@ suite('Terminal - Code Execution Helper', () => { editor.setup((e) => e.document).returns(() => document.object); }); + test('normalizeLines should handle attach_bracket_paste correctly', async () => { + 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]), + ); + + jsonParseStub = sinon.stub(JSON, 'parse'); + const mockResult = { + normalized: 'print("Looks like you are on 3.13")', + attach_bracket_paste: true, + }; + jsonParseStub.returns(mockResult); + + const result = await helper.normalizeLines('print("Looks like you are on 3.13")'); + + expect(result).to.equal(`\u001b[200~print("Looks like you are on 3.13")\u001b[201~`); + jsonParseStub.restore(); + }); + test('normalizeLines should call normalizeSelection.py', async () => { + jsonParseStub.restore(); let execArgs = ''; processService @@ -186,7 +219,7 @@ suite('Terminal - Code Execution Helper', () => { path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_normalized_selection.py`), 'utf8', ); - + // python3 -m pythonFiles.tests await ensureCodeIsNormalized(code, expectedCode); }); });