Skip to content

Commit

Permalink
Smart Send default value should be true (#23074)
Browse files Browse the repository at this point in the history
Forgot to set default value to true here:
#23067
It was true before removing experiment code since we had experiment to
100%, which effectively overrode the smart send setting value to True.
  • Loading branch information
anthonykim1 committed Mar 14, 2024
1 parent f624331 commit 028398e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
const startLineVal = activeEditor?.selection?.start.line ?? 0;
const endLineVal = activeEditor?.selection?.end.line ?? 0;
const emptyHighlightVal = activeEditor?.selection?.isEmpty ?? true;
let smartSendSettingsEnabledVal = false;
let smartSendSettingsEnabledVal = true;
const configuration = this.serviceContainer.get<IConfigurationService>(IConfigurationService);
if (configuration) {
const pythonSettings = configuration.getSettings(this.activeResourceService.getActiveResource());
Expand Down
46 changes: 45 additions & 1 deletion src/test/terminals/codeExecution/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SemVer } from 'semver';
import * as TypeMoq from 'typemoq';
import { Position, Range, Selection, TextDocument, TextEditor, TextLine, Uri } from 'vscode';
import {
IActiveResourceService,
IApplicationShell,
ICommandManager,
IDocumentManager,
Expand All @@ -23,6 +24,7 @@ import {
IProcessServiceFactory,
ObservableExecutionResult,
} from '../../../client/common/process/types';
import { IConfigurationService, IPythonSettings } from '../../../client/common/types';
import { Architecture } from '../../../client/common/utils/platform';
import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types';
import { IInterpreterService } from '../../../client/interpreter/contracts';
Expand All @@ -35,6 +37,7 @@ import { PYTHON_PATH } from '../../common';
const TEST_FILES_PATH = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'python_files', 'terminalExec');

suite('Terminal - Code Execution Helper', () => {
let activeResourceService: TypeMoq.IMock<IActiveResourceService>;
let documentManager: TypeMoq.IMock<IDocumentManager>;
let applicationShell: TypeMoq.IMock<IApplicationShell>;
let helper: ICodeExecutionHelper;
Expand All @@ -44,6 +47,8 @@ suite('Terminal - Code Execution Helper', () => {
let interpreterService: TypeMoq.IMock<IInterpreterService>;
let commandManager: TypeMoq.IMock<ICommandManager>;
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
let configurationService: TypeMoq.IMock<IConfigurationService>;
let pythonSettings: TypeMoq.IMock<IPythonSettings>;
const workingPython: PythonEnvironment = {
path: PYTHON_PATH,
version: new SemVer('3.6.6-final'),
Expand All @@ -57,13 +62,16 @@ suite('Terminal - Code Execution Helper', () => {
setup(() => {
const serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
commandManager = TypeMoq.Mock.ofType<ICommandManager>();
configurationService = TypeMoq.Mock.ofType<IConfigurationService>();
workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
documentManager = TypeMoq.Mock.ofType<IDocumentManager>();
applicationShell = TypeMoq.Mock.ofType<IApplicationShell>();
const envVariablesProvider = TypeMoq.Mock.ofType<IEnvironmentVariablesProvider>();
processService = TypeMoq.Mock.ofType<IProcessService>();
interpreterService = TypeMoq.Mock.ofType<IInterpreterService>();

activeResourceService = TypeMoq.Mock.ofType<IActiveResourceService>();
pythonSettings = TypeMoq.Mock.ofType<IPythonSettings>();
const resource = Uri.parse('a');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processService.setup((x: any) => x.then).returns(() => undefined);
interpreterService
Expand Down Expand Up @@ -95,6 +103,24 @@ suite('Terminal - Code Execution Helper', () => {
serviceContainer
.setup((c) => c.get(TypeMoq.It.isValue(IEnvironmentVariablesProvider), TypeMoq.It.isAny()))
.returns(() => envVariablesProvider.object);
serviceContainer
.setup((c) => c.get(TypeMoq.It.isValue(IConfigurationService)))
.returns(() => configurationService.object);
serviceContainer
.setup((c) => c.get(TypeMoq.It.isValue(IActiveResourceService)))
.returns(() => activeResourceService.object);
activeResourceService.setup((a) => a.getActiveResource()).returns(() => resource);
pythonSettings.setup((s) => s.REPL).returns(() => ({ enableREPLSmartSend: false, REPLSmartSend: false }));
configurationService.setup((x) => x.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);
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);
helper = new CodeExecutionHelper(serviceContainer.object);

document = TypeMoq.Mock.ofType<TextDocument>();
Expand All @@ -118,6 +144,15 @@ suite('Terminal - Code Execution Helper', () => {
});

async function ensureCodeIsNormalized(source: string, expectedSource: string) {
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()))
Expand All @@ -131,6 +166,15 @@ suite('Terminal - Code Execution Helper', () => {

['', '1', '2', '3', '4', '5', '6', '7', '8'].forEach((fileNameSuffix) => {
test(`Ensure code is normalized (Sample${fileNameSuffix})`, 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 code = await fs.readFile(path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_raw.py`), 'utf8');
const expectedCode = await fs.readFile(
path.join(TEST_FILES_PATH, `sample${fileNameSuffix}_normalized_selection.py`),
Expand Down

0 comments on commit 028398e

Please sign in to comment.