55import * as fs from 'fs-extra' ;
66import * as path from 'path' ;
77import { CancellationTokenSource , Position , Uri , window , workspace } from 'vscode' ;
8- import { IProcessServiceFactory , IPythonExecutionFactory } from '../../client/common/process/types' ;
8+ import { IProcessServiceFactory } from '../../client/common/process/types' ;
99import { AutoPep8Formatter } from '../../client/formatters/autoPep8Formatter' ;
1010import { BlackFormatter } from '../../client/formatters/blackFormatter' ;
1111import { YapfFormatter } from '../../client/formatters/yapfFormatter' ;
@@ -27,9 +27,11 @@ const workspaceRootPath = path.join(__dirname, '..', '..', '..', 'src', 'test');
2727const originalUnformattedFile = path . join ( formatFilesPath , 'fileToFormat.py' ) ;
2828
2929const autoPep8FileToFormat = path . join ( formatFilesPath , 'autoPep8FileToFormat.py' ) ;
30+ const autoPep8Formatted = path . join ( formatFilesPath , 'autoPep8Formatted.py' ) ;
3031const blackFileToFormat = path . join ( formatFilesPath , 'blackFileToFormat.py' ) ;
31- const blackReferenceFile = path . join ( formatFilesPath , 'blackFileReference .py' ) ;
32+ const blackFormatted = path . join ( formatFilesPath , 'blackFormatted .py' ) ;
3233const yapfFileToFormat = path . join ( formatFilesPath , 'yapfFileToFormat.py' ) ;
34+ const yapfFormatted = path . join ( formatFilesPath , 'yapfFormatted.py' ) ;
3335
3436let formattedYapf = '' ;
3537let formattedBlack = '' ;
@@ -42,31 +44,12 @@ suite('Formatting - General', () => {
4244 suiteSetup ( async ( ) => {
4345 await initialize ( ) ;
4446 initializeDI ( ) ;
45- [ autoPep8FileToFormat , blackFileToFormat , blackReferenceFile , yapfFileToFormat ] . forEach ( file => {
47+ [ autoPep8FileToFormat , blackFileToFormat , yapfFileToFormat ] . forEach ( file => {
4648 fs . copySync ( originalUnformattedFile , file , { overwrite : true } ) ;
4749 } ) ;
48- fs . ensureDirSync ( path . dirname ( autoPep8FileToFormat ) ) ;
49- const pythonProcess = await ioc . serviceContainer
50- . get < IPythonExecutionFactory > ( IPythonExecutionFactory )
51- . create ( { resource : Uri . file ( workspaceRootPath ) } ) ;
52- const yapf = pythonProcess . execModule ( 'yapf' , [ originalUnformattedFile ] , { cwd : workspaceRootPath } ) ;
53- const autoPep8 = pythonProcess . execModule ( 'autopep8' , [ originalUnformattedFile ] , { cwd : workspaceRootPath } ) ;
54- const formatters = [ yapf , autoPep8 ] ;
55- if ( await formattingTestIsBlackSupported ( ) ) {
56- // Black doesn't support emitting only to stdout; it either works
57- // through a pipe, emits a diff, or rewrites the file in-place.
58- // Thus it's easier to let it do its in-place rewrite and then
59- // read the reference file from there.
60- const black = pythonProcess . execModule ( 'black' , [ blackReferenceFile ] , { cwd : workspaceRootPath } ) ;
61- formatters . push ( black ) ;
62- }
63- await Promise . all ( formatters ) . then ( async formattedResults => {
64- formattedYapf = formattedResults [ 0 ] . stdout ;
65- formattedAutoPep8 = formattedResults [ 1 ] . stdout ;
66- if ( await formattingTestIsBlackSupported ( ) ) {
67- formattedBlack = fs . readFileSync ( blackReferenceFile ) . toString ( ) ;
68- }
69- } ) ;
50+ formattedYapf = fs . readFileSync ( yapfFormatted ) . toString ( ) ;
51+ formattedAutoPep8 = fs . readFileSync ( autoPep8Formatted ) . toString ( ) ;
52+ formattedBlack = fs . readFileSync ( blackFormatted ) . toString ( ) ;
7053 } ) ;
7154
7255 async function formattingTestIsBlackSupported ( ) : Promise < boolean > {
@@ -81,7 +64,7 @@ suite('Formatting - General', () => {
8164 initializeDI ( ) ;
8265 } ) ;
8366 suiteTeardown ( async ( ) => {
84- [ autoPep8FileToFormat , blackFileToFormat , blackReferenceFile , yapfFileToFormat ] . forEach ( file => {
67+ [ autoPep8FileToFormat , blackFileToFormat , yapfFileToFormat ] . forEach ( file => {
8568 if ( fs . existsSync ( file ) ) {
8669 fs . unlinkSync ( file ) ;
8770 }
0 commit comments