11
2- // Note: This example test is leveraging the Mocha test framework.
3- // Please refer to their documentation on https://mochajs.org/ for help.
2+ // // Note: This example test is leveraging the Mocha test framework.
3+ // // Please refer to their documentation on https://mochajs.org/ for help.
44
55
6- // Place this right on top
7- import { initialize , IS_TRAVIS } from './initialize' ;
8- // The module 'assert' provides assertion methods from node
9- import * as assert from 'assert' ;
6+ // // Place this right on top
7+ // import { initialize, IS_TRAVIS } from './initialize';
8+ // // The module 'assert' provides assertion methods from node
9+ // import * as assert from 'assert';
1010
11- // You can import and use all API from the 'vscode' module
12- // as well as import your extension to test it
13- import * as vscode from 'vscode' ;
14- import { AutoPep8Formatter } from '../client/formatters/autoPep8Formatter' ;
15- import { YapfFormatter } from '../client/formatters/yapfFormatter' ;
16- import * as path from 'path' ;
17- import * as settings from '../client/common/configSettings' ;
18- import * as fs from 'fs-extra' ;
19- import { execPythonFile } from '../client/common/utils' ;
11+ // // You can import and use all API from the 'vscode' module
12+ // // as well as import your extension to test it
13+ // import * as vscode from 'vscode';
14+ // import { AutoPep8Formatter } from '../client/formatters/autoPep8Formatter';
15+ // import { YapfFormatter } from '../client/formatters/yapfFormatter';
16+ // import * as path from 'path';
17+ // import * as settings from '../client/common/configSettings';
18+ // import * as fs from 'fs-extra';
19+ // import { execPythonFile } from '../client/common/utils';
2020
21- let pythonSettings = settings . PythonSettings . getInstance ( ) ;
22- let ch = vscode . window . createOutputChannel ( 'Tests' ) ;
23- let pythoFilesPath = path . join ( __dirname , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'formatting' ) ;
24- const originalUnformattedFile = path . join ( pythoFilesPath , 'fileToFormat.py' ) ;
21+ // let pythonSettings = settings.PythonSettings.getInstance();
22+ // let ch = vscode.window.createOutputChannel('Tests');
23+ // let pythoFilesPath = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'formatting');
24+ // const originalUnformattedFile = path.join(pythoFilesPath, 'fileToFormat.py');
2525
26- const autoPep8FileToFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'autoPep8FileToFormat.py' ) ;
27- const autoPep8FileToAutoFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'autoPep8FileToAutoFormat.py' ) ;
28- const yapfFileToFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'yapfFileToFormat.py' ) ;
29- const yapfFileToAutoFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'yapfFileToAutoFormat.py' ) ;
26+ // const autoPep8FileToFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'autoPep8FileToFormat.py');
27+ // const autoPep8FileToAutoFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'autoPep8FileToAutoFormat.py');
28+ // const yapfFileToFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'yapfFileToFormat.py');
29+ // const yapfFileToAutoFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'yapfFileToAutoFormat.py');
3030
31- let formattedYapf = '' ;
32- let formattedAutoPep8 = '' ;
31+ // let formattedYapf = '';
32+ // let formattedAutoPep8 = '';
3333
34- suiteSetup ( done => {
35- initialize ( ) . then ( ( ) => {
36- [ autoPep8FileToFormat , autoPep8FileToAutoFormat , yapfFileToFormat , yapfFileToAutoFormat ] . forEach ( file => {
37- if ( fs . existsSync ( file ) ) { fs . unlinkSync ( file ) ; }
38- fs . copySync ( originalUnformattedFile , file ) ;
39- } ) ;
34+ // suiteSetup(done => {
35+ // initialize().then(() => {
36+ // [autoPep8FileToFormat, autoPep8FileToAutoFormat, yapfFileToFormat, yapfFileToAutoFormat].forEach(file => {
37+ // if (fs.existsSync(file)) { fs.unlinkSync(file); }
38+ // fs.copySync(originalUnformattedFile, file);
39+ // });
4040
41- fs . ensureDirSync ( path . dirname ( autoPep8FileToFormat ) ) ;
42- let yapf = execPythonFile ( 'yapf' , [ originalUnformattedFile ] , pythoFilesPath , false ) ;
43- let autoPep8 = execPythonFile ( 'autopep8' , [ originalUnformattedFile ] , pythoFilesPath , false ) ;
44- return Promise . all < string > ( [ yapf , autoPep8 ] ) . then ( formattedResults => {
45- formattedYapf = formattedResults [ 0 ] ;
46- formattedAutoPep8 = formattedResults [ 1 ] ;
47- } ) . then ( ( ) => {
48- done ( ) ;
49- } , reason => {
50- console . error ( reason ) ;
51- console . error ( 'Failed to initialize format tests' ) ;
52- done ( ) ;
53- } ) ;
54- } , done ) ;
55- } ) ;
41+ // fs.ensureDirSync(path.dirname(autoPep8FileToFormat));
42+ // let yapf = execPythonFile('yapf', [originalUnformattedFile], pythoFilesPath, false);
43+ // let autoPep8 = execPythonFile('autopep8', [originalUnformattedFile], pythoFilesPath, false);
44+ // return Promise.all<string>([yapf, autoPep8]).then(formattedResults => {
45+ // formattedYapf = formattedResults[0];
46+ // formattedAutoPep8 = formattedResults[1];
47+ // }).then(() => {
48+ // done();
49+ // }, reason => {
50+ // console.error(reason);
51+ // console.error('Failed to initialize format tests');
52+ // done();
53+ // });
54+ // }, done);
55+ // });
5656
57- suiteTeardown ( ( ) => {
58- if ( vscode . window . activeTextEditor ) {
59- return vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
60- }
61- } ) ;
57+ // suiteTeardown(() => {
58+ // if (vscode.window.activeTextEditor) {
59+ // return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
60+ // }
61+ // });
6262
63- suite ( 'Formatting' , ( ) => {
64- teardown ( ( ) => {
65- if ( vscode . window . activeTextEditor ) {
66- return vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
67- }
68- } ) ;
69- function testFormatting ( formatter : AutoPep8Formatter | YapfFormatter , formattedContents : string , fileToFormat : string ) : PromiseLike < void > {
70- let textEditor : vscode . TextEditor ;
71- let textDocument : vscode . TextDocument ;
72- return vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
73- textDocument = document ;
74- return vscode . window . showTextDocument ( textDocument ) ;
75- } ) . then ( editor => {
76- textEditor = editor ;
77- return formatter . formatDocument ( textDocument , null , null ) ;
78- } ) . then ( edits => {
79- return textEditor . edit ( editBuilder => {
80- edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
81- } ) ;
82- } ) . then ( edited => {
83- assert . equal ( textEditor . document . getText ( ) , formattedContents , 'Formatted text is not the same' ) ;
84- } , reason => {
85- assert . fail ( reason , undefined , 'Formatting failed' , '' ) ;
86- } ) ;
87- }
88- test ( 'AutoPep8' , done => {
89- testFormatting ( new AutoPep8Formatter ( ch , pythonSettings , pythoFilesPath ) , formattedAutoPep8 , autoPep8FileToFormat ) . then ( done , done ) ;
90- } ) ;
63+ // suite('Formatting', () => {
64+ // teardown(() => {
65+ // if (vscode.window.activeTextEditor) {
66+ // return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
67+ // }
68+ // });
69+ // function testFormatting(formatter: AutoPep8Formatter | YapfFormatter, formattedContents: string, fileToFormat: string): PromiseLike<void> {
70+ // let textEditor: vscode.TextEditor;
71+ // let textDocument: vscode.TextDocument;
72+ // return vscode.workspace.openTextDocument(fileToFormat).then(document => {
73+ // textDocument = document;
74+ // return vscode.window.showTextDocument(textDocument);
75+ // }).then(editor => {
76+ // textEditor = editor;
77+ // return formatter.formatDocument(textDocument, null, null);
78+ // }).then(edits => {
79+ // return textEditor.edit(editBuilder => {
80+ // edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
81+ // });
82+ // }).then(edited => {
83+ // assert.equal(textEditor.document.getText(), formattedContents, 'Formatted text is not the same');
84+ // }, reason => {
85+ // assert.fail(reason, undefined, 'Formatting failed', '');
86+ // });
87+ // }
88+ // test('AutoPep8', done => {
89+ // testFormatting(new AutoPep8Formatter(ch, pythonSettings, pythoFilesPath), formattedAutoPep8, autoPep8FileToFormat).then(done, done);
90+ // });
9191
92- test ( 'Yapf' , done => {
93- testFormatting ( new YapfFormatter ( ch , pythonSettings , pythoFilesPath ) , formattedYapf , yapfFileToFormat ) . then ( done , done ) ;
94- } ) ;
92+ // test('Yapf', done => {
93+ // testFormatting(new YapfFormatter(ch, pythonSettings, pythoFilesPath), formattedYapf, yapfFileToFormat).then(done, done);
94+ // });
9595
96- function testAutoFormatting ( formatter : string , formattedContents : string , fileToFormat : string ) : PromiseLike < void > {
97- let textDocument : vscode . TextDocument ;
98- pythonSettings . formatting . formatOnSave = true ;
99- pythonSettings . formatting . provider = formatter ;
100- return vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
101- textDocument = document ;
102- return vscode . window . showTextDocument ( textDocument ) ;
103- } ) . then ( editor => {
104- return editor . edit ( editBuilder => {
105- editBuilder . insert ( new vscode . Position ( 0 , 0 ) , '#\n' ) ;
106- } ) ;
107- } ) . then ( edited => {
108- return textDocument . save ( ) ;
109- } ) . then ( saved => {
110- return new Promise < any > ( ( resolve , reject ) => {
111- setTimeout ( ( ) => {
112- resolve ( ) ;
113- } , 5000 ) ;
114- } ) ;
115- } ) . then ( ( ) => {
116- assert . equal ( textDocument . getText ( ) , formattedContents , 'Formatted contents are not the same' ) ;
117- } ) ;
118- }
119- test ( 'AutoPep8 autoformat on save' , done => {
120- testAutoFormatting ( 'autopep8' , '#\n' + formattedAutoPep8 , autoPep8FileToAutoFormat ) . then ( done , done ) ;
121- } ) ;
96+ // function testAutoFormatting(formatter: string, formattedContents: string, fileToFormat: string): PromiseLike<void> {
97+ // let textDocument: vscode.TextDocument;
98+ // pythonSettings.formatting.formatOnSave = true;
99+ // pythonSettings.formatting.provider = formatter;
100+ // return vscode.workspace.openTextDocument(fileToFormat).then(document => {
101+ // textDocument = document;
102+ // return vscode.window.showTextDocument(textDocument);
103+ // }).then(editor => {
104+ // return editor.edit(editBuilder => {
105+ // editBuilder.insert(new vscode.Position(0, 0), '#\n');
106+ // });
107+ // }).then(edited => {
108+ // return textDocument.save();
109+ // }).then(saved => {
110+ // return new Promise<any>((resolve, reject) => {
111+ // setTimeout(() => {
112+ // resolve();
113+ // }, 5000);
114+ // });
115+ // }).then(() => {
116+ // assert.equal(textDocument.getText(), formattedContents, 'Formatted contents are not the same');
117+ // });
118+ // }
119+ // test('AutoPep8 autoformat on save', done => {
120+ // testAutoFormatting('autopep8', '#\n' + formattedAutoPep8, autoPep8FileToAutoFormat).then(done, done);
121+ // });
122122
123- // For some reason doesn't ever work on travis
124- if ( ! IS_TRAVIS ) {
125- test ( 'Yapf autoformat on save' , done => {
126- testAutoFormatting ( 'yapf' , '#\n' + formattedYapf , yapfFileToAutoFormat ) . then ( done , done ) ;
127- } ) ;
128- }
129- } ) ;
123+ // // For some reason doesn't ever work on travis
124+ // if (!IS_TRAVIS) {
125+ // test('Yapf autoformat on save', done => {
126+ // testAutoFormatting('yapf', '#\n' + formattedYapf, yapfFileToAutoFormat).then(done, done);
127+ // });
128+ // }
129+ // });
0 commit comments