Browse Source

Python menu options now use the debugger when running ipy.exe

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4159 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 17 years ago
parent
commit
10c8a90ed8
  1. 24
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin
  2. 3
      src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj
  3. 23
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IsPythonRunningCondition.cs
  4. 19
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunDebugPythonCommand.cs
  5. 117
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs
  6. 101
      src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs
  7. 63
      src/AddIns/BackendBindings/Python/PythonBinding/Test/DebugPythonCommandTestFixture.cs
  8. 7
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj
  9. 82
      src/AddIns/BackendBindings/Python/PythonBinding/Test/RunPythonCommandTestFixture.cs
  10. 73
      src/AddIns/BackendBindings/Python/PythonBinding/Test/StopPythonCommandTestFixture.cs
  11. 178
      src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDebugger.cs

24
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin

@ -55,21 +55,23 @@
insertbefore="Tools" insertbefore="Tools"
label="&Python" label="&Python"
type="Menu"> type="Menu">
<ComplexCondition action="Disable"> <Condition name="IsProcessRunning" isprocessrunning="False" isdebugging="False" action="Disable">
<Not>
<Condition name="IsPythonRunning"/>
</Not>
<MenuItem id="Run" <MenuItem id="Run"
icon="Icons.16x16.RunProgramIcon" icon="Icons.16x16.RunProgramIcon"
class="ICSharpCode.PythonBinding.RunPythonCommand" class="ICSharpCode.PythonBinding.RunDebugPythonCommand"
label="&amp;Run" label="${res:XML.MainMenu.RunMenu.Run}"
shortcut="Control|Shift|R"/> shortcut="Control|Shift|R"/>
</ComplexCondition> <MenuItem id="RunWithoutDebugger"
<Condition name="IsPythonRunning" action="Disable"> icon="Icons.16x16.Debug.StartWithoutDebugging"
class="ICSharpCode.PythonBinding.RunPythonCommand"
label="${res:XML.MainMenu.DebugMenu.RunWithoutDebug}"
shortcut="Control|Shift|W"/>
</Condition>
<Condition name="IsProcessRunning" isdebugging="True" action="Disable">
<MenuItem id="Stop" <MenuItem id="Stop"
icon="Icons.16x16.Debug.StopProcess" icon="Icons.16x16.StopProcess"
class="ICSharpCode.PythonBinding.StopPythonCommand" class="ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand"
label="&amp;Stop"/> label="${res:XML.MainMenu.DebugMenu.Stop}"/>
</Condition> </Condition>
</MenuItem> </MenuItem>
</Condition> </Condition>

3
src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj

@ -74,7 +74,6 @@
<Compile Include="Src\IMemberProvider.cs" /> <Compile Include="Src\IMemberProvider.cs" />
<Compile Include="Src\IPadDescriptor.cs" /> <Compile Include="Src\IPadDescriptor.cs" />
<Compile Include="Src\IProcessRunner.cs" /> <Compile Include="Src\IProcessRunner.cs" />
<Compile Include="Src\IsPythonRunningCondition.cs" />
<Compile Include="Src\ITextEditor.cs" /> <Compile Include="Src\ITextEditor.cs" />
<Compile Include="Src\NRefactoryToPythonConverter.cs" /> <Compile Include="Src\NRefactoryToPythonConverter.cs" />
<Compile Include="Src\PythonAstWalker.cs" /> <Compile Include="Src\PythonAstWalker.cs" />
@ -110,9 +109,9 @@
<Compile Include="Src\PythonProject.cs" /> <Compile Include="Src\PythonProject.cs" />
<Compile Include="Src\PythonPropertyValueAssignment.cs" /> <Compile Include="Src\PythonPropertyValueAssignment.cs" />
<Compile Include="Src\PythonResolver.cs" /> <Compile Include="Src\PythonResolver.cs" />
<Compile Include="Src\RunDebugPythonCommand.cs" />
<Compile Include="Src\RunPythonCommand.cs" /> <Compile Include="Src\RunPythonCommand.cs" />
<Compile Include="Src\StandardPythonModules.cs" /> <Compile Include="Src\StandardPythonModules.cs" />
<Compile Include="Src\StopPythonCommand.cs" />
<Compile Include="Src\PythonVariableResolver.cs" /> <Compile Include="Src\PythonVariableResolver.cs" />
<Compile Include="Src\TextEditor.cs" /> <Compile Include="Src\TextEditor.cs" />
<None Include="PythonBinding.addin"> <None Include="PythonBinding.addin">

