forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportToPython.test.ts
More file actions
46 lines (43 loc) · 2.19 KB
/
exportToPython.test.ts
File metadata and controls
46 lines (43 loc) · 2.19 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
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.
// tslint:disable: no-var-requires no-require-imports no-invalid-this no-any
import { assert } from 'chai';
import * as path from 'path';
import { CancellationTokenSource, Uri } from 'vscode';
import { IDocumentManager } from '../../../client/common/application/types';
import { ExportFormat, IExport } from '../../../client/datascience/export/types';
import { IDataScienceFileSystem } from '../../../client/datascience/types';
import { IExtensionTestApi } from '../../common';
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
import { closeActiveWindows, initialize } from '../../initialize';
suite('DataScience - Export Python', () => {
let api: IExtensionTestApi;
suiteSetup(async function () {
this.timeout(10_000);
api = await initialize();
// Export to Python tests require jupyter to run. Othewrise can't
// run any of our variable execution code
const isRollingBuild = process.env ? process.env.VSCODE_PYTHON_ROLLING !== undefined : false;
if (!isRollingBuild) {
// tslint:disable-next-line:no-console
console.log('Skipping Export to Python tests. Requires python environment');
// tslint:disable-next-line:no-invalid-this
this.skip();
}
});
teardown(closeActiveWindows);
suiteTeardown(closeActiveWindows);
test('Export To Python', async () => {
const fileSystem = api.serviceContainer.get<IDataScienceFileSystem>(IDataScienceFileSystem);
const exportToPython = api.serviceContainer.get<IExport>(IExport, ExportFormat.python);
const target = Uri.file((await fileSystem.createTemporaryLocalFile('.py')).filePath);
const token = new CancellationTokenSource();
await exportToPython.export(
Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'datascience', 'export', 'test.ipynb')),
target,
token.token
);
const documentManager = api.serviceContainer.get<IDocumentManager>(IDocumentManager);
assert.include(documentManager.activeTextEditor!.document.getText(), 'tim = 1');
});
});