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- // The module 'assert' provides assertion methods from node
7- import * as assert from 'assert' ;
6+ // // The module 'assert' provides assertion methods from node
7+ // import * as assert from 'assert';
88
9- // You can import and use all API from the 'vscode' module
10- // as well as import your extension to test it
11- import * as vscode from 'vscode' ;
12- import { AutoPep8Formatter } from '../client/formatters/autoPep8Formatter' ;
13- import { YapfFormatter } from '../client/formatters/yapfFormatter' ;
14- import * as path from 'path' ;
15- import * as settings from '../client/common/configSettings' ;
16- import * as fs from 'fs-extra' ;
17- import { initialize } from './initialize' ;
18- import { execPythonFile } from '../client/common/utils' ;
9+ // // You can import and use all API from the 'vscode' module
10+ // // as well as import your extension to test it
11+ // import * as vscode from 'vscode';
12+ // import {AutoPep8Formatter} from '../client/formatters/autoPep8Formatter';
13+ // import {YapfFormatter} from '../client/formatters/yapfFormatter';
14+ // import * as path from 'path';
15+ // import * as settings from '../client/common/configSettings';
16+ // import * as fs from 'fs-extra';
17+ // import {initialize} from './initialize';
18+ // import {execPythonFile} from '../client/common/utils';
1919
20- let pythonSettings = settings . PythonSettings . getInstance ( ) ;
21- let ch = vscode . window . createOutputChannel ( 'Tests' ) ;
22- let pythoFilesPath = path . join ( __dirname , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'formatting' ) ;
23- const originalUnformattedFile = path . join ( pythoFilesPath , 'fileToFormat.py' ) ;
20+ // let pythonSettings = settings.PythonSettings.getInstance();
21+ // let ch = vscode.window.createOutputChannel('Tests');
22+ // let pythoFilesPath = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'formatting');
23+ // const originalUnformattedFile = path.join(pythoFilesPath, 'fileToFormat.py');
2424
25- const autoPep8FileToFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'autoPep8FileToFormat.py' ) ;
26- const autoPep8FileToAutoFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'autoPep8FileToAutoFormat.py' ) ;
27- const yapfFileToFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'yapfFileToFormat.py' ) ;
28- const yapfFileToAutoFormat = path . join ( __dirname , 'pythonFiles' , 'formatting' , 'yapfFileToAutoFormat.py' ) ;
25+ // const autoPep8FileToFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'autoPep8FileToFormat.py');
26+ // const autoPep8FileToAutoFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'autoPep8FileToAutoFormat.py');
27+ // const yapfFileToFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'yapfFileToFormat.py');
28+ // const yapfFileToAutoFormat = path.join(__dirname, 'pythonFiles', 'formatting', 'yapfFileToAutoFormat.py');
2929
30- let formattedYapf = '' ;
31- let formattedAutoPep8 = '' ;
30+ // let formattedYapf = '';
31+ // let formattedAutoPep8 = '';
3232
33- suiteSetup ( done => {
34- initialize ( ) . then ( ( ) => {
35- [ autoPep8FileToFormat , autoPep8FileToAutoFormat , yapfFileToFormat , yapfFileToAutoFormat ] . forEach ( file => {
36- if ( fs . existsSync ( file ) ) { fs . unlinkSync ( file ) ; }
37- fs . copySync ( originalUnformattedFile , file ) ;
38- } ) ;
33+ // suiteSetup(done => {
34+ // initialize().then(() => {
35+ // [autoPep8FileToFormat, autoPep8FileToAutoFormat, yapfFileToFormat, yapfFileToAutoFormat].forEach(file => {
36+ // if (fs.existsSync(file)) { fs.unlinkSync(file); }
37+ // fs.copySync(originalUnformattedFile, file);
38+ // });
3939
40- fs . ensureDirSync ( path . dirname ( autoPep8FileToFormat ) ) ;
41- let yapf = execPythonFile ( 'yapf' , [ originalUnformattedFile ] , pythoFilesPath , false ) ;
42- let autoPep8 = execPythonFile ( 'autopep8' , [ originalUnformattedFile ] , pythoFilesPath , false ) ;
43- return Promise . all < string > ( [ yapf , autoPep8 ] ) . then ( formattedResults => {
44- formattedYapf = formattedResults [ 0 ] ;
45- formattedAutoPep8 = formattedResults [ 1 ] ;
46- } ) . then ( ( ) => {
47- done ( ) ;
48- } ) ;
49- } , done ) ;
50- } ) ;
40+ // fs.ensureDirSync(path.dirname(autoPep8FileToFormat));
41+ // let yapf = execPythonFile('yapf', [originalUnformattedFile], pythoFilesPath, false);
42+ // let autoPep8 = execPythonFile('autopep8', [originalUnformattedFile], pythoFilesPath, false);
43+ // return Promise.all<string>([yapf, autoPep8]).then(formattedResults => {
44+ // formattedYapf = formattedResults[0];
45+ // formattedAutoPep8 = formattedResults[1];
46+ // }).then(() => {
47+ // done();
48+ // });
49+ // }, done);
50+ // });
5151
52- suiteTeardown ( ( ) => {
53- if ( vscode . window . activeTextEditor ) {
54- return vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
55- }
56- } ) ;
52+ // suiteTeardown(() => {
53+ // if (vscode.window.activeTextEditor) {
54+ // return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
55+ // }
56+ // });
5757
58- suite ( 'Formatting' , ( ) => {
59- teardown ( ( ) => {
60- if ( vscode . window . activeTextEditor ) {
61- return vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
62- }
63- } ) ;
64- function testFormatting ( formatter : AutoPep8Formatter | YapfFormatter , formattedContents : string , fileToFormat : string ) : PromiseLike < void > {
65- let textEditor : vscode . TextEditor ;
66- let textDocument : vscode . TextDocument ;
67- return vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
68- textDocument = document ;
69- return vscode . window . showTextDocument ( textDocument ) ;
70- } ) . then ( editor => {
71- textEditor = editor ;
72- return formatter . formatDocument ( textDocument , null , null ) ;
73- } ) . then ( edits => {
74- return textEditor . edit ( editBuilder => {
75- edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
76- } ) ;
77- } ) . then ( edited => {
78- assert . equal ( textEditor . document . getText ( ) , formattedContents , 'Formatted text is not the same' ) ;
79- } ) ;
80- }
81- test ( 'AutoPep8' , done => {
82- testFormatting ( new AutoPep8Formatter ( ch , pythonSettings , pythoFilesPath ) , formattedAutoPep8 , autoPep8FileToFormat ) . then ( done , done ) ;
83- } ) ;
58+ // suite('Formatting', () => {
59+ // teardown(() => {
60+ // if (vscode.window.activeTextEditor) {
61+ // return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
62+ // }
63+ // });
64+ // function testFormatting(formatter: AutoPep8Formatter | YapfFormatter, formattedContents: string, fileToFormat: string): PromiseLike<void> {
65+ // let textEditor: vscode.TextEditor;
66+ // let textDocument: vscode.TextDocument;
67+ // return vscode.workspace.openTextDocument(fileToFormat).then(document => {
68+ // textDocument = document;
69+ // return vscode.window.showTextDocument(textDocument);
70+ // }).then(editor => {
71+ // textEditor = editor;
72+ // return formatter.formatDocument(textDocument, null, null);
73+ // }).then(edits => {
74+ // return textEditor.edit(editBuilder => {
75+ // edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
76+ // });
77+ // }).then(edited => {
78+ // assert.equal(textEditor.document.getText(), formattedContents, 'Formatted text is not the same');
79+ // });
80+ // }
81+ // test('AutoPep8', done => {
82+ // testFormatting(new AutoPep8Formatter(ch, pythonSettings, pythoFilesPath), formattedAutoPep8, autoPep8FileToFormat).then(done, done);
83+ // });
8484
85- test ( 'Yapf' , done => {
86- testFormatting ( new YapfFormatter ( ch , pythonSettings , pythoFilesPath ) , formattedYapf , yapfFileToFormat ) . then ( done , done ) ;
87- } ) ;
85+ // test('Yapf', done => {
86+ // testFormatting(new YapfFormatter(ch, pythonSettings, pythoFilesPath), formattedYapf, yapfFileToFormat).then(done, done);
87+ // });
8888
89- function testAutoFormatting ( formatter : string , formattedContents : string , fileToFormat : string ) : PromiseLike < void > {
90- let textDocument : vscode . TextDocument ;
91- pythonSettings . formatting . formatOnSave = true ;
92- pythonSettings . formatting . provider = formatter ;
93- return vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
94- textDocument = document ;
95- return vscode . window . showTextDocument ( textDocument ) ;
96- } ) . then ( editor => {
97- return editor . edit ( editBuilder => {
98- editBuilder . insert ( new vscode . Position ( 0 , 0 ) , '#\n' ) ;
99- } ) ;
100- } ) . then ( edited => {
101- return textDocument . save ( ) ;
102- } ) . then ( saved => {
103- return new Promise < any > ( ( resolve , reject ) => {
104- setTimeout ( ( ) => {
105- resolve ( ) ;
106- } , 2000 ) ;
107- } ) ;
108- } ) . then ( ( ) => {
109- assert . equal ( textDocument . getText ( ) , formattedContents , 'Formatted contents are not the same' ) ;
110- } ) ;
111- }
112- test ( 'AutoPep8 autoformat on save' , done => {
113- testAutoFormatting ( 'autopep8' , '#\n' + formattedAutoPep8 , autoPep8FileToAutoFormat ) . then ( done , done ) ;
114- } ) ;
89+ // function testAutoFormatting(formatter: string, formattedContents: string, fileToFormat: string): PromiseLike<void> {
90+ // let textDocument: vscode.TextDocument;
91+ // pythonSettings.formatting.formatOnSave = true;
92+ // pythonSettings.formatting.provider = formatter;
93+ // return vscode.workspace.openTextDocument(fileToFormat).then(document => {
94+ // textDocument = document;
95+ // return vscode.window.showTextDocument(textDocument);
96+ // }).then(editor => {
97+ // return editor.edit(editBuilder => {
98+ // editBuilder.insert(new vscode.Position(0, 0), '#\n');
99+ // });
100+ // }).then(edited => {
101+ // return textDocument.save();
102+ // }).then(saved => {
103+ // return new Promise<any>((resolve, reject) => {
104+ // setTimeout(() => {
105+ // resolve();
106+ // }, 2000);
107+ // });
108+ // }).then(() => {
109+ // assert.equal(textDocument.getText(), formattedContents, 'Formatted contents are not the same');
110+ // });
111+ // }
112+ // test('AutoPep8 autoformat on save', done => {
113+ // testAutoFormatting('autopep8', '#\n' + formattedAutoPep8, autoPep8FileToAutoFormat).then(done, done);
114+ // });
115115
116- test ( 'Yapf autoformat on save' , done => {
117- testAutoFormatting ( 'yapf' , '#\n' + formattedYapf , yapfFileToAutoFormat ) . then ( done , done ) ;
118- } ) ;
119- } ) ;
116+ // test('Yapf autoformat on save', done => {
117+ // testAutoFormatting('yapf', '#\n' + formattedYapf, yapfFileToAutoFormat).then(done, done);
118+ // });
119+ // });
0 commit comments