Skip to content

Commit 614985a

Browse files
committed
feedback
1 parent 5fcb76c commit 614985a

File tree

1 file changed

+18
-51
lines changed

1 file changed

+18
-51
lines changed

src/standalone/import-export/importTracker.unit.test.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ import {
1717
} from '../../platform/common/constants';
1818
import { dispose } from '../../platform/common/utils/lifecycle';
1919
import { IDisposable } from '../../platform/common/types';
20-
import { getTelemetrySafeHashedString } from '../../platform/telemetry/helpers';
2120
import { ImportTracker } from './importTracker';
22-
import { ResourceTypeTelemetryProperty, getTelemetryReporter } from '../../telemetry';
21+
import { getTelemetryReporter } from '../../telemetry';
2322
import { createMockedNotebookDocument } from '../../test/datascience/editor-integration/helpers';
2423
import { mockedVSCodeNamespaces } from '../../test/vscode-mock';
2524
import { EmptyEvent } from '../../platform/common/utils/events';
@@ -32,15 +31,6 @@ suite(`Import Tracker`, async () => {
3231
let onDidOpenNbEvent: EventEmitter<NotebookDocument>;
3332
let onDidCloseNbEvent: EventEmitter<NotebookDocument>;
3433
let onDidSaveNbEvent: EventEmitter<NotebookDocument>;
35-
let pandasHash: string;
36-
let elephasHash: string;
37-
let kerasHash: string;
38-
let pysparkHash: string;
39-
let sparkdlHash: string;
40-
let numpyHash: string;
41-
let scipyHash: string;
42-
let sklearnHash: string;
43-
let randomHash: string;
4434
let disposables: IDisposable[] = [];
4535
let clock: fakeTimers.InstalledClock;
4636

@@ -50,11 +40,7 @@ suite(`Import Tracker`, async () => {
5040
public static measures: {}[] = [];
5141

5242
// Telemetry is now disabled, so this method just ensures the tracker doesn't crash
53-
public static async expectHashes(
54-
when: 'onExecution' | 'onOpenCloseOrSave' = 'onOpenCloseOrSave',
55-
resourceType: ResourceTypeTelemetryProperty['resourceType'] = undefined,
56-
...hashes: string[]
57-
) {
43+
public static async expectHashes() {
5844
clock.tick(1);
5945
void clock.runAllAsync();
6046
// Telemetry verification removed as telemetry is now disabled
@@ -66,17 +52,6 @@ suite(`Import Tracker`, async () => {
6652
Reporter.measures.push(measures!);
6753
}
6854
}
69-
suiteSetup(async () => {
70-
pandasHash = await getTelemetrySafeHashedString('pandas');
71-
elephasHash = await getTelemetrySafeHashedString('elephas');
72-
kerasHash = await getTelemetrySafeHashedString('keras');
73-
pysparkHash = await getTelemetrySafeHashedString('pyspark');
74-
sparkdlHash = await getTelemetrySafeHashedString('sparkdl');
75-
numpyHash = await getTelemetrySafeHashedString('numpy');
76-
scipyHash = await getTelemetrySafeHashedString('scipy');
77-
sklearnHash = await getTelemetrySafeHashedString('sklearn');
78-
randomHash = await getTelemetrySafeHashedString('random');
79-
});
8055
setup(() => {
8156
const reporter = getTelemetryReporter();
8257
sinon.stub(reporter, 'sendTelemetryEvent').callsFake((eventName: string, properties?: {}, measures?: {}) => {
@@ -125,21 +100,21 @@ suite(`Import Tracker`, async () => {
125100
const nb = createMockedNotebookDocument([{ kind: NotebookCellKind.Code, languageId: 'python', value: code }]);
126101
onDidOpenNbEvent.fire(nb);
127102

128-
await Reporter.expectHashes('onOpenCloseOrSave', 'notebook', pandasHash);
103+
await Reporter.expectHashes();
129104
});
130105
test('Close document', async () => {
131106
const code = `import pandas\r\n`;
132107
const nb = createMockedNotebookDocument([{ kind: NotebookCellKind.Code, languageId: 'python', value: code }]);
133108
onDidCloseNbEvent.fire(nb);
134109

135-
await Reporter.expectHashes('onOpenCloseOrSave', 'notebook', pandasHash);
110+
await Reporter.expectHashes();
136111
});
137112
test('Save document', async () => {
138113
const code = `import pandas\r\n`;
139114
const nb = createMockedNotebookDocument([{ kind: NotebookCellKind.Code, languageId: 'python', value: code }]);
140115
onDidSaveNbEvent.fire(nb);
141116

142-
await Reporter.expectHashes('onOpenCloseOrSave', 'notebook', pandasHash);
117+
await Reporter.expectHashes();
143118
});
144119

145120
test('Already opened documents', async () => {
@@ -149,13 +124,9 @@ suite(`Import Tracker`, async () => {
149124

150125
await importTracker.activate();
151126

152-
await Reporter.expectHashes('onOpenCloseOrSave', 'notebook', pandasHash);
127+
await Reporter.expectHashes();
153128
});
154-
async function testImports(
155-
code: string,
156-
notebookType: typeof JupyterNotebookView | typeof InteractiveWindowView,
157-
...expectedPackageHashes: string[]
158-
) {
129+
async function testImports(code: string, notebookType: typeof JupyterNotebookView | typeof InteractiveWindowView) {
159130
const nb = createMockedNotebookDocument(
160131
[{ kind: NotebookCellKind.Code, languageId: 'python', value: code }],
161132
undefined,
@@ -166,11 +137,7 @@ suite(`Import Tracker`, async () => {
166137

167138
await importTracker.activate();
168139

169-
await Reporter.expectHashes(
170-
'onOpenCloseOrSave',
171-
notebookType === 'jupyter-notebook' ? 'notebook' : 'interactive',
172-
...expectedPackageHashes
173-
);
140+
await Reporter.expectHashes();
174141
}
175142
test('from <pkg>._ import _, _', async () => {
176143
const code = `
@@ -192,7 +159,7 @@ suite(`Import Tracker`, async () => {
192159
193160
weights = adapter.retrieve_keras_weights(java_model)
194161
model.set_weights(weights)`;
195-
await testImports(code, 'jupyter-notebook', elephasHash, kerasHash);
162+
await testImports(code, 'jupyter-notebook');
196163
});
197164

198165
test('from <pkg>._ import _', async () => {
@@ -213,7 +180,7 @@ suite(`Import Tracker`, async () => {
213180
evaluator = MulticlassClassificationEvaluator(metricName="accuracy")
214181
print("Training set accuracy = " + str(evaluator.evaluate(predictionAndLabels)))`;
215182

216-
await testImports(code, 'interactive', pysparkHash, sparkdlHash);
183+
await testImports(code, 'interactive');
217184
});
218185

219186
test('import <pkg> as _', async () => {
@@ -229,7 +196,7 @@ suite(`Import Tracker`, async () => {
229196
df.Age = categories
230197
return df`;
231198

232-
await testImports(code, 'interactive', pandasHash, numpyHash, randomHash);
199+
await testImports(code, 'interactive');
233200
});
234201

235202
test('from <pkg> import _', async () => {
@@ -243,12 +210,12 @@ suite(`Import Tracker`, async () => {
243210
y = np.array([r * np.sin(theta) for r in radius])
244211
z = np.array([drumhead_height(1, 1, r, theta, 0.5) for r in radius])`;
245212

246-
await testImports(code, 'interactive', scipyHash);
213+
await testImports(code, 'interactive');
247214
});
248215

249216
test('from <pkg> import _ as _', async () => {
250217
const code = `from pandas import DataFrame as df`;
251-
await testImports(code, 'jupyter-notebook', pandasHash);
218+
await testImports(code, 'jupyter-notebook');
252219
});
253220

254221
test('import <pkg1>, <pkg2>', async () => {
@@ -261,7 +228,7 @@ suite(`Import Tracker`, async () => {
261228
x = np.array([r * np.cos(theta) for r in radius])
262229
y = np.array([r * np.sin(theta) for r in radius])
263230
z = np.array([drumhead_height(1, 1, r, theta, 0.5) for r in radius])`;
264-
await testImports(code, 'interactive', sklearnHash, pandasHash);
231+
await testImports(code, 'interactive');
265232
});
266233

267234
test('Import from within a function', async () => {
@@ -275,14 +242,14 @@ suite(`Import Tracker`, async () => {
275242
y = np.array([r * np.sin(theta) for r in radius])
276243
z = np.array([drumhead_height(1, 1, r, theta, 0.5) for r in radius])`;
277244

278-
await testImports(code, 'interactive', sklearnHash);
245+
await testImports(code, 'interactive');
279246
});
280247

281248
test('Do not send the same package twice', async () => {
282249
const code = `
283250
import pandas
284251
import pandas`;
285-
await testImports(code, 'interactive', pandasHash);
252+
await testImports(code, 'interactive');
286253
});
287254

288255
test('Ignore relative imports', async () => {
@@ -294,7 +261,7 @@ suite(`Import Tracker`, async () => {
294261
const nb = createMockedNotebookDocument([{ kind: NotebookCellKind.Code, languageId: 'python', value: code }]);
295262
notebookCellExecutions.changeCellState(nb.cellAt(0), NotebookCellExecutionState.Pending);
296263

297-
await Reporter.expectHashes('onExecution', 'notebook', numpyHash);
264+
await Reporter.expectHashes();
298265

299266
// Executing the cell multiple will have no effect, the telemetry is only sent once.
300267
notebookCellExecutions.changeCellState(nb.cellAt(0), NotebookCellExecutionState.Pending);
@@ -304,6 +271,6 @@ suite(`Import Tracker`, async () => {
304271
notebookCellExecutions.changeCellState(nb.cellAt(0), NotebookCellExecutionState.Executing);
305272
notebookCellExecutions.changeCellState(nb.cellAt(0), NotebookCellExecutionState.Idle);
306273

307-
await Reporter.expectHashes('onExecution', 'notebook', numpyHash);
274+
await Reporter.expectHashes();
308275
});
309276
});

0 commit comments

Comments
 (0)