예제 #1
0
        public void RemoveInterpreterNotInUse()
        {
            var data = PrepareWorkspace(WorkspaceTestHelper.Python27Id);

            var workspaceContext = new PythonWorkspaceContext(data.Workspace, data.OptionsService, data.RegistryService);

            workspaceContext.Initialize();

            var interpreter = workspaceContext.ReadInterpreterSetting();

            Assert.AreEqual(WorkspaceTestHelper.Python27Id, interpreter);
            Assert.AreEqual(WorkspaceTestHelper.Python27Factory, workspaceContext.CurrentFactory);

            using (var activeInterpreterEvent = new AutoResetEvent(false)) {
                workspaceContext.ActiveInterpreterChanged += (sender, e) => {
                    activeInterpreterEvent.Set();
                };

                // Uninstall Python 3.7 - not in use
                var newFactories = WorkspaceTestHelper.AllFactories.Except(WorkspaceTestHelper.Python37Factory);
                data.RegistryService.SimulateChangeInterpreters(newFactories);

                Assert.IsFalse(activeInterpreterEvent.WaitOne(1000), "Should not have raised ActiveInterpreterChanged.");

                var updatedInterpreter = workspaceContext.ReadInterpreterSetting();
                Assert.AreEqual(WorkspaceTestHelper.Python27Id, updatedInterpreter);
                Assert.AreEqual(WorkspaceTestHelper.Python27Factory, workspaceContext.CurrentFactory);
            }
        }
예제 #2
0
        public void ChangeDefaultInterpreterNotInUse()
        {
            // We don't use the global default
            var data = PrepareWorkspace(WorkspaceTestHelper.Python27Id);

            var workspaceContext = new PythonWorkspaceContext(data.Workspace, data.OptionsService, data.RegistryService);

            workspaceContext.Initialize();

            var interpreter = workspaceContext.ReadInterpreterSetting();

            Assert.AreEqual(WorkspaceTestHelper.Python27Id, interpreter);
            Assert.AreEqual(WorkspaceTestHelper.Python27Factory, workspaceContext.CurrentFactory);

            using (var activeInterpreterEvent = new AutoResetEvent(false)) {
                workspaceContext.ActiveInterpreterChanged += (sender, e) => {
                    activeInterpreterEvent.Set();
                };

                data.OptionsService.SimulateChangeDefaultInterpreter(WorkspaceTestHelper.Python37Factory);

                Assert.IsFalse(activeInterpreterEvent.WaitOne(1000), "Should not have raised ActiveInterpreterChanged.");

                var updatedInterpreter = workspaceContext.ReadInterpreterSetting();
                Assert.AreEqual(WorkspaceTestHelper.Python27Id, updatedInterpreter);
                Assert.AreEqual(WorkspaceTestHelper.Python27Factory, workspaceContext.CurrentFactory);
            }
        }
예제 #3
0
        public void ChangeDefaultInterpreterInUse()
        {
            TestSetupData data = PrepareWorkspace(WorkspaceTestHelper.PythonNoId);

            var workspaceContext = new PythonWorkspaceContext(data.Workspace, data.OptionsService, data.RegistryService);

            workspaceContext.Initialize();

            var interpreter = workspaceContext.ReadInterpreterSetting();

            Assert.AreEqual(WorkspaceTestHelper.PythonNoId, interpreter);
            Assert.AreEqual(WorkspaceTestHelper.DefaultFactory, workspaceContext.CurrentFactory);

            using (var activeInterpreterEvent = new AutoResetEvent(false))
            {
                workspaceContext.ActiveInterpreterChanged += (sender, e) =>
                {
                    activeInterpreterEvent.Set();
                };

                data.OptionsService.SimulateChangeDefaultInterpreter(WorkspaceTestHelper.Python37Factory);

                Assert.IsTrue(activeInterpreterEvent.WaitOne(1000), "Failed to raise ActiveInterpreterChanged.");

                var updatedInterpreter = workspaceContext.ReadInterpreterSetting();
                Assert.AreEqual(WorkspaceTestHelper.PythonNoId, updatedInterpreter);
                Assert.AreEqual(WorkspaceTestHelper.Python37Factory, workspaceContext.CurrentFactory);
            }
        }
예제 #4
0
        public void ChangeInterpreterSetting()
        {
            TestSetupData data = PrepareWorkspace(WorkspaceTestHelper.Python27Id);

            var workspaceContext = new PythonWorkspaceContext(data.Workspace, data.OptionsService, data.RegistryService);

            workspaceContext.Initialize();

            var interpreter = workspaceContext.ReadInterpreterSetting();

            Assert.AreEqual(WorkspaceTestHelper.Python27Id, interpreter);
            Assert.AreEqual(WorkspaceTestHelper.Python27Factory, workspaceContext.CurrentFactory);

            using (var activeInterpreterEvent = new AutoResetEvent(false))
                using (var interpreterSettingEvent = new AutoResetEvent(false))
                {
                    workspaceContext.ActiveInterpreterChanged += (sender, e) =>
                    {
                        activeInterpreterEvent.Set();
                    };

                    workspaceContext.InterpreterSettingChanged += (sender, e) =>
                    {
                        interpreterSettingEvent.Set();
                    };

                    WorkspaceTestHelper.MockWorkspaceSettings updatedSettings = new WorkspaceTestHelper.MockWorkspaceSettings(
                        new Dictionary <string, string> {
                        { "Interpreter", WorkspaceTestHelper.Python37Id }
                    }
                        );
                    data.Workspace.SettingsManager.SimulateChangeSettings(updatedSettings);

                    Assert.IsTrue(activeInterpreterEvent.WaitOne(1000), "Failed to raise ActiveInterpreterChanged.");
                    Assert.IsTrue(interpreterSettingEvent.WaitOne(1000), "Failed to raise InterpreterSettingChanged.");

                    var updatedInterpreter = workspaceContext.ReadInterpreterSetting();
                    Assert.AreEqual(WorkspaceTestHelper.Python37Id, updatedInterpreter);
                    Assert.AreEqual(WorkspaceTestHelper.Python37Factory, workspaceContext.CurrentFactory);
                }
        }
예제 #5
0
        public void UnavailableInterpreter()
        {
            var data = PrepareWorkspace(WorkspaceTestHelper.PythonUnavailableId);

            var workspaceContext = new PythonWorkspaceContext(data.Workspace, data.OptionsService, data.RegistryService);

            workspaceContext.Initialize();

            var interpreter = workspaceContext.ReadInterpreterSetting();

            Assert.AreEqual(WorkspaceTestHelper.PythonUnavailableId, interpreter);
            Assert.AreEqual(WorkspaceTestHelper.DefaultFactory, workspaceContext.CurrentFactory);
        }
예제 #6
0
        public void InstalledInterpreter()
        {
            TestSetupData data = PrepareWorkspace(WorkspaceTestHelper.Python27Id);

            var workspaceContext = new PythonWorkspaceContext(data.Workspace, data.OptionsService, data.RegistryService);

            workspaceContext.Initialize();

            var interpreter = workspaceContext.ReadInterpreterSetting();

            Assert.AreEqual(WorkspaceTestHelper.Python27Id, interpreter);
            Assert.AreEqual(WorkspaceTestHelper.Python27Factory, workspaceContext.CurrentFactory);
        }