예제 #1
0
        private static void FullStdLibTest(PythonVersion v) {
            v.AssertInstalled();
            var modules = ModulePath.GetModulesInLib(v.PrefixPath).ToList();
            var paths = modules.Select(m => m.LibraryPath).Distinct().ToArray();

            bool anySuccess = false;

            using (var analyzer = new PythonAnalysis(v.Version)) {
                analyzer.SetSearchPaths(paths);

                foreach (var modName in modules) {
                    if (modName.IsCompiled || modName.IsNativeExtension) {
                        continue;
                    }
                    var mod = analyzer.Analyzer.Interpreter.ImportModule(modName.ModuleName);
                    if (mod == null) {
                        Trace.TraceWarning("failed to import {0} from {1}".FormatInvariant(modName.ModuleName, modName.SourceFile));
                    } else {
                        anySuccess = true;
                        mod.GetMemberNames(analyzer.ModuleContext).ToList();
                    }
                }
            }
            Assert.IsTrue(anySuccess, "failed to import any modules at all");
        }
예제 #2
0
        private void BuiltinsProfile(PythonVersion interp, string[] expectedFunctions, string[] expectedNonFunctions) {
            interp.AssertInstalled();

            EnvDTE.Project project;
            IPythonProfiling profiling;
            using (var app = OpenProfileTestProject(out project, out profiling, null)) {
                var session = LaunchProcess(app, profiling, interp.Id.ToString() + ";" + interp.Version.ToVersion().ToString(),
                    TestData.GetPath(@"TestData\ProfileTest\BuiltinsProfile.py"),
                    TestData.GetPath(@"TestData\ProfileTest"),
                    "",
                    false
                );
                try {
                    while (profiling.IsProfiling) {
                        Thread.Sleep(100);
                    }

                    var report = session.GetReport(1);
                    var filename = report.Filename;
                    Assert.IsTrue(filename.Contains("BuiltinsProfile"));

                    Assert.IsNull(session.GetReport(2));

                    Assert.IsNotNull(session.GetReport(report.Filename));
                    Assert.IsTrue(File.Exists(filename));

                    if (expectedFunctions != null && expectedFunctions.Length > 0) {
                        VerifyReport(report, true, expectedFunctions);
                    }
                    if (expectedNonFunctions != null && expectedNonFunctions.Length > 0) {
                        VerifyReport(report, false, expectedNonFunctions);
                    }
                } finally {
                    profiling.RemoveSession(session, false);
                }
            }
        }
예제 #3
0
        private void TestOpen(PythonVersion path) {
            path.AssertInstalled();
            Console.WriteLine(path.InterpreterPath);

            Guid testId = Guid.NewGuid();
            var testDir = TestData.GetTempPath(testId.ToString());

            // run the scraper
            using (var proc = ProcessOutput.RunHiddenAndCapture(
                path.InterpreterPath,
                TestData.GetPath("PythonScraper.py"),
                testDir,
                TestData.GetPath("CompletionDB")
            )) {
                Console.WriteLine("Command: " + proc.Arguments);

                proc.Wait();

                // it should succeed
                Console.WriteLine("**Stdout**");
                foreach (var line in proc.StandardOutputLines) {
                    Console.WriteLine(line);
                }
                Console.WriteLine("");
                Console.WriteLine("**Stdout**");
                foreach (var line in proc.StandardErrorLines) {
                    Console.WriteLine(line);
                }
                
                Assert.AreEqual(0, proc.ExitCode, "Bad exit code: " + proc.ExitCode);
            }

            // perform some basic validation
            dynamic builtinDb = Unpickle.Load(new FileStream(Path.Combine(testDir, path.Version.Is3x() ? "builtins.idb" : "__builtin__.idb"), FileMode.Open, FileAccess.Read));
            if (path.Version.Is2x()) { // no open in 3.x
                foreach (var overload in builtinDb["members"]["open"]["value"]["overloads"]) {
                    Assert.AreEqual("__builtin__", overload["ret_type"][0][0]);
                    Assert.AreEqual("file", overload["ret_type"][0][1]);
                }

                if (!path.InterpreterPath.Contains("Iron")) {
                    // http://pytools.codeplex.com/workitem/799
                    var arr = (IList<object>)builtinDb["members"]["list"]["value"]["members"]["__init__"]["value"]["overloads"];
                    Assert.AreEqual(
                        "args",
                        ((dynamic)(arr[0]))["args"][1]["name"]
                    );
                }
            }

            if (!path.InterpreterPath.Contains("Iron")) {
                dynamic itertoolsDb = Unpickle.Load(new FileStream(Path.Combine(testDir, "itertools.idb"), FileMode.Open, FileAccess.Read));
                var tee = itertoolsDb["members"]["tee"]["value"];
                var overloads = tee["overloads"];
                var nArg = overloads[0]["args"][1];
                Assert.AreEqual("n", nArg["name"]);
                Assert.AreEqual("2", nArg["default_value"]);

                dynamic sreDb = Unpickle.Load(new FileStream(Path.Combine(testDir, "_sre.idb"), FileMode.Open, FileAccess.Read));
                var members = sreDb["members"];
                Assert.IsTrue(members.ContainsKey("SRE_Pattern"));
                Assert.IsTrue(members.ContainsKey("SRE_Match"));
            }

            Console.WriteLine("Passed: {0}", path.InterpreterPath);
        }
예제 #4
0
        private void TestMutateStdLib(PythonVersion version) {
            version.AssertInstalled();

            for (int i = 0; i < 100; i++) {
                int seed = (int)DateTime.Now.Ticks;
                var random = new Random(seed);
                Console.WriteLine("Seed == " + seed);


                Console.WriteLine("Testing version {0} {1}", version.Version, Path.Combine(version.PrefixPath, "Lib"));
                int ran = 0, succeeded = 0;
                string[] files;
                try {
                    files = Directory.GetFiles(Path.Combine(version.PrefixPath, "Lib"));
                } catch (DirectoryNotFoundException) {
                    continue;
                }

                foreach (var file in files) {
                    try {
                        if (file.EndsWith(".py")) {
                            ran++;
                            TestOneFileMutated(file, version.Version, random);
                            succeeded++;
                        }
                    } catch (Exception e) {
                        Console.WriteLine(e);
                        Console.WriteLine("Failed: {0}", file);
                        break;
                    }
                }

                Assert.AreEqual(ran, succeeded);
            }
        }