Exemplo n.º 1
0
        public static TestCase ToVsTestCase(
            this PytestTest test,
            string source,
            int line,
            Dictionary <string, PytestParent> parentMap,
            string projectHome
            )
        {
            if (parentMap == null)
            {
                throw new ArgumentException(nameof(parentMap));
            }
            if (String.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentException(nameof(source) + " " + test.ToString());
            }
            if (String.IsNullOrWhiteSpace(projectHome))
            {
                throw new ArgumentException(nameof(projectHome));
            }
            if (String.IsNullOrWhiteSpace(test.Name) ||
                String.IsNullOrWhiteSpace(test.Id))
            {
                throw new FormatException(test.ToString());
            }

            var pytestId           = CreateProperCasedPytestId(source, projectHome, test.Id);
            var fullyQualifiedName = CreateFullyQualifiedTestNameFromId(source, pytestId);
            var tc = new TestCase(fullyQualifiedName, PythonConstants.PytestExecutorUri, source)
            {
                DisplayName  = test.Name,
                LineNumber   = line,
                CodeFilePath = source
            };

            tc.SetPropertyValue(Constants.PytestIdProperty, pytestId);

            foreach (var marker in test.Markers.MaybeEnumerate())
            {
                tc.Traits.Add(new Trait(marker.ToString(), String.Empty));
            }

            return(tc);
        }
Exemplo n.º 2
0
        public static TestCase ToVsTestCase(
            this PytestTest test,
            string projectHome
            )
        {
            if (String.IsNullOrWhiteSpace(projectHome))
            {
                throw new ArgumentException(nameof(projectHome));
            }
            if (String.IsNullOrWhiteSpace(test.Name) ||
                String.IsNullOrWhiteSpace(test.Id))
            {
                throw new FormatException(test.ToString());
            }
            (string parsedSource, int line) = test.ParseSourceAndLine();
            // Note: we use _settings.ProjectHome and not result.root since it is being lowercased
            var sourceFullPath = Path.IsPathRooted(parsedSource) ? parsedSource : PathUtils.GetAbsoluteFilePath(projectHome, parsedSource);

            if (String.IsNullOrWhiteSpace(sourceFullPath))
            {
                throw new FormatException(nameof(sourceFullPath) + " " + test.ToString());
            }

            var pytestId           = CreateProperCasedPytestId(sourceFullPath, projectHome, test.Id);
            var fullyQualifiedName = CreateFullyQualifiedTestNameFromId(sourceFullPath, pytestId);
            var tc = new TestCase(fullyQualifiedName, PythonConstants.PytestExecutorUri, sourceFullPath)
            {
                DisplayName  = FixupParameterSets(test.Name),
                LineNumber   = line,
                CodeFilePath = sourceFullPath
            };

            tc.SetPropertyValue(Constants.PytestIdProperty, pytestId);

            foreach (var marker in test.Markers.MaybeEnumerate())
            {
                tc.Traits.Add(new Trait(marker.ToString(), String.Empty));
            }

            return(tc);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the relative source and line number from a PytestTest discovery result
        /// Example Test "source": ".\\test_user_marks.py:17",
        ///     returns  (test_user_marks.py, 17)
        /// </summary>
        /// <param name="test"></param>
        /// <returns></returns>
        public static (string, int) ParseSourceAndLine(this PytestTest test)
        {
            int line             = 0;
            var sourceAndLineNum = test.Source.Replace(".\\", "");
            var sourceParts      = sourceAndLineNum.Split(':');

            if (sourceParts.Length != 2 ||
                !Int32.TryParse(sourceParts[1], out line))
            {
                throw new FormatException(Strings.PytestInvalidTestSource.FormatUI(test.ToString()));
            }

            return(sourceParts[0], line);
        }