11import * as vscode from 'vscode' ;
22import { 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+
47export 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