public void WatchWorkspaceSettingsChanged() { var workspaceFolder = TestData.GetTempPath(); Directory.CreateDirectory(workspaceFolder); File.WriteAllText(Path.Combine(workspaceFolder, "app.py"), string.Empty); var aggregatedSettings1 = new MockWorkspaceSettings( new Dictionary <string, string> { { "Interpreter", null } } ); var aggregatedSettings2 = new MockWorkspaceSettings( new Dictionary <string, string> { { "Interpreter", "Global|PythonCore|3.7" } } ); var settingsManager = new MockWorkspaceSettingsManager(aggregatedSettings1); var workspace = new MockWorkspace(workspaceFolder, settingsManager); var workspaceService = new MockWorkspaceService(workspace); // Modify settings Action triggerDiscovery = () => { settingsManager.ChangeSettings(aggregatedSettings2); }; TestTriggerDiscovery(workspaceService, triggerDiscovery); }
public static MockWorkspace CreateMockWorkspace(string workspaceFolder, string interpreterSetting) { var aggregatedSettings = new MockWorkspaceSettings( new Dictionary <string, string> { { "Interpreter", interpreterSetting } } ); var settingsManager = new MockWorkspaceSettingsManager(aggregatedSettings); return(new MockWorkspace(workspaceFolder, settingsManager)); }
public void DetectLocalEnvOutsideWorkspace() { var python = PythonPaths.Python37_x64 ?? PythonPaths.Python37; var tempFolder = TestData.GetTempPath(); var workspaceFolder = Path.Combine(tempFolder, "workspace"); var envFolder = Path.Combine(tempFolder, "outside"); Directory.CreateDirectory(workspaceFolder); File.WriteAllText(Path.Combine(workspaceFolder, "app.py"), string.Empty); // Create virtual env outside the workspace folder using (var p = ProcessOutput.RunHiddenAndCapture(python.InterpreterPath, "-m", "venv", envFolder)) { Console.WriteLine(p.Arguments); p.Wait(); Console.WriteLine(string.Join(Environment.NewLine, p.StandardOutputLines.Concat(p.StandardErrorLines))); Assert.AreEqual(0, p.ExitCode); } // Normally a local virtual environment outside the workspace // wouldn't be detected, but it is when it's referenced from // the workspace python settings. var aggregatedSettings = new MockWorkspaceSettings( new Dictionary <string, string> { { "Interpreter", @"..\outside\scripts\python.exe" } } ); var settingsManager = new MockWorkspaceSettingsManager(aggregatedSettings); var workspace = new MockWorkspace(workspaceFolder, settingsManager); var workspaceService = new MockWorkspaceService(workspace); using (var provider = new WorkspaceInterpreterFactoryProvider(workspaceService)) { var configs = provider.GetInterpreterConfigurations().ToArray(); Assert.AreEqual(1, configs.Length); Assert.IsTrue(PathUtils.IsSamePath( Path.Combine(envFolder, "scripts", "python.exe"), configs[0].InterpreterPath )); Assert.AreEqual("Workspace|Workspace|outside", configs[0].Id); } }