Skip to content

Commit b4651e0

Browse files
committed
DRY tests
1 parent 114b751 commit b4651e0

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/kernels/raw/launcher/kernelEnvVarsService.unit.test.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ suite('Kernel Environment Variables Service', () => {
5757
settings = mock(JupyterSettings);
5858
sqlIntegrationEnvVars = mock<SqlIntegrationEnvironmentVariablesProvider>();
5959
when(configService.getSettings(anything())).thenReturn(instance(settings));
60-
kernelVariablesService = new KernelEnvironmentVariablesService(
61-
instance(interpreterService),
62-
instance(envActivation),
63-
variablesService,
64-
instance(customVariablesService),
65-
instance(configService),
66-
instance(sqlIntegrationEnvVars)
67-
);
6860
if (process.platform === 'win32') {
6961
// Win32 will generate upper case all the time
7062
const entries = Object.entries(process.env);
@@ -76,9 +68,34 @@ suite('Kernel Environment Variables Service', () => {
7668
processEnv = process.env;
7769
}
7870
processPath = Object.keys(processEnv).find((k) => k.toLowerCase() == 'path');
71+
kernelVariablesService = buildKernelEnvVarsService();
7972
});
73+
8074
teardown(() => Object.assign(process.env, originalEnvVars));
8175

76+
/**
77+
* Helper factory function to build KernelEnvironmentVariablesService with optional overrides.
78+
* @param overrides Optional overrides for the service dependencies
79+
* @returns A new instance of KernelEnvironmentVariablesService
80+
*/
81+
function buildKernelEnvVarsService(overrides?: {
82+
sqlIntegrationEnvVars?: SqlIntegrationEnvironmentVariablesProvider | undefined;
83+
}): KernelEnvironmentVariablesService {
84+
const sqlProvider =
85+
overrides && 'sqlIntegrationEnvVars' in overrides
86+
? overrides.sqlIntegrationEnvVars
87+
: instance(sqlIntegrationEnvVars);
88+
89+
return new KernelEnvironmentVariablesService(
90+
instance(interpreterService),
91+
instance(envActivation),
92+
variablesService,
93+
instance(customVariablesService),
94+
instance(configService),
95+
sqlProvider
96+
);
97+
}
98+
8299
test('Python Interpreter path trumps process', async () => {
83100
when(envActivation.getActivatedEnvironmentVariables(anything(), anything(), anything())).thenResolve({
84101
PATH: 'foobar'
@@ -381,14 +398,7 @@ suite('Kernel Environment Variables Service', () => {
381398
).thenResolve();
382399

383400
// Create service without SQL integration provider
384-
const serviceWithoutSql = new KernelEnvironmentVariablesService(
385-
instance(interpreterService),
386-
instance(envActivation),
387-
variablesService,
388-
instance(customVariablesService),
389-
instance(configService),
390-
undefined
391-
);
401+
const serviceWithoutSql = buildKernelEnvVarsService({ sqlIntegrationEnvVars: undefined });
392402

393403
const vars = await serviceWithoutSql.getEnvironmentVariables(resource, interpreter, kernelSpec);
394404

0 commit comments

Comments
 (0)