Skip to content

Commit 9228965

Browse files
committed
do not prompt if config file exists
1 parent a03ab26 commit 9228965

2 files changed

Lines changed: 42 additions & 50 deletions

File tree

src/client/unittests/nosetest/testConfigurationManager.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TestConfigurationManager } from '../common/testConfigurationManager';
33
import * as fs from 'fs';
44
import * as path from 'path';
55
import { Installer, Product } from '../../common/installer';
6-
6+
77
export class ConfigurationManager extends TestConfigurationManager {
88
public enable(): Thenable<any> {
99
const pythonConfig = vscode.workspace.getConfiguration('python');
@@ -14,42 +14,36 @@ export class ConfigurationManager extends TestConfigurationManager {
1414
return pythonConfig.update('unitTest.nosetestsEnabled', false);
1515
}
1616

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-
})];
17+
private static configFilesExist(rootDir: string): Promise<string[]> {
18+
const promises = ['.noserc', 'nose.cfg'].map(cfg => {
19+
return new Promise<string>(resolve => {
20+
fs.exists(path.join(rootDir, cfg), exists => { resolve(exists ? cfg : ''); });
21+
});
22+
});
2523
return Promise.all(promises).then(values => {
26-
return values.some(exists => exists);
24+
return values.filter(exists => exists.length > 0);
2725
});
2826
}
2927
public configure(rootDir: string): Promise<any> {
3028
const args = [];
3129
const configFileOptionLabel = 'Use existing config file';
32-
const options: vscode.QuickPickItem[] = [];
3330
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);
31+
return ConfigurationManager.configFilesExist(rootDir).then(configFiles => {
32+
if (configFiles.length > 0) {
33+
return Promise.resolve();
4834
}
35+
36+
return this.getTestDirs(rootDir).then(subDirs => {
37+
return this.selectTestDir(rootDir, subDirs);
38+
}).then(testDir => {
39+
if (typeof testDir === 'string' && testDir !== configFileOptionLabel) {
40+
args.push(testDir);
41+
}
42+
});
4943
}).then(() => {
5044
return installer.isProductInstalled(Product.nosetest);
5145
}).then(installed => {
52-
if (!installed){
46+
if (!installed) {
5347
return installer.installProduct(Product.nosetest);
5448
}
5549
}).then(() => {

src/client/unittests/pytest/testConfigurationManager.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,43 @@ export class ConfigurationManager extends TestConfigurationManager {
1414
return pythonConfig.update('unitTest.pyTestEnabled', false);
1515
}
1616

17-
private static configFilesExist(rootDir: string): Promise<boolean> {
18-
const promises = [
19-
new Promise<boolean>(resolve => {
20-
fs.exists(path.join(rootDir, 'pytest.ini'), exists => { resolve(true); });
21-
}),
22-
new Promise<boolean>(resolve => {
23-
fs.exists(path.join(rootDir, 'tox.ini'), exists => { resolve(true); });
24-
}),
25-
new Promise<boolean>(resolve => {
26-
fs.exists(path.join(rootDir, 'setup.cfg'), exists => { resolve(true); });
27-
})];
17+
private static configFilesExist(rootDir: string): Promise<string[]> {
18+
const promises = ['pytest.ini', 'tox.ini', 'setup.cfg'].map(cfg => {
19+
return new Promise<string>(resolve => {
20+
fs.exists(path.join(rootDir, cfg), exists => { resolve(exists ? cfg : ''); });
21+
});
22+
});
2823
return Promise.all(promises).then(values => {
29-
return values.some(exists => exists);
24+
return values.filter(exists => exists.length > 0);
3025
});
3126
}
3227
public configure(rootDir: string): Promise<any> {
3328
const args = [];
3429
const configFileOptionLabel = 'Use existing config file';
3530
const options: vscode.QuickPickItem[] = [];
3631
let installer = new Installer(this.outputChannel);
37-
return ConfigurationManager.configFilesExist(rootDir).then(configExists => {
38-
if (configExists) {
32+
return ConfigurationManager.configFilesExist(rootDir).then(configFiles => {
33+
if (configFiles.length > 0 && configFiles.length !== 1 && configFiles[0] !== 'setup.cfg') {
34+
return Promise.resolve();
35+
}
36+
37+
if (configFiles.length === 1 && configFiles[0] === 'setup.cfg') {
3938
options.push({
4039
label: configFileOptionLabel,
41-
description: 'pytest.ini, tox.ini or setup.cfg'
40+
description: 'setup.cfg'
4241
});
4342
}
44-
}).then(() => {
45-
return this.getTestDirs(rootDir);
46-
}).then(subDirs => {
47-
return this.selectTestDir(rootDir, subDirs, options);
48-
}).then(testDir => {
49-
if (typeof testDir === 'string' && testDir !== configFileOptionLabel) {
50-
args.push(testDir);
51-
}
43+
return this.getTestDirs(rootDir).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+
});
5250
}).then(() => {
5351
return installer.isProductInstalled(Product.pytest);
5452
}).then(installed => {
55-
if (!installed){
53+
if (!installed) {
5654
return installer.installProduct(Product.pytest);
5755
}
5856
}).then(() => {

0 commit comments

Comments
 (0)