public InterpretersNode( PythonProjectNode project, ProjectItem item, IPythonInterpreterFactory factory, bool isInterpreterReference, bool canDelete, bool isGlobalDefault = false ) : base(project, ChooseElement(project, item)) { ExcludeNodeFromScc = true; _interpreters = project.Interpreters; _interpreterService = project.Site.GetComponentModel().GetService<IInterpreterOptionsService>(); _factory = factory; _isReference = isInterpreterReference; _canDelete = canDelete; _isGlobalDefault = isGlobalDefault; _canRemove = !isGlobalDefault; _captionSuffix = isGlobalDefault ? SR.GetString(SR.GlobalDefaultSuffix) : ""; if (Directory.Exists(_factory.Configuration.LibraryPath)) { // TODO: Need to handle watching for creation try { _fileWatcher = new FileSystemWatcher(_factory.Configuration.LibraryPath); } catch (ArgumentException) { // Path was not actually valid, despite Directory.Exists // returning true. } if (_fileWatcher != null) { try { _fileWatcher.IncludeSubdirectories = true; _fileWatcher.Deleted += PackagesChanged; _fileWatcher.Created += PackagesChanged; _fileWatcher.EnableRaisingEvents = true; // Only create the timer if the file watcher is running. _timer = new Timer(CheckPackages); } catch (IOException) { // Raced with directory deletion _fileWatcher.Dispose(); _fileWatcher = null; } } } }
public string GetCurrentTest(string filePath, int line, int lineCharOffset) { var project = PathToProject(filePath); if (project != null && _discoverer.IsProjectKnown(project)) { var buildEngine = new MSBuild.ProjectCollection(); string projectPath; if (project.TryGetProjectPath(out projectPath)) { var proj = buildEngine.LoadProject(projectPath); var provider = new MSBuildProjectInterpreterFactoryProvider(_interpreterService, proj); try { provider.DiscoverInterpreters(); } catch (InvalidDataException) { // This exception can be safely ignored here. } var factory = provider.ActiveInterpreter; var parser = Parser.CreateParser( new StreamReader(filePath), factory.GetLanguageVersion() ); var ast = parser.ParseFile(); var walker = new FunctionFinder(ast, line, lineCharOffset); ast.Walk(walker); var projHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, proj.GetPropertyValue(PythonConstants.ProjectHomeSetting) ?? ".")); if (walker.ClassName != null && walker.FunctionName != null) { return TestAnalyzer.MakeFullyQualifiedTestName( CommonUtils.CreateFriendlyFilePath(projHome, filePath), walker.ClassName, walker.FunctionName ); } } } return null; }
public ConfiguredFactoryInfo(MSBuildProjectInterpreterFactoryProvider factoryProvider, InterpreterConfiguration config) : base(config) { _factoryProvider = factoryProvider; }
public void UnavailableEnvironments() { var collection = new Microsoft.Build.Evaluation.ProjectCollection(); try { var service = new MockInterpreterOptionsService(); var proj = collection.LoadProject(TestData.GetPath(@"TestData\Environments\Unavailable.pyproj")); using (var provider = new MSBuildProjectInterpreterFactoryProvider(service, proj)) { try { provider.DiscoverInterpreters(); Assert.Fail("Expected InvalidDataException in DiscoverInterpreters"); } catch (InvalidDataException ex) { AssertUtil.AreEqual(ex.Message .Replace(TestData.GetPath("TestData\\Environments\\"), "$") .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Trim()), "Some project interpreters failed to load:", @"Interpreter $env\ has invalid value for 'Id': INVALID ID", @"Interpreter $env\ has invalid value for 'Version': INVALID VERSION", @"Interpreter $env\ has invalid value for 'BaseInterpreter': INVALID BASE", @"Interpreter $env\ has invalid value for 'InterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'WindowsInterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'LibraryPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'BaseInterpreter': {98512745-4ac7-4abb-9f33-120af32edc77}" ); } var factories = provider.GetInterpreterFactories().ToList(); foreach (var fact in factories) { Console.WriteLine("{0}: {1}", fact.GetType().FullName, fact.Description); } foreach (var fact in factories) { Assert.IsInstanceOfType( fact, typeof(MSBuildProjectInterpreterFactoryProvider.NotFoundInterpreterFactory), string.Format("{0} was not correct type", fact.Description) ); Assert.IsFalse(provider.IsAvailable(fact), string.Format("{0} was not unavailable", fact.Description)); } AssertUtil.AreEqual(factories.Select(f => f.Description), "Invalid BaseInterpreter (unavailable)", "Invalid InterpreterPath (unavailable)", "Invalid WindowsInterpreterPath (unavailable)", "Invalid LibraryPath (unavailable)", "Absent BaseInterpreter (unavailable)", "Unknown Python 2.7" ); } } finally { collection.UnloadAllProjects(); collection.Dispose(); } }
public void UnavailableEnvironments() { var collection = new Microsoft.Build.Evaluation.ProjectCollection(); try { var service = new MockInterpreterOptionsService(); var proj = collection.LoadProject(TestData.GetPath(@"TestData\Environments\Unavailable.pyproj")); var contextProvider = new MockProjectContextProvider(proj); var logger = new MockLogger(); using (var provider = new MSBuildProjectInterpreterFactoryProvider( new[] { new Lazy<IProjectContextProvider>(() => contextProvider) }, null, new[] { new Lazy<IInterpreterLog>(() => logger) })) { var configs = provider.GetInterpreterConfigurations().ToArray(); // force the load... AssertUtil.AreEqual( logger.Errors.ToString() .Replace(TestData.GetPath("TestData\\Environments\\"), "$") .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select(s => s.Trim()), @"Interpreter $env\ has invalid value for 'Id':", @"Interpreter $env\ has invalid value for 'Version': INVALID VERSION", @"Interpreter $env\ has invalid value for 'InterpreterPath': INVALID<>PATH", @"Interpreter $env\ has invalid value for 'WindowsInterpreterPath': INVALID<>PATH" ); var factories = provider.GetInterpreterFactories().ToList(); foreach (var fact in factories) { Console.WriteLine("{0}: {1}", fact.GetType().FullName, fact.Configuration.Description); } foreach (var fact in factories) { Assert.IsInstanceOfType( fact, typeof(NotFoundInterpreterFactory), string.Format("{0} was not correct type", fact.Configuration.Description) ); Assert.IsFalse(fact.Configuration.IsAvailable(), string.Format("{0} was not unavailable", fact.Configuration.Description)); } AssertUtil.AreEqual(factories.Select(f => f.Configuration.Description), "Invalid InterpreterPath (unavailable)", "Invalid WindowsInterpreterPath (unavailable)" ); } } finally { collection.UnloadAllProjects(); collection.Dispose(); } }
public ProjectInfo(IVsProject project, TestContainerDiscoverer discoverer, MSBuildProjectInterpreterFactoryProvider factoryProvider) { Project = project; Discoverer = discoverer; FactoryProvider = factoryProvider; ActiveInterpreter = FactoryProvider.ActiveInterpreter; Attach(); HookNewDatabaseAvailable(); }
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) { ValidateArg.NotNull(sources, "sources"); ValidateArg.NotNull(discoverySink, "discoverySink"); var buildEngine = new MSBuild.ProjectCollection(); try { // Load all the test containers passed in (.pyproj msbuild files) foreach (string source in sources) { buildEngine.LoadProject(source); } foreach (var proj in buildEngine.LoadedProjects) { using (var provider = new MSBuildProjectInterpreterFactoryProvider(_interpreterService, proj)) { try { provider.DiscoverInterpreters(); } catch (InvalidDataException) { // This exception can be safely ignored here. } var factory = provider.ActiveInterpreter; if (factory == _interpreterService.NoInterpretersValue) { if (logger != null) { logger.SendMessage(TestMessageLevel.Warning, "No interpreters available for project " + proj.FullPath); } continue; } var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, proj.GetPropertyValue(PythonConstants.ProjectHomeSetting) ?? ".")); // Do the analysis even if the database is not up to date. At // worst, we'll get no results. using (var analyzer = new TestAnalyzer( factory, proj.FullPath, projectHome, TestExecutor.ExecutorUri )) { // Provide all files to the test analyzer foreach (var item in proj.GetItems("Compile")) { string fileAbsolutePath = CommonUtils.GetAbsoluteFilePath(projectHome, item.EvaluatedInclude); string fullName; try { fullName = ModulePath.FromFullPath(fileAbsolutePath).ModuleName; } catch (ArgumentException) { if (logger != null) { logger.SendMessage(TestMessageLevel.Warning, "File has an invalid module name: " + fileAbsolutePath); } continue; } try { using (var reader = new StreamReader(fileAbsolutePath)) { analyzer.AddModule(fullName, fileAbsolutePath, reader); } } catch (FileNotFoundException) { // user deleted file, we send the test update, but the project // isn't saved. #if DEBUG } catch (Exception ex) { if (logger != null) { logger.SendMessage(TestMessageLevel.Warning, "Failed to discover tests in " + fileAbsolutePath); logger.SendMessage(TestMessageLevel.Informational, ex.ToString()); } } #else } catch (Exception) { if (logger != null) { logger.SendMessage(TestMessageLevel.Warning, "Failed to discover tests in " + fileAbsolutePath); } } #endif }
public ConfiguredFactoryInfo(MSBuildProjectInterpreterFactoryProvider factoryProvider, InterpreterConfiguration baseConfig, InterpreterConfiguration config) : base(config) { _factoryProvider = factoryProvider; _baseConfig = baseConfig; }