Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c66e8cb

Browse files
committed
fixed errors in unit test
1 parent c8dee7b commit c66e8cb

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/test/extension.format.test.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ suite("Formatting", () => {
2828
test("AutoPep8", done => {
2929
let fileToFormat = path.join(pythoFilesPath, "beforeAutoPep8.py");
3030
vscode.workspace.openTextDocument(fileToFormat).then(textDocument => {
31-
vscode.window.showTextDocument(textDocument);
32-
let formatter = new AutoPep8Formatter(ch, pythonSettings, pythoFilesPath);
33-
return formatter.formatDocument(textDocument, null, null).then(edits => {
34-
let activeEditor = vscode.window.activeTextEditor;
35-
activeEditor.edit(editBuilder => {
36-
edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
37-
}).then(edited => {
38-
let formattedFile = path.join(pythoFilesPath, "afterAutoPep8.py");
39-
let formattedContents = fs.readFile(formattedFile, "utf-8", (error, data) => {
40-
if (error) {
41-
return assert.fail(error, "", "Failed to read formatted file");
42-
}
43-
assert.equal(activeEditor.document.getText(), data, "Formatted text is not the same");
31+
vscode.window.showTextDocument(textDocument).then(textEditor => {
32+
let formatter = new AutoPep8Formatter(ch, pythonSettings, pythoFilesPath);
33+
return formatter.formatDocument(textDocument, null, null).then(edits => {
34+
textEditor.edit(editBuilder => {
35+
edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
36+
}).then(edited => {
37+
let formattedFile = path.join(pythoFilesPath, "afterAutoPep8.py");
38+
let formattedContents = fs.readFile(formattedFile, "utf-8", (error, data) => {
39+
if (error) {
40+
return assert.fail(error, "", "Failed to read formatted file");
41+
}
42+
assert.equal(textEditor.document.getText(), data, "Formatted text is not the same");
43+
});
4444
});
45+
}, error => {
46+
assert.fail(error, "", "Error in Formatting, " + error);
4547
});
4648
}, error => {
4749
assert.fail(error, "", "Error in Formatting, " + error);
@@ -54,20 +56,22 @@ suite("Formatting", () => {
5456
test("Yapf", done => {
5557
let fileToFormat = path.join(pythoFilesPath, "beforeYapf.py");
5658
vscode.workspace.openTextDocument(fileToFormat).then(textDocument => {
57-
vscode.window.showTextDocument(textDocument);
58-
let formatter = new YapfFormatter(ch, pythonSettings, pythoFilesPath);
59-
return formatter.formatDocument(textDocument, null, null).then(edits => {
60-
let activeEditor = vscode.window.activeTextEditor;
61-
activeEditor.edit(editBuilder => {
62-
edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
63-
}).then(edited => {
64-
let formattedFile = path.join(pythoFilesPath, "afterYapf.py");
65-
let formattedContents = fs.readFile(formattedFile, "utf-8", (error, data) => {
66-
if (error) {
67-
return assert.fail(error, "", "Failed to read formatted file");
68-
}
69-
assert.equal(activeEditor.document.getText(), data, "Formatted text is not the same");
59+
vscode.window.showTextDocument(textDocument).then(textEditor => {
60+
let formatter = new YapfFormatter(ch, pythonSettings, pythoFilesPath);
61+
return formatter.formatDocument(textDocument, null, null).then(edits => {
62+
textEditor.edit(editBuilder => {
63+
edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
64+
}).then(edited => {
65+
let formattedFile = path.join(pythoFilesPath, "afterYapf.py");
66+
let formattedContents = fs.readFile(formattedFile, "utf-8", (error, data) => {
67+
if (error) {
68+
return assert.fail(error, "", "Failed to read formatted file");
69+
}
70+
assert.equal(textEditor.document.getText(), data, "Formatted text is not the same");
71+
});
7072
});
73+
}, error => {
74+
assert.fail(error, "", "Error in Formatting, " + error);
7175
});
7276
}, error => {
7377
assert.fail(error, "", "Error in Formatting, " + error);

0 commit comments

Comments
 (0)