forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatascience.smoke.test.ts
More file actions
84 lines (72 loc) · 3.15 KB
/
datascience.smoke.test.ts
File metadata and controls
84 lines (72 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:max-func-body-length no-invalid-this no-any
import * as fs from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';
import { openFile, setAutoSaveDelayInWorkspaceRoot, waitForCondition } from '../common';
import { EXTENSION_ROOT_DIR_FOR_TESTS, IS_SMOKE_TEST } from '../constants';
import { noop, sleep } from '../core';
import { closeActiveWindows, initialize, initializeTest } from '../initialize';
const timeoutForCellToRun = 3 * 60 * 1_000;
suite('Smoke Test: Interactive Window', () => {
suiteSetup(async function() {
if (!IS_SMOKE_TEST) {
return this.skip();
}
await initialize();
await setAutoSaveDelayInWorkspaceRoot(1);
});
setup(initializeTest);
suiteTeardown(closeActiveWindows);
teardown(closeActiveWindows);
test('Run Cell in interactive window', async () => {
const file = path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'test',
'pythonFiles',
'datascience',
'simple_note_book.py'
);
const outputFile = path.join(path.dirname(file), 'ds.log');
if (await fs.pathExists(outputFile)) {
await fs.unlink(outputFile);
}
const textDocument = await openFile(file);
// Wait for code lenses to get detected.
await sleep(1_000);
await vscode.commands.executeCommand<void>('python.datascience.runallcells', textDocument.uri);
const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile);
await waitForCondition(checkIfFileHasBeenCreated, timeoutForCellToRun, `"${outputFile}" file not created`);
}).timeout(timeoutForCellToRun);
test('Run Cell in native editor', async () => {
const file = path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'test',
'pythonFiles',
'datascience',
'simple_nb.ipynb'
);
const fileContents = await fs.readFile(file, { encoding: 'utf-8' });
const outputFile = path.join(path.dirname(file), 'ds_n.log');
await fs.writeFile(file, fileContents.replace("'ds_n.log'", `'${outputFile.replace(/\\/g, '/')}'`), {
encoding: 'utf-8'
});
if (await fs.pathExists(outputFile)) {
await fs.unlink(outputFile);
}
// Ignore exceptions (as native editor closes the document as soon as its opened);
await openFile(file).catch(noop);
// Wait for 15 seconds for notebook to launch.
// Unfortunately there's no way to know for sure it has completely loaded.
await sleep(15_000);
await vscode.commands.executeCommand<void>('python.datascience.notebookeditor.runallcells');
const checkIfFileHasBeenCreated = () => fs.pathExists(outputFile);
await waitForCondition(checkIfFileHasBeenCreated, timeoutForCellToRun, `"${outputFile}" file not created`);
// Give time for the file to be saved before we shutdown
await sleep(300);
}).timeout(timeoutForCellToRun);
});