本文整理汇总了C#中TestUtilities.UI.Python.PythonVisualStudioApp.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# PythonVisualStudioApp.GetService方法的具体用法?C# PythonVisualStudioApp.GetService怎么用?C# PythonVisualStudioApp.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestUtilities.UI.Python.PythonVisualStudioApp
的用法示例。
在下文中一共展示了PythonVisualStudioApp.GetService方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DjangoCollectStaticFilesCommand
public void DjangoCollectStaticFilesCommand() {
using (var app = new PythonVisualStudioApp()) {
var service = app.GetService<IComponentModel>(typeof(SComponentModel)).GetService<IInterpreterOptionsService>();
var envWithDjango = service.Interpreters.LastOrDefault(env => env.FindModulesAsync("django").WaitAndUnwrapExceptions().Contains("django"));
if (envWithDjango == null) {
Assert.Inconclusive("No available environments have Django installed");
}
using (var dis = new DefaultInterpreterSetter(envWithDjango)) {
var project = app.OpenProject("TestData\\DjangoApplication1\\DjangoApplication1.sln");
app.SolutionExplorerTreeView.SelectProject(project);
app.Dte.ExecuteCommand("Project.CollectStaticFiles");
var console = app.GetInteractiveWindow("Django Management Console - " + project.Name);
Assert.IsNotNull(console);
console.WaitForTextEnd("The Python REPL process has exited", ">>> ");
Assert.IsTrue(console.Text.Contains("0 static files copied"));
}
}
}
示例2: DeleteVirtualEnv
public void DeleteVirtualEnv() {
using (var app = new PythonVisualStudioApp())
using (var dis = Init(app)) {
var options = app.GetService<PythonToolsService>().GeneralOptions;
var oldAutoAnalyze = options.AutoAnalyzeStandardLibrary;
app.OnDispose(() => { options.AutoAnalyzeStandardLibrary = oldAutoAnalyze; options.Save(); });
options.AutoAnalyzeStandardLibrary = false;
options.Save();
var project = CreateTemporaryProject(app);
string envName, envPath;
TreeNode env;
using (var ps = new ProcessScope("Microsoft.PythonTools.Analyzer")) {
env = app.CreateVirtualEnvironment(project, out envName, out envPath);
Assert.IsFalse(ps.WaitForNewProcess(TimeSpan.FromSeconds(10)).Any(), "Unexpected analyzer processes");
}
// Need to wait some more for the database to be loaded.
app.WaitForNoDialog(TimeSpan.FromSeconds(10.0));
env.Select();
using (var removeDeleteDlg = RemoveItemDialog.FromDte(app)) {
removeDeleteDlg.Delete();
}
app.WaitForNoDialog(TimeSpan.FromSeconds(5.0));
app.OpenSolutionExplorer().WaitForChildOfProjectRemoved(
project,
SR.GetString(SR.Environments),
envName
);
var projectHome = (string)project.Properties.Item("ProjectHome").Value;
envPath = Path.Combine(projectHome, envPath);
for (int retries = 10;
Directory.Exists(envPath) && retries > 0;
--retries) {
Thread.Sleep(1000);
}
Assert.IsFalse(Directory.Exists(envPath), envPath);
}
}
示例3: AddItemPreviousSiblingNotVisible
public void AddItemPreviousSiblingNotVisible() {
using (var app = new PythonVisualStudioApp()) {
var project = app.OpenProject(@"TestData\AddItemPreviousSiblingNotVisible.sln");
app.OpenSolutionExplorer();
var window = app.SolutionExplorerTreeView;
var projectNode = window.WaitForItem("Solution 'AddItemPreviousSiblingNotVisible' (1 project)", "HelloWorld");
Assert.IsNotNull(projectNode);
AutomationWrapper.Select(projectNode);
var solutionService = app.GetService<IVsSolution>(typeof(SVsSolution));
Assert.IsNotNull(solutionService);
IVsHierarchy selectedHierarchy;
ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy));
Assert.IsNotNull(selectedHierarchy);
HierarchyEvents events = new HierarchyEvents();
uint cookie;
selectedHierarchy.AdviseHierarchyEvents(events, out cookie);
using (var newItem = NewItemDialog.FromDte(app)) {
AutomationWrapper.Select(newItem.ProjectTypes.FindItem("Empty Python File"));
newItem.FileName = "zmodule1.py";
newItem.OK();
}
var test2 = window.WaitForItem("Solution 'AddItemPreviousSiblingNotVisible' (1 project)", "HelloWorld", "zmodule1.py");
Assert.IsNotNull(test2);
selectedHierarchy.UnadviseHierarchyEvents(cookie);
object caption;
ErrorHandler.ThrowOnFailure(
selectedHierarchy.GetProperty(
events.SiblingPrev,
(int)__VSHPROPID.VSHPROPID_Caption,
out caption
)
);
Assert.AreEqual("Program.py", caption);
}
}
示例4: CloudProjectTest
private static void CloudProjectTest(string roleType, bool openServiceDefinition) {
Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType);
Assembly asm = null;
try {
asm = Assembly.Load("Microsoft.VisualStudio.CloudService.Wizard,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a");
} catch {
// Failed to load - we'll skip the test below
}
if (asm != null && asm.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
.OfType<AssemblyFileVersionAttribute>()
.Any(a => {
Version ver;
return Version.TryParse(a.Version, out ver) && ver < new Version(2, 5);
})
) {
Assert.Inconclusive("Test requires Microsoft Azure Tools 2.5 or later");
}
using (var app = new PythonVisualStudioApp())
using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"))) {
app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3);
var ccproj = app.Dte.Solution.Projects.Cast<Project>().FirstOrDefault(p => p.Name == "CloudProject");
Assert.IsNotNull(ccproj);
if (openServiceDefinition) {
var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open();
wnd.Activate();
app.OnDispose(() => wnd.Close());
}
IVsHierarchy hier;
var sln = app.GetService<IVsSolution>(typeof(SVsSolution));
ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier));
app.ServiceProvider.GetUIThread().InvokeAsync(() =>
PythonProjectNode.UpdateServiceDefinition(hier, roleType, roleType + "Role1", app.ServiceProvider)
).GetAwaiter().GetResult();
var doc = new XmlDocument();
for (int retries = 5; retries > 0; --retries) {
try {
doc.Load(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"));
break;
} catch (IOException ex) {
Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex);
} catch (XmlException) {
var copyTo = TestData.GetPath(@"TestData\CloudProject\" + Path.GetRandomFileName());
File.Copy(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"), copyTo);
Console.WriteLine("Copied file to " + copyTo);
throw;
}
Thread.Sleep(100);
}
var ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition");
doc.Save(Console.Out);
var nav = doc.CreateNavigator();
if (roleType == "Web") {
Assert.IsNotNull(nav.SelectSingleNode(
"/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='ps.cmd ConfigureCloudService.ps1']",
ns
));
} else if (roleType == "Worker") {
Assert.IsNotNull(nav.SelectSingleNode(
"/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='bin\\ps.cmd ConfigureCloudService.ps1']",
ns
));
Assert.IsNotNull(nav.SelectSingleNode(
"/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='bin\\ps.cmd LaunchWorker.ps1']",
ns
));
}
}
}
示例5: WebProjectBuildWarnings
public void WebProjectBuildWarnings() {
using (var app = new PythonVisualStudioApp())
using (app.SelectDefaultInterpreter(PythonPaths.Python33 ?? PythonPaths.Python33_x64)) {
var project = app.CreateProject(
PythonVisualStudioApp.TemplateLanguageName,
PythonVisualStudioApp.EmptyWebProjectTemplate,
TestData.GetTempPath(),
"WebProjectBuildWarnings"
);
var proj = project.GetPythonProject();
Assert.IsNotNull(proj);
Assert.AreEqual(new Version(3, 3), app.ServiceProvider.GetUIThread().Invoke(() => proj.GetLaunchConfigurationOrThrow().Interpreter.Version));
for (int iteration = 0; iteration <= 2; ++iteration) {
var warnings = app.ServiceProvider.GetUIThread().Invoke(() => {
var buildPane = app.GetOutputWindow("Build");
buildPane.Clear();
project.DTE.Solution.SolutionBuild.Clean(true);
project.DTE.Solution.SolutionBuild.Build(true);
var text = app.GetOutputWindowText("Build");
Console.WriteLine(text);
return text.Split('\r', '\n')
.Select(s => Regex.Match(s, @"warning\s*:\s*(?<msg>.+)"))
.Where(m => m.Success)
.Select(m => m.Groups["msg"].Value)
.ToList();
});
Console.WriteLine("Warnings:{0}{1}", Environment.NewLine, string.Join(Environment.NewLine, warnings));
if (iteration < 2) {
Assert.IsNotNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, @"Python( 64-bit)? 3\.3 is not natively supported.+")),
"Missing \"not natively supported\" warning"
);
} else {
// Third time through, we've fixed this warning.
Assert.IsNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, @"Python( 64-bit)? 3\.3 is not natively supported.+")),
"Still recieved \"not natively supported\" warning"
);
}
if (iteration < 1) {
Assert.IsNotNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, "Using old configuration tools.+")),
"Missing \"old configuration tools\" warning"
);
} else {
// Second time through, we've fixed this warning.
Assert.IsNull(
warnings.FirstOrDefault(s => Regex.IsMatch(s, "Using old configuration tools.+")),
"Still received \"old configuration tools\" warning"
);
}
switch (iteration) {
case 0:
app.AddItem(project, PythonVisualStudioApp.TemplateLanguageName, PythonVisualStudioApp.WebRoleSupportTemplate, "bin");
break;
case 1:
var model = app.GetService<IComponentModel>(typeof(SComponentModel));
var interpreterService = model.GetService<IInterpreterRegistryService>();
var optionsService = model.GetService<IInterpreterOptionsService>();
var newInterpreter = interpreterService.FindInterpreter("Global|PythonCore|3.4|x86")
?? interpreterService.FindInterpreter("Global|PythonCore|2.7|x86");
Assert.IsNotNull(newInterpreter);
optionsService.DefaultInterpreter = newInterpreter;
break;
}
}
}
}
示例6: AutoIndent
public void AutoIndent() {
using (var app = new PythonVisualStudioApp()) {
var options = app.GetService<PythonToolsService>().AdvancedOptions;
var prevSetting = options.AddNewLineAtEndOfFullyTypedWord;
app.OnDispose(() => options.AddNewLineAtEndOfFullyTypedWord = prevSetting);
options.AddNewLineAtEndOfFullyTypedWord = true;
var project = app.OpenProject(@"TestData\AutoIndent.sln");
// http://pytools.codeplex.com/workitem/116
AutoIndentTest(app, project, "def f():\rprint 'hi'\r\rdef inner(): pass←←←←←←←←←←←←←←←←←\r", @"def f():
print 'hi'
def inner(): pass");
// http://pytools.codeplex.com/workitem/121
AutoIndentTest(app, project, "x = {'a': [1, 2, 3],\r\r'b':42}", @"x = {'a': [1, 2, 3],
'b':42}");
AutoIndentTest(app, project, "x = { #comment\r'a': [\r1,\r2,\r3\r],\r\r'b':42\r}", @"x = { #comment
'a': [
1,
2,
3
],
'b':42
}");
AutoIndentTest(app, project, "if True:\rpass\r\r42\r\r", @"if True:
pass
42
");
AutoIndentTest(app, project, "def f():\rreturn\r\r42\r\r", @"def f():
return
42
");
AutoIndentTest(app, project, "if True: #fob\rpass\relse: #oar\rpass\r\r42\r\r", @"if True: #fob
pass
else: #oar
pass
42
");
AutoIndentTest(app, project, "if True:\rraise Exception()\r\r42\r\r", @"if True:
raise Exception()
42
");
AutoIndentTest(app, project, "while True:\rcontinue\r\r42\r\r", @"while True:
continue
42
");
AutoIndentTest(app, project, "while True:\rbreak\r\r42\r\r", @"while True:
break
42
");
// http://pytools.codeplex.com/workitem/127
AutoIndentTest(app, project, "print ('%s, %s' %\r(1, 2))", @"print ('%s, %s' %
(1, 2))");
// http://pytools.codeplex.com/workitem/125
AutoIndentTest(app, project, "def f():\rx = (\r7)\rp", @"def f():
x = (
7)
p");
AutoIndentTest(app, project, "def f():\rassert False, \\\r'A message'\rp", @"def f():
assert False, \
'A message'
p");
// other tests...
AutoIndentTest(app, project, "1 +\\\r2 +\\\r3 +\\\r4 + 5\r", @"1 +\
2 +\
3 +\
4 + 5
");
AutoIndentTest(app, project, "x = {42 :\r42}\rp", @"x = {42 :
42}
//.........这里部分代码省略.........
示例7: OutlineTest
private void OutlineTest(string filename, params ExpectedTag[] expected) {
using (var app = new PythonVisualStudioApp()) {
var prevOption = app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen;
try {
app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen = true;
var project = app.OpenProject(@"TestData\Outlining.sln");
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
var tags = doc.GetTaggerAggregator<IOutliningRegionTag>(doc.TextView.TextBuffer).GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length));
VerifyTags(doc.TextView.TextBuffer, tags, expected);
} finally {
app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen = prevOption;
}
}
}