23
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IsPythonRunningCondition.cs

@ -1,23 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Indicates whether the python console is running.
/// </summary>
public class IsPythonRunningCondition : IConditionEvaluator
{
public bool IsValid(object caller, Condition condition)
{
return RunPythonCommand.IsRunning;
}
}
}

19
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/StopPythonCommand.cs → src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunDebugPythonCommand.cs

@ -1,4 +1,4 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt"/> // <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/> // <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/> // <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
@ -7,26 +7,23 @@
using System; using System;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Util; using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.PythonBinding namespace ICSharpCode.PythonBinding
{ {
/// <summary> public class RunDebugPythonCommand : RunPythonCommand
/// Stops the Python console that is currently running.
/// </summary>
public class StopPythonCommand : AbstractMenuCommand
{ {
public StopPythonCommand() public RunDebugPythonCommand(IWorkbench workbench, AddInOptions options, IDebugger debugger)
: base(workbench, options, debugger)
{ {
Debug = true;
} }
public override void Run() public RunDebugPythonCommand()
: this(WorkbenchSingleton.Workbench, new AddInOptions(), DebuggerService.CurrentDebugger)
{ {
RunPythonCommand runCommand = RunPythonCommand.RunningCommand;
if (runCommand != null) {
runCommand.Stop();
}
} }
} }
} }

117
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs

@ -6,7 +6,9 @@
// </file> // </file>
using System; using System;
using System.Diagnostics;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Util; using ICSharpCode.SharpDevelop.Util;
@ -18,116 +20,55 @@ namespace ICSharpCode.PythonBinding
/// </summary> /// </summary>
public class RunPythonCommand : AbstractMenuCommand public class RunPythonCommand : AbstractMenuCommand
{ {
IProcessRunner processRunner; IDebugger debugger;
AddInOptions options; AddInOptions options;
IWorkbench workbench; IWorkbench workbench;
MessageViewCategory category; bool debug;
IPadDescriptor outputWindowPad;
static MessageViewCategory categorySingleton;
static RunPythonCommand runningCommand;
public RunPythonCommand() public RunPythonCommand()
: this(WorkbenchSingleton.Workbench, new AddInOptions(), new PythonProcessRunner(), PythonMessageViewCategory, new PythonOutputWindowPadDescriptor()) : this(WorkbenchSingleton.Workbench, new AddInOptions(), DebuggerService.CurrentDebugger)
{ {
} }
public RunPythonCommand(IWorkbench workbench, AddInOptions options, IProcessRunner processRunner, MessageViewCategory category, IPadDescriptor outputWindowPad) public RunPythonCommand(IWorkbench workbench, AddInOptions options, IDebugger debugger)
{ {
this.processRunner = processRunner;
this.options = options;
this.workbench = workbench; this.workbench = workbench;
this.category = category; this.debugger = debugger;
this.outputWindowPad = outputWindowPad; this.options = options;
processRunner.OutputLineReceived += OutputLineReceived;
processRunner.ProcessExited += ProcessExited;
} }
/// <summary> public bool Debug {
/// Indicates whether the command is still running. get { return debug; }
/// </summary> set { debug = value; }
public static bool IsRunning {
get {
return runningCommand != null;
}
} }
/// <summary>
/// Gets the command that is currently running.
/// </summary>
public static RunPythonCommand RunningCommand {
get {
return runningCommand;
}
}
/// <summary>
/// Runs the python console passing the filename to the currently
/// active python script.
/// </summary>
public override void Run() public override void Run()
{ {
// Get the python script filename. if (debug) {
string fileName = workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName; debugger.Start(CreateProcessStartInfo());
} else {
// Clear the output window. debugger.StartWithoutDebugging(CreateProcessStartInfo());
outputWindowPad.BringPadToFront();
category.ClearText();
// Start the python console app passing the python script filename.
CategoryWriteLine("Running Python...");
string args = String.Concat('\"', fileName, '\"');
CategoryWriteLine(String.Concat(options.PythonFileName, " ", args));
processRunner.Start(options.PythonFileName, args);
runningCommand = this;
}
/// <summary>
/// Stops the python console.
/// </summary>
public void Stop()
{
if (runningCommand != null) {
runningCommand = null;
processRunner.Kill();
}
}
/// <summary>
/// Creates the single instance of the
/// </summary>
static MessageViewCategory PythonMessageViewCategory {
get {
if (categorySingleton == null) {
MessageViewCategory.Create(ref categorySingleton, "Python");
}
return categorySingleton;
} }
} }
/// <summary> ProcessStartInfo CreateProcessStartInfo()
/// Handler for the ProcessRunner's output line received event.
/// </summary>
void OutputLineReceived(object source, LineReceivedEventArgs e)
{ {
CategoryWriteLine(e.Line); ProcessStartInfo info = new ProcessStartInfo();
info.FileName = options.PythonFileName;
info.Arguments = GetArguments();
return info;
} }
/// <summary> string GetArguments()
/// Handler for the process exit event.
/// </summary>
void ProcessExited(object source, EventArgs e)
{ {
runningCommand = null; // Get the python script filename.
string pythonScriptFileName = "\"" + workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName + "\"";
if (Debug) {
return "-D " + pythonScriptFileName;
}
return pythonScriptFileName;
} }
/// <summary>
/// Writes a line of text to the output window.
/// </summary>
void CategoryWriteLine(string message)
{
category.AppendText(String.Concat(message, Environment.NewLine));
}
} }
} }

