33import * as assert from 'assert' ;
44import * as fs from 'fs-extra' ;
55import * as path from 'path' ;
6- import * as vscode from 'vscode' ;
7- import { Position } from 'vscode' ;
6+ import { commands , Position , Range , Selection , TextEditorCursorStyle , TextEditorLineNumbersStyle , TextEditorOptions , Uri , window , workspace } from 'vscode' ;
87import { PythonSettings } from '../../client/common/configSettings' ;
98import { getTextEditsFromPatch } from '../../client/common/editor' ;
109import { extractVariable } from '../../client/providers/simpleRefactorProvider' ;
1110import { RefactorProxy } from '../../client/refactor/proxy' ;
11+ import { PythonVersionInformation } from '../../client/unittests/common/types' ;
12+ import { rootWorkspaceUri } from '../common' ;
1213import { UnitTestIocContainer } from '../unittests/serviceRegistry' ;
1314import { closeActiveWindows , initialize , initializeTest , IS_CI_SERVER } from './../initialize' ;
1415import { MockOutputChannel } from './../mockClasses' ;
@@ -23,24 +24,24 @@ interface RenameResponse {
2324
2425suite ( 'Variable Extraction' , ( ) => {
2526 // Hack hac hack
26- const oldExecuteCommand = vscode . commands . executeCommand ;
27- const options : vscode . TextEditorOptions = { cursorStyle : vscode . TextEditorCursorStyle . Line , insertSpaces : true , lineNumbers : vscode . TextEditorLineNumbersStyle . Off , tabSize : 4 } ;
27+ const oldExecuteCommand = commands . executeCommand ;
28+ const options : TextEditorOptions = { cursorStyle : TextEditorCursorStyle . Line , insertSpaces : true , lineNumbers : TextEditorLineNumbersStyle . Off , tabSize : 4 } ;
2829 let refactorTargetFile = '' ;
2930 let ioc : UnitTestIocContainer ;
3031 suiteSetup ( initialize ) ;
3132 suiteTeardown ( ( ) => {
32- vscode . commands . executeCommand = oldExecuteCommand ;
33+ commands . executeCommand = oldExecuteCommand ;
3334 return closeActiveWindows ( ) ;
3435 } ) ;
3536 setup ( async ( ) => {
3637 initializeDI ( ) ;
3738 refactorTargetFile = path . join ( refactorTargetFileDir , `refactor${ new Date ( ) . getTime ( ) } .py` ) ;
3839 fs . copySync ( refactorSourceFile , refactorTargetFile , { overwrite : true } ) ;
3940 await initializeTest ( ) ;
40- ( < any > vscode ) . commands . executeCommand = ( cmd ) => Promise . resolve ( ) ;
41+ ( < any > commands ) . executeCommand = ( cmd ) => Promise . resolve ( ) ;
4142 } ) ;
4243 teardown ( async ( ) => {
43- vscode . commands . executeCommand = oldExecuteCommand ;
44+ commands . executeCommand = oldExecuteCommand ;
4445 try {
4546 await fs . unlink ( refactorTargetFile ) ;
4647 } catch { }
@@ -55,12 +56,12 @@ suite('Variable Extraction', () => {
5556 }
5657
5758 async function testingVariableExtraction ( shouldError : boolean , startPos : Position , endPos : Position ) : Promise < void > {
58- const pythonSettings = PythonSettings . getInstance ( vscode . Uri . file ( refactorTargetFile ) ) ;
59- const rangeOfTextToExtract = new vscode . Range ( startPos , endPos ) ;
59+ const pythonSettings = PythonSettings . getInstance ( Uri . file ( refactorTargetFile ) ) ;
60+ const rangeOfTextToExtract = new Range ( startPos , endPos ) ;
6061 const proxy = new RefactorProxy ( EXTENSION_DIR , pythonSettings , path . dirname ( refactorTargetFile ) , ioc . serviceContainer ) ;
6162
6263 const DIFF = '--- a/refactor.py\n+++ b/refactor.py\n@@ -232,7 +232,8 @@\n sys.stdout.flush()\n \n def watch(self):\n- self._write_response("STARTED")\n+ myNewVariable = "STARTED"\n+ self._write_response(myNewVariable)\n while True:\n try:\n self._process_request(self._input.readline())\n' ;
63- const mockTextDoc = await vscode . workspace . openTextDocument ( refactorTargetFile ) ;
64+ const mockTextDoc = await workspace . openTextDocument ( refactorTargetFile ) ;
6465 const expectedTextEdits = getTextEditsFromPatch ( mockTextDoc . getText ( ) , DIFF ) ;
6566 try {
6667 const response = await proxy . extractVariable < RenameResponse > ( mockTextDoc , 'myNewVariable' , refactorTargetFile , rangeOfTextToExtract , options ) ;
@@ -81,27 +82,35 @@ suite('Variable Extraction', () => {
8182 }
8283 }
8384
84- test ( 'Extract Variable' , async ( ) => {
85- const startPos = new vscode . Position ( 234 , 29 ) ;
86- const endPos = new vscode . Position ( 234 , 38 ) ;
87- await testingVariableExtraction ( false , startPos , endPos ) ;
85+ // tslint:disable-next-line:no-function-expression
86+ test ( 'Extract Variable' , async function ( ) {
87+ const pyVersion : PythonVersionInformation = await ioc . getPythonMajorMinorVersion ( rootWorkspaceUri ) ;
88+
89+ if ( pyVersion . major === 3 && pyVersion . minor === 7 ) {
90+ // tslint:disable-next-line:no-invalid-this
91+ return this . skip ( ) ;
92+ } else {
93+ const startPos = new Position ( 234 , 29 ) ;
94+ const endPos = new Position ( 234 , 38 ) ;
95+ await testingVariableExtraction ( false , startPos , endPos ) ;
96+ }
8897 } ) ;
8998
9099 test ( 'Extract Variable fails if whole string not selected' , async ( ) => {
91- const startPos = new vscode . Position ( 234 , 20 ) ;
92- const endPos = new vscode . Position ( 234 , 38 ) ;
100+ const startPos = new Position ( 234 , 20 ) ;
101+ const endPos = new Position ( 234 , 38 ) ;
93102 await testingVariableExtraction ( true , startPos , endPos ) ;
94103 } ) ;
95104
96105 async function testingVariableExtractionEndToEnd ( shouldError : boolean , startPos : Position , endPos : Position ) : Promise < void > {
97106 const ch = new MockOutputChannel ( 'Python' ) ;
98- const rangeOfTextToExtract = new vscode . Range ( startPos , endPos ) ;
107+ const rangeOfTextToExtract = new Range ( startPos , endPos ) ;
99108
100- const textDocument = await vscode . workspace . openTextDocument ( refactorTargetFile ) ;
101- const editor = await vscode . window . showTextDocument ( textDocument ) ;
109+ const textDocument = await workspace . openTextDocument ( refactorTargetFile ) ;
110+ const editor = await window . showTextDocument ( textDocument ) ;
102111
103- editor . selections = [ new vscode . Selection ( rangeOfTextToExtract . start , rangeOfTextToExtract . end ) ] ;
104- editor . selection = new vscode . Selection ( rangeOfTextToExtract . start , rangeOfTextToExtract . end ) ;
112+ editor . selections = [ new Selection ( rangeOfTextToExtract . start , rangeOfTextToExtract . end ) ] ;
113+ editor . selection = new Selection ( rangeOfTextToExtract . start , rangeOfTextToExtract . end ) ;
105114 try {
106115 await extractVariable ( EXTENSION_DIR , editor , rangeOfTextToExtract , ch , ioc . serviceContainer ) ;
107116 if ( shouldError ) {
@@ -125,15 +134,15 @@ suite('Variable Extraction', () => {
125134 // This test fails on linux (text document not getting updated in time)
126135 if ( ! IS_CI_SERVER ) {
127136 test ( 'Extract Variable (end to end)' , async ( ) => {
128- const startPos = new vscode . Position ( 234 , 29 ) ;
129- const endPos = new vscode . Position ( 234 , 38 ) ;
137+ const startPos = new Position ( 234 , 29 ) ;
138+ const endPos = new Position ( 234 , 38 ) ;
130139 await testingVariableExtractionEndToEnd ( false , startPos , endPos ) ;
131140 } ) ;
132141 }
133142
134143 test ( 'Extract Variable fails if whole string not selected (end to end)' , async ( ) => {
135- const startPos = new vscode . Position ( 234 , 20 ) ;
136- const endPos = new vscode . Position ( 234 , 38 ) ;
144+ const startPos = new Position ( 234 , 20 ) ;
145+ const endPos = new Position ( 234 , 38 ) ;
137146 await testingVariableExtractionEndToEnd ( true , startPos , endPos ) ;
138147 } ) ;
139148} ) ;
0 commit comments