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

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

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

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

@ -1,23 +0,0 @@ @@ -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 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
@ -7,26 +7,23 @@ @@ -7,26 +7,23 @@
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Util;
namespace ICSharpCode.PythonBinding
{
/// <summary>
/// Stops the Python console that is currently running.
/// </summary>
public class StopPythonCommand : AbstractMenuCommand
public class RunDebugPythonCommand : RunPythonCommand
{
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 @@ @@ -6,7 +6,9 @@
// </file>
using System;
using System.Diagnostics;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Util;
@ -18,116 +20,55 @@ namespace ICSharpCode.PythonBinding @@ -18,116 +20,55 @@ namespace ICSharpCode.PythonBinding
/// </summary>
public class RunPythonCommand : AbstractMenuCommand
{
IProcessRunner processRunner;
IDebugger debugger;
AddInOptions options;
IWorkbench workbench;
MessageViewCategory category;
IPadDescriptor outputWindowPad;
static MessageViewCategory categorySingleton;
static RunPythonCommand runningCommand;
bool debug;
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.category = category;
this.outputWindowPad = outputWindowPad;
processRunner.OutputLineReceived += OutputLineReceived;
processRunner.ProcessExited += ProcessExited;
this.debugger = debugger;
this.options = options;
}
/// <summary>
/// Indicates whether the command is still running.
/// </summary>
public static bool IsRunning {
get {
return runningCommand != null;
}
public bool Debug {
get { return debug; }
set { debug = value; }
}
/// <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()
{
// Get the python script filename.
string fileName = workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName;
// Clear the output window.
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;
if (debug) {
debugger.Start(CreateProcessStartInfo());
} else {
debugger.StartWithoutDebugging(CreateProcessStartInfo());
}
}
/// <summary>
/// Handler for the ProcessRunner's output line received event.
/// </summary>
void OutputLineReceived(object source, LineReceivedEventArgs e)
ProcessStartInfo CreateProcessStartInfo()
{
CategoryWriteLine(e.Line);
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = options.PythonFileName;
info.Arguments = GetArguments();
return info;
}
/// <summary>
/// Handler for the process exit event.
/// </summary>
void ProcessExited(object source, EventArgs e)
string GetArguments()
{
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 @@ -28,6 +28,7 @@ namespace PythonBinding.Tests
Codon fileFilterCodon;
Codon pythonMenuCodon;
Codon pythonRunMenuItemCodon;
Codon pythonWithoutDebuggerRunMenuItemCodon;
Codon pythonStopMenuItemCodon;
Codon fileTemplatesCodon;
Codon optionsPanelCodon;
@ -63,6 +64,7 @@ namespace PythonBinding.Tests @@ -63,6 +64,7 @@ namespace PythonBinding.Tests
const string runMenuExtensionPath = "/SharpDevelop/Workbench/MainMenu/Python";
pythonRunMenuItemCodon = GetCodon(runMenuExtensionPath, "Run");
pythonWithoutDebuggerRunMenuItemCodon = GetCodon(runMenuExtensionPath, "RunWithoutDebugger");
pythonStopMenuItemCodon = GetCodon(runMenuExtensionPath, "Stop");
fileTemplatesCodon = GetCodon("/SharpDevelop/BackendBindings/Templates", "Python");
@ -232,7 +234,7 @@ namespace PythonBinding.Tests @@ -232,7 +234,7 @@ namespace PythonBinding.Tests
[Test]
public void PythonStopMenuItemLabel()
{
Assert.AreEqual("&Stop", pythonStopMenuItemCodon["label"]);
Assert.AreEqual("${res:XML.MainMenu.DebugMenu.Stop}", pythonStopMenuItemCodon["label"]);
}
[Test]
@ -244,19 +246,19 @@ namespace PythonBinding.Tests @@ -244,19 +246,19 @@ namespace PythonBinding.Tests
[Test]
public void PythonStopMenuItemClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.StopPythonCommand", pythonStopMenuItemCodon["class"]);
Assert.AreEqual("ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand", pythonStopMenuItemCodon["class"]);
}
[Test]
public void PythonStopMenuItemIcon()
{
Assert.AreEqual("Icons.16x16.Debug.StopProcess", pythonStopMenuItemCodon["icon"]);
Assert.AreEqual("Icons.16x16.StopProcess", pythonStopMenuItemCodon["icon"]);
}
[Test]
public void PythonRunMenuItemLabel()
{
Assert.AreEqual("&Run", pythonRunMenuItemCodon["label"]);
Assert.AreEqual("${res:XML.MainMenu.RunMenu.Run}", pythonRunMenuItemCodon["label"]);
}
[Test]
@ -268,7 +270,7 @@ namespace PythonBinding.Tests @@ -268,7 +270,7 @@ namespace PythonBinding.Tests
[Test]
public void PythonRunMenuItemClass()
{
Assert.AreEqual("ICSharpCode.PythonBinding.RunPythonCommand", pythonRunMenuItemCodon["class"]);
Assert.AreEqual("ICSharpCode.PythonBinding.RunDebugPythonCommand", pythonRunMenuItemCodon["class"]);
}
[Test]
@ -290,26 +292,26 @@ namespace PythonBinding.Tests @@ -290,26 +292,26 @@ namespace PythonBinding.Tests
}
[Test]
public void PythonRunMenuNotConditionExists()
public void PythonRunMenuConditionName()
{
NegatedCondition notCondition = pythonRunMenuItemCodon.Conditions[0] as NegatedCondition;
Assert.IsNotNull(notCondition);
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.IsNotNull("IsProcessRunning", condition.Name);
}
[Test]
public void PythonRunMenuNotCondition()
public void PythonRunMenuConditionIsDebuggingProperty()
{
NegatedCondition notCondition = pythonRunMenuItemCodon.Conditions[0] as NegatedCondition;
// 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);
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("False", condition["isdebugging"]);
}
[Test]
public void PythonRunMenuConditionIsProcessRunningProperty()
{
Condition condition = pythonRunMenuItemCodon.Conditions[0] as Condition;
Assert.AreEqual("False", condition["isprocessrunning"]);
}
[Test]
public void PythonRunMenuConditionAction()
{
@ -318,17 +320,30 @@ namespace PythonBinding.Tests @@ -318,17 +320,30 @@ namespace PythonBinding.Tests
}
[Test]
public void PythonStopMenuConditionAction()
public void PythonStopMenuHasSingleCondition()
{
ICondition condition = pythonStopMenuItemCodon.Conditions[0];
Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
Assert.AreEqual(1, pythonStopMenuItemCodon.Conditions.Length);
}
[Test]
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];
Assert.AreEqual("IsPythonRunning", condition.Name);
Assert.AreEqual(ConditionFailedAction.Disable, condition.Action);
}
[Test]
@ -704,6 +719,48 @@ namespace PythonBinding.Tests @@ -704,6 +719,48 @@ namespace PythonBinding.Tests
Condition condition = convertVBNetProjectCodon.Conditions[0] as Condition;
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)
{

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

@ -0,0 +1,63 @@ @@ -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 @@ @@ -152,6 +152,7 @@
<Compile Include="Converter\VBClassConversionTestFixture.cs" />
<Compile Include="Converter\VBStringConcatTestFixture.cs" />
<Compile Include="Converter\WhileLoopConversionTestFixture.cs" />
<Compile Include="DebugPythonCommandTestFixture.cs" />
<Compile Include="Designer\CreateDesignerComponentTests.cs" />
<Compile Include="Designer\CursorTypeResolutionTestFixture.cs" />
<Compile Include="Designer\DeserializeAssignmentTestFixtureBase.cs" />
@ -277,7 +278,6 @@ @@ -277,7 +278,6 @@
<Compile Include="Resolver\ResolveSystemNamespaceTestFixture.cs" />
<Compile Include="Resolver\ResolveUnknownNamespaceTestFixture.cs" />
<Compile Include="RunPythonCommandTestFixture.cs" />
<Compile Include="StopPythonCommandTestFixture.cs" />
<Compile Include="Utils\AddedComponent.cs" />
<Compile Include="Utils\AddInHelper.cs" />
<Compile Include="Utils\BrowseButtonInfo.cs" />
@ -297,6 +297,7 @@ @@ -297,6 +297,7 @@
<Compile Include="Utils\DerivedToolStripMenuItem.cs" />
<Compile Include="Utils\MockClass.cs" />
<Compile Include="Utils\MockComponentCreator.cs" />
<Compile Include="Utils\MockDebugger.cs" />
<Compile Include="Utils\MockDesignerGenerator.cs" />
<Compile Include="Utils\MockDesignerLoaderHost.cs" />
<Compile Include="Utils\MockEditableViewContent.cs" />
@ -349,6 +350,10 @@ @@ -349,6 +350,10 @@
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
</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">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name>

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

@ -22,11 +22,8 @@ namespace PythonBinding.Tests @@ -22,11 +22,8 @@ namespace PythonBinding.Tests
[TestFixture]
public class RunPythonCommandTestFixture
{
MockProcessRunner processRunner;
MessageViewCategory messageViewCategory;
bool messageViewCategoryCleared;
MockPadDescriptor padDescriptor;
bool isRunning;
MockDebugger debugger;
RunPythonCommand command;
[TestFixtureSetUp]
public void SetUpFixture()
@ -38,90 +35,39 @@ namespace PythonBinding.Tests @@ -38,90 +35,39 @@ namespace PythonBinding.Tests
workbenchWindow.ActiveViewContent = viewContent;
MockWorkbench workbench = new MockWorkbench();
workbench.ActiveWorkbenchWindow = workbenchWindow;
// Create a dummy output window pad descriptor.
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();
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);
debugger = new MockDebugger();
command = new RunPythonCommand(workbench, options, debugger);
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]
public void CommandLine()
public void RunPythonCommandIsAbstractCommand()
{
// Check the correct filename was used to execute the command.
Assert.AreEqual("C:\\IronPython\\ipy.exe \"C:\\Projects\\test.py\"", processRunner.CommandLine);
Assert.IsNotNull(command as AbstractCommand);
}
[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]
public void MessageViewCategoryText()
public void ProcessInfoFileName()
{
string expectedText = "Running Python...\r\n" +
"C:\\IronPython\\ipy.exe \"C:\\Projects\\test.py\"\r\n" +
"Test\r\n" +
"Output\r\n";
Assert.AreEqual(expectedText, messageViewCategory.Text);
Assert.AreEqual(@"C:\IronPython\ipy.exe", debugger.ProcessStartInfo.FileName);
}
[Test]
public void OutputWindowPadBroughtToFront()
{
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)
public void ProcessInfoArgs()
{
if (e.Text == "")
messageViewCategoryCleared = true;
Assert.AreEqual("\"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments);
}
}
}

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

@ -1,73 +0,0 @@ @@ -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 @@ @@ -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