Skip to content

Commit 0234dcc

Browse files
committed
installing and configuring nosetests
1 parent 69af301 commit 0234dcc

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

src/client/common/installer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,10 @@ export function disableLinter(product: Product) {
155155
pythonConfig.update(settingToDisable, false);
156156
}
157157

158-
function isPyTestInstalled(): Promise<boolean> {
158+
function isTestFrameworkInstalled(product: Product): Promise<boolean> {
159+
const fileToRun = product === Product.pytest ? 'py.test' : 'nosetests';
159160
const def = createDeferred<boolean>();
160-
execPythonFile('py.test', ['--version'], vscode.workspace.rootPath, false)
161+
execPythonFile(fileToRun, ['--version'], vscode.workspace.rootPath, false)
161162
.then(() => {
162163
def.resolve(true);
163164
}).catch(reason => {
@@ -171,8 +172,13 @@ function isPyTestInstalled(): Promise<boolean> {
171172
return def.promise;
172173
}
173174
function isProductInstalled(product: Product): Promise<boolean> {
174-
if (product === Product.pytest) {
175-
return isPyTestInstalled();
175+
switch (product) {
176+
case Product.pytest: {
177+
return isTestFrameworkInstalled(product);
178+
}
179+
case Product.nosetest: {
180+
return isTestFrameworkInstalled(product);
181+
}
176182
}
177183
throw new Error('Not supported');
178184
}
Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as vscode from 'vscode';
22
import { TestConfigurationManager } from '../common/testConfigurationManager';
3-
3+
import * as fs from 'fs';
4+
import * as path from 'path';
5+
import { Installer, Product } from '../../common/installer';
6+
47
export class ConfigurationManager extends TestConfigurationManager {
58
public enable(): Thenable<any> {
69
const pythonConfig = vscode.workspace.getConfiguration('python');
@@ -11,12 +14,47 @@ export class ConfigurationManager extends TestConfigurationManager {
1114
return pythonConfig.update('unitTest.nosetestsEnabled', false);
1215
}
1316

17+
private static configFilesExist(rootDir: string): Promise<boolean> {
18+
const promises = [
19+
new Promise<boolean>(resolve => {
20+
fs.exists(path.join(rootDir, '.noserc'), exists => { resolve(true); });
21+
}),
22+
new Promise<boolean>(resolve => {
23+
fs.exists(path.join(rootDir, 'nose.cfg'), exists => { resolve(true); });
24+
})];
25+
return Promise.all(promises).then(values => {
26+
return values.some(exists => exists);
27+
});
28+
}
1429
public configure(rootDir: string): Promise<any> {
15-
// TODO:
16-
// 1. Ask if pytest configuration exists
17-
// 2. Ask to create a py test config or use arguments
18-
// 3. Finally check if pytest is installed, if not prompt to install it
19-
// Do we have issues if nose is installed in a separate place (will nose be able to import the files??)
20-
return Promise.resolve();
30+
const args = [];
31+
const configFileOptionLabel = 'Use existing config file';
32+
const options: vscode.QuickPickItem[] = [];
33+
let installer = new Installer(this.outputChannel);
34+
return ConfigurationManager.configFilesExist(rootDir).then(configExists => {
35+
if (configExists) {
36+
options.push({
37+
label: configFileOptionLabel,
38+
description: '.noserc or nose.cfg'
39+
});
40+
}
41+
}).then(() => {
42+
return this.getTestDirs(rootDir);
43+
}).then(subDirs => {
44+
return this.selectTestDir(rootDir, subDirs, options);
45+
}).then(testDir => {
46+
if (typeof testDir === 'string' && testDir !== configFileOptionLabel) {
47+
args.push(testDir);
48+
}
49+
}).then(() => {
50+
return installer.isProductInstalled(Product.nosetest);
51+
}).then(installed => {
52+
if (!installed){
53+
return installer.installProduct(Product.nosetest);
54+
}
55+
}).then(() => {
56+
const pythonConfig = vscode.workspace.getConfiguration('python');
57+
return pythonConfig.update('unitTest.nosetestArgs', args);
58+
});
2159
}
2260
}

0 commit comments

Comments
 (0)