Skip to content

Commit

Permalink
added and got test WORKING
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Nov 7, 2024
1 parent 25b2f17 commit 73952bb
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/test/terminals/codeExecution/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -49,10 +50,11 @@ suite('Terminal - Code Execution Helper', () => {
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
let configurationService: TypeMoq.IMock<IConfigurationService>;
let pythonSettings: TypeMoq.IMock<IPythonSettings>;
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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
});
Expand Down

0 comments on commit 73952bb

Please sign in to comment.