Skip to content

Commit 9a7c38c

Browse files
committed
use separate files to be opened
1 parent bb4078c commit 9a7c38c

4 files changed

Lines changed: 38 additions & 34 deletions

File tree

src/test/extension.sort.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const fileToFormatWithoutConfig = path.join(__dirname, '..', '..', 'src', 'test'
2222
const originalFileToFormatWithoutConfig = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'noconfig', 'original.py');
2323
const fileToFormatWithConfig = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'withconfig', 'before.py');
2424
const originalFileToFormatWithConfig = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'withconfig', 'original.py');
25+
const fileToFormatWithConfig1 = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'withconfig', 'before.1.py');
26+
const originalFileToFormatWithConfig1 = path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'withconfig', 'original.1.py');
2527
const extensionDir = path.join(__dirname, '..', '..');
2628

2729
suite('Formatting', () => {
@@ -33,6 +35,7 @@ suite('Formatting', () => {
3335

3436
suiteTeardown(() => {
3537
fs.writeFileSync(fileToFormatWithConfig, fs.readFileSync(originalFileToFormatWithConfig));
38+
fs.writeFileSync(fileToFormatWithConfig1, fs.readFileSync(originalFileToFormatWithConfig1));
3639
fs.writeFileSync(fileToFormatWithoutConfig, fs.readFileSync(originalFileToFormatWithoutConfig));
3740
if (vscode.window.activeTextEditor) {
3841
return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
@@ -42,10 +45,12 @@ suite('Formatting', () => {
4245
pythonSettings.sortImports.args = [];
4346
fs.writeFileSync(fileToFormatWithConfig, fs.readFileSync(originalFileToFormatWithConfig));
4447
fs.writeFileSync(fileToFormatWithoutConfig, fs.readFileSync(originalFileToFormatWithoutConfig));
48+
fs.writeFileSync(fileToFormatWithConfig1, fs.readFileSync(originalFileToFormatWithConfig1));
4549
});
4650
teardown(() => {
4751
fs.writeFileSync(fileToFormatWithConfig, fs.readFileSync(originalFileToFormatWithConfig));
4852
fs.writeFileSync(fileToFormatWithoutConfig, fs.readFileSync(originalFileToFormatWithoutConfig));
53+
fs.writeFileSync(fileToFormatWithConfig1, fs.readFileSync(originalFileToFormatWithConfig1));
4954
if (vscode.window.activeTextEditor) {
5055
return vscode.commands.executeCommand('workbench.action.closeActiveEditor');
5156
}
@@ -117,34 +122,29 @@ suite('Formatting', () => {
117122
}).then(done, done);
118123
});
119124

120-
// Lol this doesn't work
121-
// VS Code repeatedly fails to open the document with the following error
122-
// "Error: Failed to show text document file:///.../before.py, should show in editor #undefined"
123-
if (!IS_TRAVIS) {
124-
test('With Changes and Config in Args', done => {
125-
let textEditor: vscode.TextEditor;
126-
let textDocument: vscode.TextDocument;
127-
pythonSettings.sortImports.args = ['-sp', path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'withconfig')];
128-
return vscode.workspace.openTextDocument(fileToFormatWithConfig).then(document => {
129-
textDocument = document;
130-
return vscode.window.showTextDocument(textDocument);
131-
}).then(editor => {
132-
textEditor = editor;
133-
return editor.edit(editor => {
134-
editor.insert(new vscode.Position(0, 0), 'from third_party import lib0' + EOL);
135-
});
136-
}).then(() => {
137-
const sorter = new PythonImportSortProvider();
138-
return sorter.sortImports(extensionDir, textDocument);
139-
}).then(edits => {
140-
const newValue = `from third_party import lib1${EOL}from third_party import lib2${EOL}from third_party import lib3${EOL}from third_party import lib4${EOL}from third_party import lib5${EOL}from third_party import lib6${EOL}from third_party import lib7${EOL}from third_party import lib8${EOL}from third_party import lib9${EOL}`;
141-
assert.equal(edits.length, 1, 'Incorrect number of edits');
142-
assert.equal(edits[0].newText, newValue, 'New Value is not the same');
143-
assert.equal(`${edits[0].range.start.line},${edits[0].range.start.character}`, '1,0', 'Start position is not the same');
144-
assert.equal(`${edits[0].range.end.line},${edits[0].range.end.character}`, '2,0', 'End position is not the same');
145-
}).then(done, done);
146-
});
147-
}
125+
test('With Changes and Config in Args', done => {
126+
let textEditor: vscode.TextEditor;
127+
let textDocument: vscode.TextDocument;
128+
pythonSettings.sortImports.args = ['-sp', path.join(__dirname, '..', '..', 'src', 'test', 'pythonFiles', 'sorting', 'withconfig')];
129+
return vscode.workspace.openTextDocument(fileToFormatWithConfig).then(document => {
130+
textDocument = document;
131+
return vscode.window.showTextDocument(textDocument);
132+
}).then(editor => {
133+
textEditor = editor;
134+
return editor.edit(editor => {
135+
editor.insert(new vscode.Position(0, 0), 'from third_party import lib0' + EOL);
136+
});
137+
}).then(() => {
138+
const sorter = new PythonImportSortProvider();
139+
return sorter.sortImports(extensionDir, textDocument);
140+
}).then(edits => {
141+
const newValue = `from third_party import lib1${EOL}from third_party import lib2${EOL}from third_party import lib3${EOL}from third_party import lib4${EOL}from third_party import lib5${EOL}from third_party import lib6${EOL}from third_party import lib7${EOL}from third_party import lib8${EOL}from third_party import lib9${EOL}`;
142+
assert.equal(edits.length, 1, 'Incorrect number of edits');
143+
assert.equal(edits[0].newText, newValue, 'New Value is not the same');
144+
assert.equal(`${edits[0].range.start.line},${edits[0].range.start.character}`, '1,0', 'Start position is not the same');
145+
assert.equal(`${edits[0].range.end.line},${edits[0].range.end.character}`, '2,0', 'End position is not the same');
146+
}).then(done, done);
147+
});
148148

149149
test('With Changes and Config in Args (via Command)', done => {
150150
let textEditor: vscode.TextEditor;
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import io; sys; json
22
import traceback
3-
import rope
43

4+
import rope
55
import rope.base.project
66
import rope.base.taskhandle
7+
from rope.base import libutils
8+
from rope.refactor.extract import ExtractMethod, ExtractVariable
9+
from rope.refactor.rename import Rename
710

811
WORKSPACE_ROOT = sys.argv[1]
912
ROPE_PROJECT_FOLDER = sys.argv[2]
1013

1114

1215
def test():
1316
pass
14-
15-
from rope.base import libutils
16-
from rope.refactor.rename import Rename
17-
from rope.refactor.extract import ExtractMethod, ExtractVariable
18-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from third_party import (lib1, lib2, lib3,
2+
lib4, lib5, lib6,
3+
lib7, lib8, lib9)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from third_party import (lib1, lib2, lib3,
2+
lib4, lib5, lib6,
3+
lib7, lib8, lib9)

0 commit comments

Comments
 (0)