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" ;
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";
1818
19- let pythonSettings = settings . PythonSettings . getInstance ( ) ;
20- let ch = vscode . window . createOutputChannel ( "Tests" ) ;
21- let pythoFilesPath = path . join ( __dirname , ".." , ".." , "src" , "test" , "pythonFiles" , "formatting" ) ;
19+ // let pythonSettings = settings.PythonSettings.getInstance();
20+ // let ch = vscode.window.createOutputChannel("Tests");
21+ // let pythoFilesPath = path.join(__dirname, "..", "..", "src", "test", "pythonFiles", "formatting");
2222
23- suite ( "Formatting" , ( ) => {
24- setup ( done => {
25- initialize ( ) . then ( ( ) => done ( ) , done ) ;
26- } ) ;
27- teardown ( ( ) => {
28- if ( vscode . window . activeTextEditor ) {
29- return vscode . commands . executeCommand ( "workbench.action.closeActiveEditor" ) ;
30- }
31- return Promise . resolve ( ) ;
32- } ) ;
33- test ( "AutoPep8" , done => {
34- let fileToFormat = path . join ( pythoFilesPath , "beforeAutoPep8.py" ) ;
35- let textEditor : vscode . TextEditor ;
36- let textDocument : vscode . TextDocument ;
37- vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
38- textDocument = document ;
39- return vscode . window . showTextDocument ( textDocument ) ;
40- } ) . then ( editor => {
41- textEditor = editor ;
42- let formatter = new AutoPep8Formatter ( ch , pythonSettings , pythoFilesPath ) ;
43- return formatter . formatDocument ( textDocument , null , null ) ;
44- } ) . then ( edits => {
45- return textEditor . edit ( editBuilder => {
46- edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
47- } ) ;
48- } ) . then ( edited => {
49- let formattedFile = path . join ( pythoFilesPath , "afterAutoPep8.py" ) ;
50- let formattedContents = fs . readFile ( formattedFile , "utf-8" , ( error , data ) => {
51- if ( error ) {
52- return assert . fail ( error , "" , "Failed to read formatted file" ) ;
53- }
54- assert . equal ( textEditor . document . getText ( ) , data , "Formatted text is not the same" ) ;
55- } ) ;
56- } ) . then ( done , done ) ;
57- } ) ;
23+ // suite("Formatting", () => {
24+ // setup(done => {
25+ // initialize().then(() => done(), done);
26+ // });
27+ // teardown(() => {
28+ // if (vscode.window.activeTextEditor) {
29+ // return vscode.commands.executeCommand("workbench.action.closeActiveEditor");
30+ // }
31+ // return Promise.resolve();
32+ // });
33+ // test("AutoPep8", done => {
34+ // let fileToFormat = path.join(pythoFilesPath, "beforeAutoPep8.py");
35+ // let textEditor: vscode.TextEditor;
36+ // let textDocument: vscode.TextDocument;
37+ // vscode.workspace.openTextDocument(fileToFormat).then(document => {
38+ // textDocument = document;
39+ // return vscode.window.showTextDocument(textDocument);
40+ // }).then(editor => {
41+ // textEditor = editor;
42+ // let formatter = new AutoPep8Formatter(ch, pythonSettings, pythoFilesPath);
43+ // return formatter.formatDocument(textDocument, null, null);
44+ // }).then(edits => {
45+ // return textEditor.edit(editBuilder => {
46+ // edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
47+ // });
48+ // }).then(edited => {
49+ // let formattedFile = path.join(pythoFilesPath, "afterAutoPep8.py");
50+ // let formattedContents = fs.readFile(formattedFile, "utf-8", (error, data) => {
51+ // if (error) {
52+ // return assert.fail(error, "", "Failed to read formatted file");
53+ // }
54+ // assert.equal(textEditor.document.getText(), data, "Formatted text is not the same");
55+ // });
56+ // }).then(done, done);
57+ // });
5858
59- test ( "Yapf" , done => {
60- let fileToFormat = path . join ( pythoFilesPath , "beforeYapf.py" ) ;
61- let textEditor : vscode . TextEditor ;
62- let textDocument : vscode . TextDocument ;
63- vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
64- textDocument = document ;
65- return vscode . window . showTextDocument ( textDocument ) ;
66- } ) . then ( editor => {
67- textEditor = editor ;
68- let formatter = new YapfFormatter ( ch , pythonSettings , pythoFilesPath ) ;
69- return formatter . formatDocument ( textDocument , null , null ) ;
70- } ) . then ( edits => {
71- return textEditor . edit ( editBuilder => {
72- edits . forEach ( edit => editBuilder . replace ( edit . range , edit . newText ) ) ;
73- } ) ;
74- } ) . then ( edited => {
75- let formattedFile = path . join ( pythoFilesPath , "afterYapf.py" ) ;
76- let formattedContents = fs . readFile ( formattedFile , "utf-8" , ( error , data ) => {
77- if ( error ) {
78- return assert . fail ( error , "" , "Failed to read formatted file" ) ;
79- }
80- assert . equal ( textEditor . document . getText ( ) , data , "Formatted text is not the same" ) ;
81- } ) ;
82- } ) . then ( done , done ) ;
83- } ) ;
59+ // test("Yapf", done => {
60+ // let fileToFormat = path.join(pythoFilesPath, "beforeYapf.py");
61+ // let textEditor: vscode.TextEditor;
62+ // let textDocument: vscode.TextDocument;
63+ // vscode.workspace.openTextDocument(fileToFormat).then(document => {
64+ // textDocument = document;
65+ // return vscode.window.showTextDocument(textDocument);
66+ // }).then(editor => {
67+ // textEditor = editor;
68+ // let formatter = new YapfFormatter(ch, pythonSettings, pythoFilesPath);
69+ // return formatter.formatDocument(textDocument, null, null);
70+ // }).then(edits => {
71+ // return textEditor.edit(editBuilder => {
72+ // edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
73+ // });
74+ // }).then(edited => {
75+ // let formattedFile = path.join(pythoFilesPath, "afterYapf.py");
76+ // let formattedContents = fs.readFile(formattedFile, "utf-8", (error, data) => {
77+ // if (error) {
78+ // return assert.fail(error, "", "Failed to read formatted file");
79+ // }
80+ // assert.equal(textEditor.document.getText(), data, "Formatted text is not the same");
81+ // });
82+ // }).then(done, done);
83+ // });
8484
85- test ( "Yapf autoformat on save" , done => {
86- let formattedFile = path . join ( pythoFilesPath , "afterYapfFormatOnSave.py" ) ;
87- let fileToCopyFrom = path . join ( pythoFilesPath , "beforeYapfFormatOnSaveOriginal.py" ) ;
88- let formattedFileContents = fs . readFileSync ( formattedFile , "utf-8" ) ;
85+ // test("Yapf autoformat on save", done => {
86+ // let formattedFile = path.join(pythoFilesPath, "afterYapfFormatOnSave.py");
87+ // let fileToCopyFrom = path.join(pythoFilesPath, "beforeYapfFormatOnSaveOriginal.py");
88+ // let formattedFileContents = fs.readFileSync(formattedFile, "utf-8");
8989
90- let fileToFormat = path . join ( pythoFilesPath , "beforeYapf.py" ) ;
91- let textDocument : vscode . TextDocument ;
90+ // let fileToFormat = path.join(pythoFilesPath, "beforeYapf.py");
91+ // let textDocument: vscode.TextDocument;
9292
93- if ( fs . existsSync ( fileToFormat ) ) { fs . unlinkSync ( fileToFormat ) ; }
94- fs . copySync ( fileToCopyFrom , fileToFormat ) ;
95- const FORMAT_ON_SAVE = pythonSettings . formatting . formatOnSave ;
96- pythonSettings . formatting . formatOnSave = true ;
97- pythonSettings . formatting . provider = "yapf" ;
93+ // if (fs.existsSync(fileToFormat)) { fs.unlinkSync(fileToFormat); }
94+ // fs.copySync(fileToCopyFrom, fileToFormat);
95+ // const FORMAT_ON_SAVE = pythonSettings.formatting.formatOnSave;
96+ // pythonSettings.formatting.formatOnSave = true;
97+ // pythonSettings.formatting.provider = "yapf";
9898
99- vscode . workspace . openTextDocument ( fileToFormat ) . then ( document => {
100- textDocument = document ;
101- return vscode . window . showTextDocument ( textDocument ) ;
102- } ) . then ( editor => {
103- return editor . edit ( editBuilder => {
104- editBuilder . insert ( new vscode . Position ( 0 , 0 ) , "#\n" ) ;
105- } ) ;
106- } ) . then ( saved => {
107- return new Promise < any > ( ( resolve , reject ) => {
108- setTimeout ( ( ) => {
109- resolve ( ) ;
110- } , 1000 ) ;
111- } ) ;
112- } ) . then ( ( ) => {
113- assert . equal ( textDocument . getText ( ) , formattedFileContents , "Formatted contents are not the same" ) ;
114- } ) . then ( done , done ) ;
115- } ) ;
116- } ) ;
99+ // vscode.workspace.openTextDocument(fileToFormat).then(document => {
100+ // textDocument = document;
101+ // return vscode.window.showTextDocument(textDocument);
102+ // }).then(editor => {
103+ // return editor.edit(editBuilder => {
104+ // editBuilder.insert(new vscode.Position(0, 0), "#\n");
105+ // });
106+ // }).then(saved => {
107+ // return new Promise<any>((resolve, reject) => {
108+ // setTimeout(() => {
109+ // resolve();
110+ // }, 1000);
111+ // });
112+ // }).then(() => {
113+ // assert.equal(textDocument.getText(), formattedFileContents, "Formatted contents are not the same");
114+ // }).then(done, done);
115+ // });
116+ // });
0 commit comments