101
src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs

@ -28,6 +28,7 @@ namespace PythonBinding.Tests
Codon fileFilterCodon; Codon fileFilterCodon;
Codon pythonMenuCodon; Codon pythonMenuCodon;
Codon pythonRunMenuItemCodon; Codon pythonRunMenuItemCodon;
Codon pythonWithoutDebuggerRunMenuItemCodon;
Codon pythonStopMenuItemCodon; Codon pythonStopMenuItemCodon;
Codon fileTemplatesCodon; Codon fileTemplatesCodon;
Codon optionsPanelCodon; Codon optionsPanelCodon;
@ -63,6 +64,7 @@ namespace PythonBinding.Tests
const string runMenuExtensionPath = "/SharpDevelop/Workbench/MainMenu/Python"; const string runMenuExtensionPath = "/SharpDevelop/Workbench/MainMenu/Python";
pythonRunMenuItemCodon = GetCodon(runMenuExtensionPath, "Run"); pythonRunMenuItemCodon = GetCodon(runMenuExtensionPath, "Run");
pythonWithoutDebuggerRunMenuItemCodon = GetCodon(runMenuExtensionPath, "RunWithoutDebugger");
pythonStopMenuItemCodon = GetCodon(runMenuExtensionPath, "Stop"); pythonStopMenuItemCodon = GetCodon(runMenuExtensionPath, "Stop");
fileTemplatesCodon = GetCodon("/SharpDevelop/BackendBindings/Templates", "Python"); fileTemplatesCodon = GetCodon("/SharpDevelop/BackendBindings/Templates", "Python");
@ -232,7 +234,7 @@ namespace PythonBinding.Tests
[Test] [Test]
public void PythonStopMenuItemLabel() public void PythonStopMenuItemLabel()
{ {
Assert.AreEqual("&Stop", pythonStopMenuItemCodon["label"]); Assert.AreEqual("${res:XML.MainMenu.DebugMenu.Stop}", pythonStopMenuItemCodon["label"]);
} }
[Test] [Test]
@ -244,19 +246,19 @@ namespace PythonBinding.Tests
[Test] [Test]
public void PythonStopMenuItemClass() public void PythonStopMenuItemClass()
{ {
Assert.AreEqual("ICSharpCode.PythonBinding.StopPythonCommand", pythonStopMenuItemCodon["class"]); Assert.AreEqual("ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand", pythonStopMenuItemCodon["class"]);
} }
[Test] [Test]
public void PythonStopMenuItemIcon() public void PythonStopMenuItemIcon()
{ {
Assert.AreEqual("Icons.16x16.Debug.StopProcess", pythonStopMenuItemCodon["icon"]); Assert.AreEqual("Icons.16x16.StopProcess", pythonStopMenuItemCodon["icon"]);
} }
[Test] [Test]
public void PythonRunMenuItemLabel() public void PythonRunMenuItemLabel()
{ {
Assert.AreEqual("&Run", pythonRunMenuItemCodon["label"]); Assert.AreEqual("${res:XML.MainMenu.RunMenu.Run}", pythonRunMenuItemCodon["label"]);
} }
[Test] [Test]
@ -268,7 +270,7 @@ namespace PythonBinding.Tests
[Test] [Test]
public void PythonRunMenuItemClass() public void PythonRunMenuItemClass()
{ {
Assert.AreEqual("ICSharpCode.PythonBinding.RunPythonCommand", pythonRunMenuItemCodon["class"]); Assert.AreEqual("ICSharpCode.PythonBinding.RunDebugPythonCommand", pythonRunMenuItemCodon["class"]);
} }
[Test] [Test]
@ -290,26 +292,26 @@ namespace PythonBinding.Tests
} }
[Test] [Test]
public void PythonRunMenuNotConditionExists() public void PythonRunMenuConditionName()
{ {
NegatedCondition notCondition = pythonRunMenuItemCodon.Conditions[0] as NegatedCondition; Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.IsNotNull(notCondition); Assert.IsNotNull("IsProcessRunning", condition.Name);
} }
[Test] [Test]
public void PythonRunMenuNotCondition() public void PythonRunMenuConditionIsDebuggingProperty()
{ {
NegatedCondition notCondition = pythonRunMenuItemCodon.Conditions[0] as NegatedCondition; Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("False", condition["isdebugging"]);
// Use reflection to get the ICondition associated with the not
// condition.
Type type = notCondition.GetType();
FieldInfo fieldInfo = type.GetField("condition", BindingFlags.NonPublic | BindingFlags.Instance);
ICondition condition = fieldInfo.GetValue(notCondition) as ICondition;
Assert.AreEqual("IsPythonRunning", condition.Name);
} }
[Test]
public void PythonRunMenuConditionIsProcessRunningProperty()
{
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("False", condition["isprocessrunning"]);
}
[Test] [Test]
public void PythonRunMenuConditionAction() public void PythonRunMenuConditionAction()
{ {
@ -318,17 +320,30 @@ namespace PythonBinding.Tests
} }
[Test] [Test]
public void PythonStopMenuConditionAction() public void PythonStopMenuHasSingleCondition()
{ {
ICondition condition = pythonStopMenuItemCodon.Conditions[0]; Assert.AreEqual(1, pythonStopMenuItemCodon.Conditions.Length);
Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
} }
[Test] [Test]
public void PythonStopMenuConditionName() public void PythonStopMenuConditionName()
{
Condition condition = pythonStopMenuItemCodon.Conditions[0] as Condition;
Assert.IsNotNull("IsProcessRunning", condition.Name);
}
[Test]
public void PythonStopMenuConditionIsDebuggingProperty()
{
Condition condition = pythonStopMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("True", condition["isdebugging"]);
}
[Test]
public void PythonStopMenuConditionAction()
{ {
ICondition condition = pythonStopMenuItemCodon.Conditions[0]; ICondition condition = pythonStopMenuItemCodon.Conditions[0];
Assert.AreEqual("IsPythonRunning", condition.Name); Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
} }
[Test] [Test]
@ -704,6 +719,48 @@ namespace PythonBinding.Tests
Condition condition = convertVBNetProjectCodon.Conditions[0] as Condition; Condition condition = convertVBNetProjectCodon.Conditions[0] as Condition;
Assert.AreEqual("VBNet", condition["activeproject"]); Assert.AreEqual("VBNet", condition["activeproject"]);
} }
[Test]
public void PythonRunWithoutDebuggerMenuItemLabel()
{
Assert.AreEqual("${res:XML.MainMenu.DebugMenu.RunWithoutDebug}", pythonWithoutDebuggerRunMenuItemCodon["label"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemIsMenuItem()
{
Assert.AreEqual("MenuItem", pythonWithoutDebuggerRunMenuItemCodon.Name);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.RunPythonCommand", pythonWithoutDebuggerRunMenuItemCodon["class"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemShortcut()
{
Assert.AreEqual("Control|Shift|W", pythonWithoutDebuggerRunMenuItemCodon["shortcut"]);
}
[Test]
public void PythonRunWithoutDebuggerMenuItemIcon()
{
Assert.AreEqual("Icons.16x16.Debug.StartWithoutDebugging", pythonWithoutDebuggerRunMenuItemCodon["icon"]);
}
[Test]
public void PythonDebugRunMenuHasSingleCondition()
{
Assert.AreEqual(1, pythonWithoutDebuggerRunMenuItemCodon.Conditions.Length);
}
[Test]
public void PythonDebugRunConditionIsSameAsPythonRunCondition()
{
Assert.AreEqual(pythonWithoutDebuggerRunMenuItemCodon.Conditions[0], pythonRunMenuItemCodon.Conditions[0]);
}
Codon GetCodon(string name, string extensionPath) Codon GetCodon(string name, string extensionPath)
{ {

63
src/AddIns/BackendBindings/Python/PythonBinding/Test/DebugPythonCommandTestFixture.cs

@ -0,0 +1,63 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.PythonBinding;
using PythonBinding.Tests.Utils;
using NUnit.Framework;
namespace PythonBinding.Tests
{
[TestFixture]
public class DebugPythonCommandTestFixture
{
MockDebugger debugger;
RunDebugPythonCommand command;
[TestFixtureSetUp]
public void SetUpFixture()
{
// Create dummy view content with the Python script.
MockViewContent viewContent = new MockViewContent();
viewContent.PrimaryFileName = @"C:\Projects\test.py";
MockWorkbenchWindow workbenchWindow = new MockWorkbenchWindow();
workbenchWindow.ActiveViewContent = viewContent;
MockWorkbench workbench = new MockWorkbench();
workbench.ActiveWorkbenchWindow = workbenchWindow;
// Create the Python binding addin options.
Properties p = new Properties();
AddInOptions options = new AddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe";
debugger = new MockDebugger();
command = new RunDebugPythonCommand(workbench, options, debugger);
command.Run();
}
[Test]
public void DebuggerStartMethodCalled()
{
Assert.IsTrue(debugger.StartMethodCalled);
}
[Test]
public void ProcessInfoFileName()
{
Assert.AreEqual(@"C:\IronPython\ipy.exe", debugger.ProcessStartInfo.FileName);
}
[Test]
public void ProcessInfoArgs()
{
Assert.AreEqual("-D \"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments);
}
}
}

7
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj

@ -152,6 +152,7 @@
<Compile Include="Converter\VBClassConversionTestFixture.cs" /> <Compile Include="Converter\VBClassConversionTestFixture.cs" />
<Compile Include="Converter\VBStringConcatTestFixture.cs" /> <Compile Include="Converter\VBStringConcatTestFixture.cs" />
<Compile Include="Converter\WhileLoopConversionTestFixture.cs" /> <Compile Include="Converter\WhileLoopConversionTestFixture.cs" />
<Compile Include="DebugPythonCommandTestFixture.cs" />
<Compile Include="Designer\CreateDesignerComponentTests.cs" /> <Compile Include="Designer\CreateDesignerComponentTests.cs" />
<Compile Include="Designer\CursorTypeResolutionTestFixture.cs" /> <Compile Include="Designer\CursorTypeResolutionTestFixture.cs" />
<Compile Include="Designer\DeserializeAssignmentTestFixtureBase.cs" /> <Compile Include="Designer\DeserializeAssignmentTestFixtureBase.cs" />
@ -277,7 +278,6 @@
<Compile Include="Resolver\ResolveSystemNamespaceTestFixture.cs" /> <Compile Include="Resolver\ResolveSystemNamespaceTestFixture.cs" />
<Compile Include="Resolver\ResolveUnknownNamespaceTestFixture.cs" /> <Compile Include="Resolver\ResolveUnknownNamespaceTestFixture.cs" />
<Compile Include="RunPythonCommandTestFixture.cs" /> <Compile Include="RunPythonCommandTestFixture.cs" />
<Compile Include="StopPythonCommandTestFixture.cs" />
<Compile Include="Utils\AddedComponent.cs" /> <Compile Include="Utils\AddedComponent.cs" />
<Compile Include="Utils\AddInHelper.cs" /> <Compile Include="Utils\AddInHelper.cs" />
<Compile Include="Utils\BrowseButtonInfo.cs" /> <Compile Include="Utils\BrowseButtonInfo.cs" />
@ -297,6 +297,7 @@
<Compile Include="Utils\DerivedToolStripMenuItem.cs" /> <Compile Include="Utils\DerivedToolStripMenuItem.cs" />
<Compile Include="Utils\MockClass.cs" /> <Compile Include="Utils\MockClass.cs" />
<Compile Include="Utils\MockComponentCreator.cs" /> <Compile Include="Utils\MockComponentCreator.cs" />
<Compile Include="Utils\MockDebugger.cs" />
<Compile Include="Utils\MockDesignerGenerator.cs" /> <Compile Include="Utils\MockDesignerGenerator.cs" />
<Compile Include="Utils\MockDesignerLoaderHost.cs" /> <Compile Include="Utils\MockDesignerLoaderHost.cs" />
<Compile Include="Utils\MockEditableViewContent.cs" /> <Compile Include="Utils\MockEditableViewContent.cs" />
@ -349,6 +350,10 @@
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project> <Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name> <Name>ICSharpCode.SharpDevelop.Dom</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\DisplayBindings\FormsDesigner\Project\FormsDesigner.csproj"> <ProjectReference Include="..\..\..\..\DisplayBindings\FormsDesigner\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project> <Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name> <Name>FormsDesigner</Name>

82
src/AddIns/BackendBindings/Python/PythonBinding/Test/RunPythonCommandTestFixture.cs

@ -22,11 +22,8 @@ namespace PythonBinding.Tests
[TestFixture] [TestFixture]
public class RunPythonCommandTestFixture public class RunPythonCommandTestFixture
{ {
MockProcessRunner processRunner; MockDebugger debugger;
MessageViewCategory messageViewCategory; RunPythonCommand command;
bool messageViewCategoryCleared;
MockPadDescriptor padDescriptor;
bool isRunning;
[TestFixtureSetUp] [TestFixtureSetUp]
public void SetUpFixture() public void SetUpFixture()
@ -38,90 +35,39 @@ namespace PythonBinding.Tests
workbenchWindow.ActiveViewContent = viewContent; workbenchWindow.ActiveViewContent = viewContent;
MockWorkbench workbench = new MockWorkbench(); MockWorkbench workbench = new MockWorkbench();
workbench.ActiveWorkbenchWindow = workbenchWindow; workbench.ActiveWorkbenchWindow = workbenchWindow;
// Create a dummy output window pad descriptor.
padDescriptor = new MockPadDescriptor();
// Create the Python binding addin options. // Create the Python binding addin options.
Properties p = new Properties(); Properties p = new Properties();
AddInOptions options = new AddInOptions(p); AddInOptions options = new AddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe"; options.PythonFileName = @"C:\IronPython\ipy.exe";
// Create the process runner. debugger = new MockDebugger();
processRunner = new MockProcessRunner(); command = new RunPythonCommand(workbench, options, debugger);
processRunner.OutputText = "Test\r\nOutput";
// Create the message view category.
messageViewCategory = new MessageViewCategory("Python");
messageViewCategory.TextSet += MessageViewCategoryCleared;
// Run the command.
RunPythonCommand command = new RunPythonCommand(workbench, options, processRunner, messageViewCategory, padDescriptor);
command.Run(); command.Run();
// Check that the IsPythonRunning thinks the command is still
// running.
IsPythonRunningCondition condition = new IsPythonRunningCondition();
isRunning = condition.IsValid(null, null);
// The python console process exits.
processRunner.RaiseExitEvent();
} }
[Test] [Test]
public void CommandLine() public void RunPythonCommandIsAbstractCommand()
{ {
// Check the correct filename was used to execute the command. Assert.IsNotNull(command as AbstractCommand);
Assert.AreEqual("C:\\IronPython\\ipy.exe \"C:\\Projects\\test.py\"", processRunner.CommandLine);
} }
[Test] [Test]
public void MessageViewCategoryClearTextCalled() public void DebuggerStartWithoutDebuggingMethodCalled()
{ {
Assert.IsTrue(messageViewCategoryCleared); Assert.IsTrue(debugger.StartWithoutDebuggingMethodCalled);
} }
/// <summary>
/// Message view category should have the command line
/// used to start the python console and any output from it.
/// </summary>
[Test] [Test]
public void MessageViewCategoryText() public void ProcessInfoFileName()
{ {
string expectedText = "Running Python...\r\n" + Assert.AreEqual(@"C:\IronPython\ipy.exe", debugger.ProcessStartInfo.FileName);
"C:\\IronPython\\ipy.exe \"C:\\Projects\\test.py\"\r\n" +
"Test\r\n" +
"Output\r\n";
Assert.AreEqual(expectedText, messageViewCategory.Text);
} }
[Test] [Test]
public void OutputWindowPadBroughtToFront() public void ProcessInfoArgs()
{
Assert.IsTrue(padDescriptor.BringPadToFrontCalled);
}
/// <summary>
/// Until the ipy.exe process exits the RunPythonCommand
/// should return true from the IsRunning property.
/// </summary>
[Test]
public void IsPythonRunningBeforeExit()
{
Assert.IsTrue(isRunning);
}
[Test]
public void IsPythonRunningAfterExit()
{
IsPythonRunningCondition condition = new IsPythonRunningCondition();
Assert.IsFalse(condition.IsValid(null, null));
}
void MessageViewCategoryCleared(object sender, TextEventArgs e)
{ {
if (e.Text == "") Assert.AreEqual("\"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments);
messageViewCategoryCleared = true;
} }
} }
} }

73
src/AddIns/BackendBindings/Python/PythonBinding/Test/StopPythonCommandTestFixture.cs

@ -1,73 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using ICSharpCode.Core;
using ICSharpCode.PythonBinding;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using NUnit.Framework;
using PythonBinding.Tests.Utils;
namespace PythonBinding.Tests
{
/// <summary>
/// Tests that the StopPythonCommand kills the python console process.
/// </summary>
[TestFixture]
public class StopPythonCommandTestFixture
{
MockProcessRunner processRunner;
[TestFixtureSetUp]
public void SetUpFixture()
{
// Create dummy view content with the Python script.
MockViewContent viewContent = new MockViewContent();
viewContent.PrimaryFileName = @"C:\Projects\test.py";
MockWorkbenchWindow workbenchWindow = new MockWorkbenchWindow();
workbenchWindow.ActiveViewContent = viewContent;
MockWorkbench workbench = new MockWorkbench();
workbench.ActiveWorkbenchWindow = workbenchWindow;
// Create a dummy output window pad descriptor.
MockPadDescriptor padDescriptor = new MockPadDescriptor();
// Create the Python binding addin options.
Properties p = new Properties();
AddInOptions options = new AddInOptions(p);
options.PythonFileName = @"C:\IronPython\ipy.exe";
// Create the process runner.
processRunner = new MockProcessRunner();
// Create the message view category.
MessageViewCategory messageViewCategory = new MessageViewCategory("Python");
// Run the command.
RunPythonCommand command = new RunPythonCommand(workbench, options, processRunner, messageViewCategory, padDescriptor);
command.Run();
StopPythonCommand stopCommand = new StopPythonCommand();
stopCommand.Run();
}
[Test]
public void IsStopped()
{
// Check that the IsPythonRunning thinks the command has stopped
IsPythonRunningCondition condition = new IsPythonRunningCondition();
Assert.IsFalse(condition.IsValid(null, null));
}
[Test]
public void ProcessRunnerStopped()
{
Assert.IsTrue(processRunner.KillCalled);
}
}
}

178
src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDebugger.cs

@ -0,0 +1,178 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Project;
namespace PythonBinding.Tests.Utils
{
public class MockDebugger : IDebugger
{
ProcessStartInfo processStartInfo;
bool startMethodCalled;
bool startWithoutDebuggingMethodCalled;
bool stopMethodCalled;
public MockDebugger()
{
}
/// <summary>
/// Gets the ProcessStartInfo passed to the Start or StartWithoutDebugging methods.
/// </summary>
public ProcessStartInfo ProcessStartInfo {
get { return processStartInfo; }
}
public bool StartMethodCalled {
get { return startMethodCalled; }
}
public bool StartWithoutDebuggingMethodCalled {
get { return startWithoutDebuggingMethodCalled; }
}
public bool StopMethodCalled {
get { return stopMethodCalled; }
}
public event EventHandler DebugStarting;
public event EventHandler DebugStarted;
public event EventHandler IsProcessRunningChanged;
public event EventHandler DebugStopped;
public bool IsDebugging {
get {
throw new NotImplementedException();
}
}
public bool IsProcessRunning {
get {
throw new NotImplementedException();
}
}
public bool CanDebug(IProject project)
{
throw new NotImplementedException();
}
public void Start(ProcessStartInfo processStartInfo)
{
this.processStartInfo = processStartInfo;
startMethodCalled = true;
}
public void StartWithoutDebugging(ProcessStartInfo processStartInfo)
{
this.processStartInfo = processStartInfo;
startWithoutDebuggingMethodCalled = true;
}
public void Stop()
{
stopMethodCalled = true;
}
public void Break()
{
throw new NotImplementedException();
}
public void Continue()
{
throw new NotImplementedException();
}
public void StepInto()
{
throw new NotImplementedException();
}
public void StepOver()
{
throw new NotImplementedException();
}
public void StepOut()
{
throw new NotImplementedException();
}
public void ShowAttachDialog()
{
throw new NotImplementedException();
}
public void Attach(System.Diagnostics.Process process)
{
throw new NotImplementedException();
}
public void Detach()
{
throw new NotImplementedException();
}
public string GetValueAsString(string variable)
{
throw new NotImplementedException();
}
public DebuggerGridControl GetTooltipControl(string variable)
{
throw new NotImplementedException();
}
public bool CanSetInstructionPointer(string filename, int line, int column)
{
throw new NotImplementedException();
}
public bool SetInstructionPointer(string filename, int line, int column)
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
protected virtual void OnDebugStarting(EventArgs e)
{
if (DebugStarting != null) {
DebugStarting(this, e);
}
}
protected virtual void OnDebugStarted(EventArgs e)
{
if (DebugStarted != null) {
DebugStarted(this, e);
}
}
protected virtual void OnIsProcessRunningChanged(EventArgs e)
{
if (IsProcessRunningChanged != null) {
IsProcessRunningChanged(this, e);
}
}
protected virtual void OnDebugStopped(EventArgs e)
{
if (DebugStopped != null) {
DebugStopped(this, e);
}
}
}
}
Loading…
Cancel
Save