Skip to content

Commit

Permalink
add more test and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Nov 8, 2024
1 parent 73952bb commit 2cc7007
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 33 additions & 4 deletions src/test/terminals/codeExecution/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IActiveResourceService>;
let documentManager: TypeMoq.IMock<IDocumentManager>;
Expand All @@ -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,
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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);
});
});
Expand Down

0 comments on commit 2cc7007

Please sign in to comment.