private IEnumerable <KeyValuePair <string, TestCase> > GetTestCases() { var moduleCache = new Dictionary <string, ModulePath>(); foreach (var test in _tests) { string testFile, testClass, testMethod; TestReader.ParseFullyQualifiedTestName( test.FullyQualifiedName, out testFile, out testClass, out testMethod ); ModulePath module; if (!moduleCache.TryGetValue(testFile, out module)) { string testFilePath = PathUtils.GetAbsoluteFilePath(_settings.ProjectHome, testFile); moduleCache[testFile] = module = ModulePath.FromFullPath(testFilePath); } yield return(new KeyValuePair <string, TestCase>("{0}.{1}.{2}".FormatInvariant( module.ModuleName, testClass, testMethod ), test)); } }
private static string GetCoveragePath(IEnumerable<TestCase> tests) { string bestFile = null, bestClass = null, bestMethod = null; // Try and generate a friendly name for the coverage report. We use // the filename, class, and method. We include each one if we're // running from a single filename/class/method. When we have multiple // we drop the identifying names. If we have multiple files we // go to the top level directory... If all else fails we do "pycov". foreach (var test in tests) { string testFile, testClass, testMethod; TestReader.ParseFullyQualifiedTestName( test.FullyQualifiedName, out testFile, out testClass, out testMethod ); bestFile = UpdateBestFile(bestFile, test.CodeFilePath); if (bestFile != test.CodeFilePath) { // Different files, don't include class/methods even // if they happen to be the same. bestClass = bestMethod = ""; } bestClass = UpdateBest(bestClass, testClass); bestMethod = UpdateBest(bestMethod, testMethod); } string filename = ""; if (!String.IsNullOrWhiteSpace(bestFile)) { if (ModulePath.IsPythonSourceFile(bestFile)) { filename = ModulePath.FromFullPath(bestFile).ModuleName; } else { filename = Path.GetFileName(bestFile); } } else { filename = "pycov"; } if (!String.IsNullOrWhiteSpace(bestClass)) { filename += "_" + bestClass; } if (!String.IsNullOrWhiteSpace(bestMethod)) { filename += "_" + bestMethod; } filename += "_" + DateTime.Now.ToString("s").Replace(':', '_'); return Path.Combine(Path.GetTempPath(), filename); }
private string[] GetArguments() { var arguments = new List <string>(); arguments.Add(TestLauncherPath); foreach (var test in _tests) { arguments.Add("-t"); string testFile, testClass, testMethod; TestReader.ParseFullyQualifiedTestName( test.FullyQualifiedName, out testFile, out testClass, out testMethod ); string testFilePath = PathUtils.GetAbsoluteFilePath(_settings.ProjectHome, testFile); var module = ModulePath.FromFullPath(testFilePath); arguments.Add( string.Format("{0}.{1}.{2}", module.ModuleName, testClass, testMethod ) ); } if (_codeCoverageFile != null) { arguments.Add("--coverage"); arguments.Add(_codeCoverageFile); } if (_debugMode == PythonDebugMode.PythonOnly) { arguments.AddRange(new[] { "-s", _debugSecret, "-p", _debugPort.ToString() }); } else if (_debugMode == PythonDebugMode.PythonAndNative) { arguments.Add("-x"); } arguments.Add("-r"); arguments.Add(((IPEndPoint)_socket.LocalEndPoint).Port.ToString()); return(arguments.ToArray()); }
private void ConectionReceivedEvent(object sender, EventReceivedEventArgs e) { switch (e.Name) { case TP.ResultEvent.Name: var result = (TP.ResultEvent)e.Event; TestOutcome outcome = TestOutcome.None; switch (result.outcome) { case "passed": outcome = TestOutcome.Passed; break; case "failed": outcome = TestOutcome.Failed; break; case "skipped": outcome = TestOutcome.Skipped; break; } var testResult = new TestResult(_curTest); RecordEnd( _frameworkHandle, _curTest, testResult, _stdOut.ToString(), _stdErr.ToString(), outcome, result ); _stdOut.Clear(); _stdErr.Clear(); break; case TP.StartEvent.Name: var start = (TP.StartEvent)e.Event; _curTest = null; foreach (var test in _tests) { string testFile, testClass, testMethod; TestReader.ParseFullyQualifiedTestName( test.FullyQualifiedName, out testFile, out testClass, out testMethod ); string testFilePath = PathUtils.GetAbsoluteFilePath(_settings.ProjectHome, test.CodeFilePath); var modulePath = ModulePath.FromFullPath(testFilePath); if (start.test == modulePath.ModuleName + "." + testClass + "." + testMethod) { _curTest = test; break; } } if (_curTest != null) { _frameworkHandle.RecordStart(_curTest); } else { Warning(Strings.Test_UnexpectedResult.FormatUI(start.classname, start.method)); } break; case TP.StdErrEvent.Name: var err = (TP.StdErrEvent)e.Event; _stdErr.Append(err.content); break; case TP.StdOutEvent.Name: var outp = (TP.StdOutEvent)e.Event; _stdOut.Append(outp.content); break; case TP.DoneEvent.Name: _done.Set(); break; } }