forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added system tests to check activation for virtual environments
- Loading branch information
Kartik Raj
committed
Dec 8, 2018
1 parent
1aa6c54
commit 061bc9f
Showing
7 changed files
with
157 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#Adds the virtual environment's executable path to json file | ||
|
||
import json,sys | ||
import os.path | ||
key = sys.argv[1] | ||
|
||
if os.path.isfile('$(ENV_PATHS_LOCATION)'): | ||
with open('$(ENV_PATHS_LOCATION)', 'r') as read_file: | ||
data = json.load(read_file) | ||
else: | ||
with open('$(ENV_PATHS_LOCATION)', 'w+') as read_file: | ||
data = {} | ||
with open('$(ENV_PATHS_LOCATION)', 'w') as outfile: | ||
data[key] = sys.executable | ||
json.dump(data, outfile, sort_keys=True, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...est/common/terminals/environmentActivationProviders/terminalActivation.testvirtualenvs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
// tslint:disable:max-func-body-length no-invalid-this no-any | ||
|
||
import { expect } from 'chai'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import { ENV_PATHS_LOCATION } from '../../../ciConstants'; | ||
import { PYTHON_PATH, restorePythonPathInWorkspaceRoot, setPythonPathInWorkspaceRoot, updateSetting, waitForCondition } from '../../../common'; | ||
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants'; | ||
import { sleep } from '../../../core'; | ||
import { initialize, initializeTest } from '../../../initialize'; | ||
|
||
suite('Activation of Environments in Terminal', () => { | ||
const file = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'testExecInTerminal.py'); | ||
const outputFile = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'testExecInTerminal.log'); | ||
const envPathsLocation = ENV_PATHS_LOCATION || path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'tmp', 'envPaths.json'); | ||
const waitTimeForActivation = 5000; | ||
type EnvPath = { | ||
venvPath: string; | ||
pipenvPath: string; | ||
virtualEnvPath: string; | ||
}; | ||
let envPaths: EnvPath; | ||
suiteSetup(async () => { | ||
envPaths = await fs.readJson(envPathsLocation); | ||
await initialize(); | ||
}); | ||
setup(async () => { | ||
await initializeTest(); | ||
await cleanUp(); | ||
}); | ||
teardown(cleanUp); | ||
suiteTeardown(revertSettings); | ||
async function revertSettings() { | ||
await updateSetting('terminal.activateEnvironment', undefined , vscode.workspace.workspaceFolders[0].uri, vscode.ConfigurationTarget.WorkspaceFolder); | ||
await restorePythonPathInWorkspaceRoot(); | ||
} | ||
async function cleanUp() { | ||
if (await fs.pathExists(outputFile)) { | ||
await fs.unlink(outputFile); | ||
} | ||
} | ||
async function testActivation(envPath){ | ||
await updateSetting('terminal.activateEnvironment', true, vscode.workspace.workspaceFolders[0].uri, vscode.ConfigurationTarget.WorkspaceFolder); | ||
await setPythonPathInWorkspaceRoot(envPath); | ||
const terminal = vscode.window.createTerminal(); | ||
await sleep(waitTimeForActivation); | ||
terminal.sendText(`python ${file}`, true); | ||
await waitForCondition(() => fs.pathExists(outputFile), 5_000, '\'testExecInTerminal.log\' file not created'); | ||
const content = await fs.readFile(outputFile, 'utf-8'); | ||
|
||
expect(content).to.equal(envPath); | ||
} | ||
async function testNonActivation(){ | ||
await updateSetting('terminal.activateEnvironment', false, vscode.workspace.workspaceFolders[0].uri, vscode.ConfigurationTarget.WorkspaceFolder); | ||
const terminal = vscode.window.createTerminal(); | ||
terminal.sendText(`python ${file}`, true); | ||
await waitForCondition(() => fs.pathExists(outputFile), 5_000, '\'testExecInTerminal.log\' file not created'); | ||
const content = await fs.readFile(outputFile, 'utf-8'); | ||
expect(content).to.not.equal(PYTHON_PATH); | ||
} | ||
test('Should not activate', async () => { | ||
await testNonActivation(); | ||
}); | ||
test('Should activate with venv', async () => { | ||
await testActivation(envPaths.venvPath); | ||
}); | ||
test('Should activate with pipenv', async () => { | ||
await testActivation(envPaths.pipenvPath); | ||
}); | ||
test('Should activate with virtualenv', async () => { | ||
await testActivation(envPaths.virtualEnvPath); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"condaPath": "C:\\Users\\karraj\\AppData\\Local\\Continuum\\anaconda3\\envs\\.conda\\python.exe", | ||
"pipenvPath": "C:\\Users\\karraj\\.virtualenvs\\test-mFICMEuQ\\Scripts\\python.exe", | ||
"venvPath": "C:\\Users\\karraj\\Desktop\\vscode-python\\src\\test\\.venv\\Scripts\\python.exe", | ||
"virtualEnvPath": "C:\\Users\\karraj\\Desktop\\.virtualenv\\Scripts\\python.exe" | ||
} |