public void WatchWorkspaceVirtualEnvCreated() { var python = PythonPaths.Python37_x64 ?? PythonPaths.Python37; var workspaceFolder = TestData.GetTempPath(); Directory.CreateDirectory(workspaceFolder); File.WriteAllText(Path.Combine(workspaceFolder, "app.py"), string.Empty); string envFolder = Path.Combine(workspaceFolder, "env"); var workspace = new MockWorkspace(workspaceFolder); var workspaceService = new MockWorkspaceService(workspace); // Create virtual env inside the workspace folder (one level from root) Action triggerDiscovery = () => { 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); } }; var configs = TestTriggerDiscovery(workspaceService, triggerDiscovery).ToArray(); Assert.AreEqual(1, configs.Length); Assert.IsTrue(PathUtils.IsSamePath( Path.Combine(envFolder, "scripts", "python.exe"), configs[0].InterpreterPath )); Assert.AreEqual("Workspace|Workspace|env", configs[0].Id); }
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 void WatchWorkspaceVirtualEnvCreated() { var python = PythonPaths.Python37_x64 ?? PythonPaths.Python37; var workspaceFolder = TestData.GetTempPath(); Directory.CreateDirectory(workspaceFolder); File.WriteAllText(Path.Combine(workspaceFolder, "app.py"), string.Empty); string envFolder = Path.Combine(workspaceFolder, "env"); var workspace = new MockWorkspace(workspaceFolder); var workspaceService = new MockWorkspaceService(workspace); // Create virtual env inside the workspace folder (one level from root) var configs = TestTriggerDiscovery( workspaceService, () => CreatePythonVirtualEnv(python.InterpreterPath, workspaceFolder, "env") ).ToArray(); Assert.AreEqual(1, configs.Length); Assert.IsTrue(PathUtils.IsSamePath( Path.Combine(envFolder, "scripts", "python.exe"), configs[0].InterpreterPath )); Assert.AreEqual("Workspace|Workspace|env", configs[0].Id); }
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); } }
public void WatchWorkspaceFolderChanged() { var workspaceFolder1 = TestData.GetTempPath(); Directory.CreateDirectory(workspaceFolder1); File.WriteAllText(Path.Combine(workspaceFolder1, "app1.py"), string.Empty); var workspaceFolder2 = TestData.GetTempPath(); Directory.CreateDirectory(workspaceFolder2); File.WriteAllText(Path.Combine(workspaceFolder2, "app2.py"), string.Empty); var workspace1 = new MockWorkspace(workspaceFolder1); var workspace2 = new MockWorkspace(workspaceFolder2); var workspaceService = new MockWorkspaceService(workspace1); // Load a different workspace Action triggerDiscovery = () => { workspaceService.ChangeWorkspace(workspace2); }; TestTriggerDiscovery(workspaceService, triggerDiscovery); }