forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnosetest.test.ts
More file actions
66 lines (61 loc) · 2.88 KB
/
Copy pathnosetest.test.ts
File metadata and controls
66 lines (61 loc) · 2.88 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
import * as assert from 'assert';
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { CommandSource } from '../../client/unittests/common/constants';
import { ITestManagerFactory } from '../../client/unittests/common/types';
import { rootWorkspaceUri, updateSetting } from '../common';
import { initialize, initializeTest, IS_MULTI_ROOT_TEST } from './../initialize';
import { UnitTestIocContainer } from './serviceRegistry';
const UNITTEST_TEST_FILES_PATH = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'testFiles', 'noseFiles');
const UNITTEST_SINGLE_TEST_FILE_PATH = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'testFiles', 'single');
const filesToDelete = [
path.join(UNITTEST_TEST_FILES_PATH, '.noseids'),
path.join(UNITTEST_SINGLE_TEST_FILE_PATH, '.noseids')
];
// tslint:disable-next-line:max-func-body-length
suite('Unit Tests - nose - discovery against actual python process', () => {
let ioc: UnitTestIocContainer;
const configTarget = IS_MULTI_ROOT_TEST ? vscode.ConfigurationTarget.WorkspaceFolder : vscode.ConfigurationTarget.Workspace;
suiteSetup(async () => {
filesToDelete.forEach(file => {
if (fs.existsSync(file)) {
fs.unlinkSync(file);
}
});
await updateSetting('unitTest.nosetestArgs', [], rootWorkspaceUri, configTarget);
await initialize();
});
suiteTeardown(async () => {
await updateSetting('unitTest.nosetestArgs', [], rootWorkspaceUri, configTarget);
filesToDelete.forEach(file => {
if (fs.existsSync(file)) {
fs.unlinkSync(file);
}
});
});
setup(async () => {
await initializeTest();
initializeDI();
});
teardown(async () => {
ioc.dispose();
await updateSetting('unitTest.nosetestArgs', [], rootWorkspaceUri, configTarget);
});
function initializeDI() {
ioc = new UnitTestIocContainer();
ioc.registerCommonTypes();
ioc.registerProcessTypes();
ioc.registerUnitTestTypes();
ioc.registerVariableTypes();
}
test('Discover Tests (single test file)', async () => {
const factory = ioc.serviceContainer.get<ITestManagerFactory>(ITestManagerFactory);
const testManager = factory('nosetest', rootWorkspaceUri, UNITTEST_SINGLE_TEST_FILE_PATH);
const tests = await testManager.discoverTests(CommandSource.ui, true, true);
assert.equal(tests.testFiles.length, 2, 'Incorrect number of test files');
assert.equal(tests.testFunctions.length, 6, 'Incorrect number of test functions');
assert.equal(tests.testSuites.length, 2, 'Incorrect number of test suites');
assert.equal(tests.testFiles.some(t => t.name === path.join('tests', 'test_one.py') && t.nameToRun === t.name), true, 'Test File not found');
});
});