diff --git a/src/AddIns/BackendBindings/Python/PythonBinding.sln b/src/AddIns/BackendBindings/Python/PythonBinding.sln index c0bb7b11c1..132066a9ec 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding.sln +++ b/src/AddIns/BackendBindings/Python/PythonBinding.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -# SharpDevelop 4.0.0.5293 +# SharpDevelop 4.0.0.5840 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding", "PythonBinding\Project\PythonBinding.csproj", "{8D732610-8FC6-43BA-94C9-7126FD7FE361}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonBinding.Tests", "PythonBinding\Test\PythonBinding.Tests.csproj", "{23B517C9-1ECC-4419-A13F-0B7136D085CB}" @@ -30,6 +30,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Wi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvalonEdit.AddIn", "..\..\DisplayBindings\AvalonEdit.AddIn\AvalonEdit.AddIn.csproj", "{0162E499-42D0-409B-AA25-EED21F75336B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "..\..\Analysis\UnitTesting\UnitTesting.csproj", "{1F261725-6318-4434-A1B1-6C70CE4CD324}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting.Tests", "..\..\Analysis\UnitTesting\Test\UnitTesting.Tests.csproj", "{44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -94,5 +98,13 @@ Global {0162E499-42D0-409B-AA25-EED21F75336B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0162E499-42D0-409B-AA25-EED21F75336B}.Release|Any CPU.Build.0 = Release|Any CPU {0162E499-42D0-409B-AA25-EED21F75336B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F261725-6318-4434-A1B1-6C70CE4CD324}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F261725-6318-4434-A1B1-6C70CE4CD324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F261725-6318-4434-A1B1-6C70CE4CD324}.Release|Any CPU.Build.0 = Release|Any CPU + {1F261725-6318-4434-A1B1-6C70CE4CD324}.Release|Any CPU.ActiveCfg = Release|Any CPU + {44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Debug|Any CPU.Build.0 = Debug|Any CPU + {44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Release|Any CPU.Build.0 = Release|Any CPU + {44A8DE09-CAB9-49D8-9CFC-5EB0A552F181}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin index 7559322692..1cfc29b3b3 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.addin @@ -1,7 +1,7 @@ - @@ -12,15 +12,16 @@ + + extensions=".py" + name="Python" + resource="ICSharpCode.PythonBinding.Resources.Python.xshd"/> @@ -30,19 +31,19 @@ + insertbefore="Resources" + insertafter="Icons" + name="${res:ICSharpCode.PythonBinding.PythonFiles} (*.py)" + extensions="*.py"/> - + + insertbefore="AllFiles" + name="${res:ICSharpCode.PythonBinding.PythonProjectFiles} (*.pyproj)" + class="ICSharpCode.SharpDevelop.Project.LoadProject" + extensions="*.pyproj"/> @@ -54,27 +55,27 @@ + insertafter="Search" + insertbefore="Tools" + label="&Python" + type="Menu"> + icon="Icons.16x16.RunProgramIcon" + class="ICSharpCode.PythonBinding.RunDebugPythonCommand" + label="${res:XML.MainMenu.RunMenu.Run}" + shortcut="Control|Shift|R"/> + icon="Icons.16x16.Debug.StartWithoutDebugging" + class="ICSharpCode.PythonBinding.RunPythonCommand" + label="${res:XML.MainMenu.DebugMenu.RunWithoutDebug}" + shortcut="Control|Shift|W"/> + icon="Icons.16x16.StopProcess" + class="ICSharpCode.SharpDevelop.Project.Commands.StopDebuggingCommand" + label="${res:XML.MainMenu.DebugMenu.Stop}"/> @@ -83,22 +84,22 @@ + supportedextensions=".py" + projectfileextension=".pyproj" + class="ICSharpCode.PythonBinding.PythonParser"/> + guid="{FD48973F-F585-4F70-812B-4D0503B36CE9}" + supportedextensions=".py" + projectfileextension=".pyproj" + class="ICSharpCode.PythonBinding.PythonProjectBinding" /> - + @@ -115,33 +116,33 @@ + label="Python" + class="ICSharpCode.PythonBinding.PythonOptionsPanel"/> + label="${res:Dialog.ProjectOptions.ApplicationSettings}" + class="ICSharpCode.PythonBinding.ApplicationSettingsPanel"/> + label="${res:Dialog.ProjectOptions.BuildEvents}" + class="ICSharpCode.SharpDevelop.Gui.OptionPanels.BuildEvents"/> + label="${res:Dialog.ProjectOptions.BuildOptions}" + class="ICSharpCode.PythonBinding.CompilingOptionsPanel"/> + label="${res:Dialog.ProjectOptions.DebugOptions}" + class="ICSharpCode.SharpDevelop.Gui.OptionPanels.DebugOptions"/> + type="Secondary" + fileNamePattern="\.py$" + languagePattern="^Python$" + class="ICSharpCode.PythonBinding.PythonFormsDesignerDisplayBinding" /> @@ -151,43 +152,49 @@ + insertafter="CSharp" + insertbefore="VBNet" + label="Python" + class="ICSharpCode.PythonBinding.ConvertToPythonMenuCommand"/> - - - + + + - - + + - - - - - - - + + + + + + + + + + + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj index 03ac606f0d..7f35aa139f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/PythonBinding.csproj @@ -74,11 +74,15 @@ + + + + @@ -89,11 +93,18 @@ + + + + + + + @@ -178,9 +189,16 @@ Always + + Always + + + Always + + @@ -208,6 +226,11 @@ ICSharpCode.SharpDevelop.Dom False + + {1F261725-6318-4434-A1B1-6C70CE4CD324} + UnitTesting + False + {7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57} FormsDesigner diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Resources/PythonOptionsPanel.xfrm b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Resources/PythonOptionsPanel.xfrm index f0194f88e2..fe281e6870 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Resources/PythonOptionsPanel.xfrm +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Resources/PythonOptionsPanel.xfrm @@ -11,6 +11,20 @@ + + + + + + + + + + + + + + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/AddInOptions.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/AddInOptions.cs index d4df5988ff..fd597347ab 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/AddInOptions.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/AddInOptions.cs @@ -29,6 +29,7 @@ namespace ICSharpCode.PythonBinding #region Property names public static readonly string PythonFileNameProperty = "PythonFileName"; + public static readonly string PythonLibraryPathProperty = "PythonLibraryPath"; #endregion Properties properties; @@ -47,13 +48,20 @@ namespace ICSharpCode.PythonBinding this.properties = properties; } + public string PythonLibraryPath { + get { return properties.Get(PythonLibraryPathProperty, String.Empty); } + set { properties.Set(PythonLibraryPathProperty, value); } + } + + public bool HasPythonLibraryPath { + get { return !String.IsNullOrEmpty(PythonLibraryPath); } + } + /// /// Gets or sets the python console filename. /// public string PythonFileName { - get { - return properties.Get(PythonFileNameProperty, GetDefaultPythonFileName()); - } + get { return properties.Get(PythonFileNameProperty, GetDefaultPythonFileName()); } set { if (String.IsNullOrEmpty(value)) { properties.Set(PythonFileNameProperty, GetDefaultPythonFileName()); @@ -63,23 +71,19 @@ namespace ICSharpCode.PythonBinding } } - /// - /// Gets the path to the specified addin. - /// - /// The addin name: "${addin:ICSharpCode.PythonBinding}" - protected virtual string GetAddInPath(string addIn) - { - return StringParser.Parse(addIn); - } - /// /// Returns the full path to ipyw.exe which is installed in the /// Python addin folder. /// string GetDefaultPythonFileName() { - string path = GetAddInPath("${addinpath:ICSharpCode.PythonBinding}"); + string path = GetPythonBindingAddInPath(); return Path.Combine(path, DefaultPythonFileName); } + + string GetPythonBindingAddInPath() + { + return StringParser.Parse("${addinpath:ICSharpCode.PythonBinding}"); + } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CreateTextWriterInfo.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CreateTextWriterInfo.cs new file mode 100644 index 0000000000..264fe024d5 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/CreateTextWriterInfo.cs @@ -0,0 +1,65 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; + +namespace ICSharpCode.PythonBinding +{ + public class CreateTextWriterInfo + { + string fileName; + Encoding encoding; + bool append; + + public CreateTextWriterInfo(string fileName, Encoding encoding, bool append) + { + this.fileName = fileName; + this.encoding = encoding; + this.append = append; + } + + public string FileName { + get { return fileName; } + } + + public Encoding Encoding { + get { return encoding; } + } + + public bool Append { + get { return append; } + } + + public override bool Equals(object obj) + { + CreateTextWriterInfo rhs = obj as CreateTextWriterInfo; + if (rhs != null) { + return Equals(rhs); + } + return false; + } + + bool Equals(CreateTextWriterInfo rhs) + { + return (fileName == rhs.fileName) && + (encoding == rhs.encoding) && + (append == rhs.append); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public TextWriter CreateTextWriter() + { + return new StreamWriter(fileName, append, encoding); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonFileService.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonFileService.cs new file mode 100644 index 0000000000..822fa1adc3 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/IPythonFileService.cs @@ -0,0 +1,20 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; + +namespace ICSharpCode.PythonBinding +{ + public interface IPythonFileService + { + string GetTempFileName(); + TextWriter CreateTextWriter(CreateTextWriterInfo createTextWriterInfo); + void DeleteFile(string fileName); + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs index 3c276ddd91..f3dbe7d692 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonAstWalker.cs @@ -23,18 +23,30 @@ namespace ICSharpCode.PythonBinding public class PythonAstWalker : PythonWalker { DefaultCompilationUnit compilationUnit; - DefaultClass currentClass; - DefaultClass globalClass; - string currentNamespace; + IClass currentClass; + IClass globalClass; /// /// All classes in a file take the namespace of the filename. /// public PythonAstWalker(IProjectContent projectContent, string fileName) + { + CreateCompilationUnit(projectContent, fileName); + } + + void CreateCompilationUnit(IProjectContent projectContent, string fileName) { compilationUnit = new DefaultCompilationUnit(projectContent); compilationUnit.FileName = fileName; - currentNamespace = Path.GetFileNameWithoutExtension(fileName); + + CreateUsingScopeForCompilationUnit(fileName); + } + + void CreateUsingScopeForCompilationUnit(string fileName) + { + DefaultUsingScope usingScope = new DefaultUsingScope(); + usingScope.NamespaceName = Path.GetFileNameWithoutExtension(fileName); + compilationUnit.UsingScope = usingScope; } /// @@ -62,7 +74,7 @@ namespace ICSharpCode.PythonBinding c.Region = GetRegion(node); c.BodyRegion = GetBodyRegion(node.Body, node.Header); AddBaseTypes(c, node.Bases); - + // Save the class. compilationUnit.Classes.Add(c); @@ -80,7 +92,7 @@ namespace ICSharpCode.PythonBinding public override bool Walk(FunctionDefinition node) { if (node.Body == null) { - return true; + return false; } bool ignoreFirstMethodParameter = true; @@ -91,7 +103,7 @@ namespace ICSharpCode.PythonBinding c = globalClass; ignoreFirstMethodParameter = false; } - + // Create method. string methodName = node.Name; DomRegion bodyRegion = GetBodyRegion(node.Body, node.Header); @@ -107,7 +119,7 @@ namespace ICSharpCode.PythonBinding method.Parameters.Add(parameter); } c.Methods.Add(method); - return true; + return false; } /// @@ -120,7 +132,7 @@ namespace ICSharpCode.PythonBinding compilationUnit.UsingScope.Usings.Add(import); return false; } - + public override bool Walk(FromImportStatement node) { PythonFromImport import = new PythonFromImport(compilationUnit.ProjectContent, node); @@ -185,7 +197,12 @@ namespace ICSharpCode.PythonBinding /// void AddBaseType(IClass c, string name) { - c.BaseTypes.Add(new SearchClassReturnType(c.ProjectContent, c, 0, 0, name, 0)); + c.BaseTypes.Add(CreateSearchClassReturnType(c, name)); + } + + SearchClassReturnType CreateSearchClassReturnType(IClass c, string name) + { + return new SearchClassReturnType(c.ProjectContent, c, 0, 0, name, 0); } /// @@ -215,7 +232,7 @@ namespace ICSharpCode.PythonBinding /// string GetFullyQualifiedClassName(ClassDefinition classDef) { - return String.Concat(currentNamespace, ".", classDef.Name); + return String.Concat(compilationUnit.UsingScope.NamespaceName, ".", classDef.Name); } /// @@ -224,7 +241,7 @@ namespace ICSharpCode.PythonBinding void CreateGlobalClass() { if (globalClass == null) { - globalClass = new DefaultClass(compilationUnit, currentNamespace); + globalClass = new DefaultClass(compilationUnit, compilationUnit.UsingScope.NamespaceName); compilationUnit.Classes.Add(globalClass); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs index 434394315b..3564feabfb 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsole.cs @@ -50,25 +50,15 @@ namespace ICSharpCode.PythonBinding //textArea.KeyEventHandler -= ProcessKeyPress; //textArea.DoProcessDialogKey -= ProcessDialogKey; } - + public TextWriter Output { - get { - Console.WriteLine("PythonConsole.Output get"); - return null; - } - set { - Console.WriteLine("PythonConsole.Output set"); - } + get { return null; } + set { } } public TextWriter ErrorOutput { - get { - Console.WriteLine("PythonConsole.ErrorOutput get"); - return null; - } - set { - Console.WriteLine("PythonConsole.ErrorOutput get"); - } + get { return null; } + set { } } /// @@ -90,8 +80,6 @@ namespace ICSharpCode.PythonBinding /// public string ReadLine(int autoIndentSize) { - Console.WriteLine("PythonConsole.ReadLine(): autoIndentSize: " + autoIndentSize); - string indent = String.Empty; if (autoIndentSize > 0) { indent = String.Empty.PadLeft(autoIndentSize); @@ -100,7 +88,6 @@ namespace ICSharpCode.PythonBinding string line = ReadLineFromTextEditor(); if (line != null) { - Console.WriteLine("ReadLine: " + indent + line); return indent + line; } return null; @@ -111,10 +98,7 @@ namespace ICSharpCode.PythonBinding /// public void Write(string text, Style style) { - Console.WriteLine("PythonConsole.Write(text, style): " + text); - textEditor.Write(text); - if (style == Style.Prompt) { promptLength = text.Length; textEditor.MakeCurrentContentReadOnly(); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs new file mode 100644 index 0000000000..eff8b57007 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonConsoleApplication.cs @@ -0,0 +1,109 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using System.Text; + +namespace ICSharpCode.PythonBinding +{ + public class PythonConsoleApplication + { + string fileName = String.Empty; + StringBuilder arguments; + bool debug; + string pythonScriptFileName = String.Empty; + string pythonScriptCommandLineArguments = String.Empty; + string workingDirectory = String.Empty; + + public PythonConsoleApplication(AddInOptions options) + : this(options.PythonFileName) + { + } + + public PythonConsoleApplication(string fileName) + { + this.fileName = fileName; + } + + public string FileName { + get { return fileName; } + } + + public bool Debug { + get { return debug; } + set { debug = value; } + } + + public string PythonScriptFileName { + get { return pythonScriptFileName; } + set { pythonScriptFileName = value; } + } + + public string PythonScriptCommandLineArguments { + get { return pythonScriptCommandLineArguments; } + set { pythonScriptCommandLineArguments = value; } + } + + public string WorkingDirectory { + get { return workingDirectory; } + set { workingDirectory = value; } + } + + public ProcessStartInfo GetProcessStartInfo() + { + ProcessStartInfo processStartInfo = new ProcessStartInfo(); + processStartInfo.FileName = fileName; + processStartInfo.Arguments = GetArguments(); + processStartInfo.WorkingDirectory = workingDirectory; + return processStartInfo; + } + + public string GetArguments() + { + arguments = new StringBuilder(); + + AppendBooleanOptionIfTrue("-X:Debug", debug); + AppendQuotedStringIfNotEmpty(pythonScriptFileName); + AppendStringIfNotEmpty(pythonScriptCommandLineArguments); + + return arguments.ToString().TrimEnd(); + } + + void AppendBooleanOptionIfTrue(string option, bool flag) + { + if (flag) { + AppendOption(option); + } + } + + void AppendOption(string option) + { + arguments.Append(option + " "); + } + + void AppendQuotedStringIfNotEmpty(string option) + { + if (!String.IsNullOrEmpty(option)) { + AppendQuotedString(option); + } + } + + void AppendQuotedString(string option) + { + string quotedOption = String.Format("\"{0}\"", option); + AppendOption(quotedOption); + } + + void AppendStringIfNotEmpty(string option) + { + if (!String.IsNullOrEmpty(option)) { + AppendOption(option); + } + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFileService.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFileService.cs new file mode 100644 index 0000000000..afca45eb89 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFileService.cs @@ -0,0 +1,31 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; + +namespace ICSharpCode.PythonBinding +{ + public class PythonFileService : IPythonFileService + { + public string GetTempFileName() + { + return Path.GetTempFileName(); + } + + public TextWriter CreateTextWriter(CreateTextWriterInfo createTextWriterInfo) + { + return createTextWriterInfo.CreateTextWriter(); + } + + public void DeleteFile(string fileName) + { + File.Delete(fileName); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.cs index 21f899a422..01c979f66d 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonOptionsPanel.cs @@ -5,11 +5,11 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Gui.OptionPanels; using System; using System.Drawing; using System.Windows.Forms; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Gui.OptionPanels; using ICSharpCode.SharpDevelop.Project; namespace ICSharpCode.PythonBinding @@ -21,6 +21,7 @@ namespace ICSharpCode.PythonBinding { AddInOptions options; TextBox pythonFileNameTextBox; + TextBox pythonLibraryPathTextBox; public PythonOptionsPanel() : this(new AddInOptions()) { @@ -38,12 +39,16 @@ namespace ICSharpCode.PythonBinding pythonFileNameTextBox = (TextBox)ControlDictionary["pythonFileNameTextBox"]; pythonFileNameTextBox.Text = options.PythonFileName; + pythonLibraryPathTextBox = (TextBox)ControlDictionary["pythonLibraryPathTextBox"]; + pythonLibraryPathTextBox.Text = options.PythonLibraryPath; + ConnectBrowseButton("browseButton", "pythonFileNameTextBox", "${res:SharpDevelop.FileFilter.ExecutableFiles}|*.exe", TextBoxEditMode.EditRawProperty); } public override bool StorePanelContents() { options.PythonFileName = pythonFileNameTextBox.Text; + options.PythonLibraryPath = pythonLibraryPathTextBox.Text; return true; } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonStandardLibraryPath.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonStandardLibraryPath.cs new file mode 100644 index 0000000000..36da59f78a --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonStandardLibraryPath.cs @@ -0,0 +1,77 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.IO; +using System.Security; +using Microsoft.Win32; + +namespace ICSharpCode.PythonBinding +{ + public class PythonStandardLibraryPath + { + List directories = new List(); + string path = String.Empty; + + public PythonStandardLibraryPath(string path) + { + Path = path; + } + + public PythonStandardLibraryPath() + { + ReadPathFromRegistry(); + } + + void ReadPathFromRegistry() + { + try { + using (RegistryKey registryKey = GetPythonLibraryRegistryKey()) { + if (registryKey != null) { + Path = (string)registryKey.GetValue(String.Empty, String.Empty); + } + } + } catch (SecurityException) { + } catch (UnauthorizedAccessException) { + } catch (IOException) { + } + } + + RegistryKey GetPythonLibraryRegistryKey() + { + return Registry.LocalMachine.OpenSubKey(@"Software\Python\PythonCore\2.6\PythonPath"); + } + + public string[] Directories { + get { return directories.ToArray(); } + } + + public string Path { + get { return path; } + set { + path = value; + ReadDirectories(); + } + } + + void ReadDirectories() + { + directories.Clear(); + foreach (string item in path.Split(';')) { + string directory = item.Trim(); + if (!String.IsNullOrEmpty(directory)) { + directories.Add(directory); + } + } + } + + public bool HasPath { + get { return directories.Count > 0; } + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestDebugger.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestDebugger.cs new file mode 100644 index 0000000000..3e9e6b31f8 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestDebugger.cs @@ -0,0 +1,73 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.PythonBinding +{ + public class PythonTestDebugger : TestDebuggerBase + { + AddInOptions options; + IPythonFileService fileService; + PythonTestRunnerApplication testRunnerApplication; + PythonStandardLibraryPath pythonStandardLibraryPath; + + public PythonTestDebugger() + : this(new UnitTestDebuggerService(), + new UnitTestMessageService(), + new TestResultsMonitor(), + new AddInOptions(), + new PythonStandardLibraryPath(), + new PythonFileService()) + { + } + + public PythonTestDebugger(IUnitTestDebuggerService debuggerService, + IUnitTestMessageService messageService, + ITestResultsMonitor testResultsMonitor, + AddInOptions options, + PythonStandardLibraryPath pythonStandardLibraryPath, + IPythonFileService fileService) + : base(debuggerService, messageService, testResultsMonitor) + { + this.options = options; + this.pythonStandardLibraryPath = pythonStandardLibraryPath; + this.fileService = fileService; + } + + public override void Start(SelectedTests selectedTests) + { + CreateTestRunnerApplication(); + testRunnerApplication.CreateResponseFile(selectedTests); + base.Start(selectedTests); + } + + void CreateTestRunnerApplication() + { + testRunnerApplication = new PythonTestRunnerApplication(base.TestResultsMonitor.FileName, options, pythonStandardLibraryPath, fileService); + } + + protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) + { + testRunnerApplication.Debug = true; + return testRunnerApplication.CreateProcessStartInfo(selectedTests); + } + + public override void Dispose() + { + testRunnerApplication.Dispose(); + base.Dispose(); + } + + protected override TestResult CreateTestResultForTestFramework(TestResult testResult) + { + return new PythonTestResult(testResult); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs new file mode 100644 index 0000000000..9670f44d76 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestFramework.cs @@ -0,0 +1,63 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.PythonBinding +{ + public class PythonTestFramework : ITestFramework + { + public bool IsTestMethod(IMember member) + { + if (member != null) { + return member.Name.StartsWith("test"); + } + return false; + } + + public bool IsTestClass(IClass c) + { + while (c != null) { + if (HasTestCaseBaseType(c)) { + return true; + } + c = c.BaseClass; + } + return false; + } + + bool HasTestCaseBaseType(IClass c) + { + if (c.BaseTypes.Count > 0) { + return c.BaseTypes[0].FullyQualifiedName == "unittest.TestCase"; + } + return false; + } + + public bool IsTestProject(IProject project) + { + return project is PythonProject; + } + + public ITestRunner CreateTestRunner() + { + return new PythonTestRunner(); + } + + public ITestRunner CreateTestDebugger() + { + return new PythonTestDebugger(); + } + + public bool IsBuildNeededBeforeTestRun { + get { return false; } + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestResult.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestResult.cs new file mode 100644 index 0000000000..62fc443a6b --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestResult.cs @@ -0,0 +1,66 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Dom; +using System.Text.RegularExpressions; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.PythonBinding +{ + public class PythonTestResult : TestResult + { + public PythonTestResult(TestResult testResult) + : base(testResult.Name) + { + ResultType = testResult.ResultType; + Message = testResult.Message; + StackTrace = testResult.StackTrace; + } + + protected override void OnStackTraceChanged() + { + if (String.IsNullOrEmpty(StackTrace)) { + ResetStackTraceFilePosition(); + } else { + GetFilePositionFromStackTrace(); + } + } + + void ResetStackTraceFilePosition() + { + StackTraceFilePosition = FilePosition.Empty; + } + + /// + /// Stack trace: + /// Traceback (most recent call last): + /// File "d:\temp\test\PyTests\Tests\MyClassTest.py", line 19, in testRaiseException + /// raise 'abc' + /// + void GetFilePositionFromStackTrace() + { + Match match = Regex.Match(StackTrace, "\\sFile\\s\"(.*?)\",\\sline\\s(\\d+),", RegexOptions.Multiline); + if (match.Success) { + try { + SetStackTraceFilePosition(match.Groups); + } catch (OverflowException) { + // Ignore. + } + } + } + + void SetStackTraceFilePosition(GroupCollection groups) + { + string fileName = groups[1].Value; + int line = Convert.ToInt32(groups[2].Value); + int column = 1; + + StackTraceFilePosition = new FilePosition(fileName, line, column); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunner.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunner.cs new file mode 100644 index 0000000000..461a203135 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunner.cs @@ -0,0 +1,73 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using ICSharpCode.Core; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.PythonBinding +{ + public class PythonTestRunner : TestProcessRunnerBase + { + AddInOptions options; + PythonStandardLibraryPath pythonStandardLibraryPath; + IPythonFileService fileService; + PythonTestRunnerApplication testRunnerApplication; + + public PythonTestRunner() + : this(new UnitTestProcessRunner(), + new TestResultsMonitor(), + new AddInOptions(), + new PythonStandardLibraryPath(), + new PythonFileService()) + { + } + + public PythonTestRunner(IUnitTestProcessRunner processRunner, + ITestResultsMonitor testResultsMonitor, + AddInOptions options, + PythonStandardLibraryPath pythonStandardLibraryPath, + IPythonFileService fileService) + : base(processRunner, testResultsMonitor) + { + this.options = options; + this.pythonStandardLibraryPath = pythonStandardLibraryPath; + this.fileService = fileService; + } + + public override void Start(SelectedTests selectedTests) + { + CreateTestRunnerApplication(); + testRunnerApplication.CreateResponseFile(selectedTests); + base.Start(selectedTests); + } + + void CreateTestRunnerApplication() + { + testRunnerApplication = new PythonTestRunnerApplication(base.TestResultsMonitor.FileName, options, pythonStandardLibraryPath, fileService); + } + + protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) + { + return testRunnerApplication.CreateProcessStartInfo(selectedTests); + } + + public override void Dispose() + { + testRunnerApplication.Dispose(); + base.Dispose(); + } + + protected override TestResult CreateTestResultForTestFramework(TestResult testResult) + { + return new PythonTestResult(testResult); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs new file mode 100644 index 0000000000..5414ecf030 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerApplication.cs @@ -0,0 +1,109 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using ICSharpCode.Core; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.PythonBinding +{ + public class PythonTestRunnerApplication + { + string testResultsFileName = String.Empty; + AddInOptions options; + PythonStandardLibraryPath pythonStandardLibraryPath; + PythonTestRunnerResponseFile responseFile; + IPythonFileService fileService; + CreateTextWriterInfo textWriterInfo; + PythonConsoleApplication consoleApplication; + + public PythonTestRunnerApplication(string testResultsFileName, + AddInOptions options, + PythonStandardLibraryPath pythonStandardLibraryPath, + IPythonFileService fileService) + { + this.testResultsFileName = testResultsFileName; + this.options = options; + this.pythonStandardLibraryPath = pythonStandardLibraryPath; + this.fileService = fileService; + consoleApplication = new PythonConsoleApplication(options); + } + + public bool Debug { + get { return consoleApplication.Debug; } + set { consoleApplication.Debug = value; } + } + + public void CreateResponseFile(SelectedTests selectedTests) + { + CreateResponseFile(); + using (responseFile) { + WritePythonSystemPaths(); + WriteTestsResultsFileName(); + WriteTests(selectedTests); + } + } + + void CreateResponseFile() + { + TextWriter writer = CreateTextWriter(); + responseFile = new PythonTestRunnerResponseFile(writer); + } + + TextWriter CreateTextWriter() + { + string fileName = fileService.GetTempFileName(); + textWriterInfo = new CreateTextWriterInfo(fileName, Encoding.UTF8, false); + return fileService.CreateTextWriter(textWriterInfo); + } + + void WritePythonSystemPaths() + { + if (options.HasPythonLibraryPath) { + responseFile.WritePath(options.PythonLibraryPath); + } else if (pythonStandardLibraryPath.HasPath) { + responseFile.WritePaths(pythonStandardLibraryPath.Directories); + } + } + + void WriteTestsResultsFileName() + { + responseFile.WriteResultsFileName(testResultsFileName); + } + + void WriteTests(SelectedTests selectedTests) + { + responseFile.WriteTests(selectedTests); + } + + public ProcessStartInfo CreateProcessStartInfo(SelectedTests selectedTests) + { + consoleApplication.PythonScriptFileName = GetSharpDevelopTestPythonScriptFileName(); + consoleApplication.PythonScriptCommandLineArguments = GetResponseFileNameCommandLineArgument(); + consoleApplication.WorkingDirectory = selectedTests.Project.Directory; + return consoleApplication.GetProcessStartInfo(); + } + + string GetSharpDevelopTestPythonScriptFileName() + { + return StringParser.Parse(@"${addinpath:ICSharpCode.PythonBinding}\TestRunner\sdtest.py"); + } + + string GetResponseFileNameCommandLineArgument() + { + return String.Format("\"@{0}\"", textWriterInfo.FileName); + } + + public void Dispose() + { + fileService.DeleteFile(textWriterInfo.FileName); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerResponseFile.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerResponseFile.cs new file mode 100644 index 0000000000..9e526a0d00 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonTestRunnerResponseFile.cs @@ -0,0 +1,122 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.ObjectModel; +using System.IO; +using System.Text; +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.UnitTesting; + +namespace ICSharpCode.PythonBinding +{ + public class PythonTestRunnerResponseFile : IDisposable + { + TextWriter writer; + + public PythonTestRunnerResponseFile(string fileName) + : this(new StreamWriter(fileName, false, Encoding.UTF8)) + { + } + + public PythonTestRunnerResponseFile(TextWriter writer) + { + this.writer = writer; + } + + public void WriteTest(string testName) + { + writer.WriteLine(testName); + } + + public void WritePaths(string[] paths) + { + foreach (string path in paths) { + WritePath(path); + } + } + + public void WritePathIfNotEmpty(string path) + { + if (!String.IsNullOrEmpty(path)) { + WritePath(path); + } + } + + public void WritePath(string path) + { + WriteQuotedArgument("p", path); + } + + void WriteQuotedArgument(string option, string value) + { + writer.WriteLine("/{0}:\"{1}\"", option, value); + } + + public void WriteResultsFileName(string fileName) + { + WriteQuotedArgument("r", fileName); + } + + public void Dispose() + { + writer.Dispose(); + } + + public void WriteTests(SelectedTests selectedTests) + { + WritePathsForReferencedProjects(selectedTests.Project); + + if (selectedTests.Method != null) { + WriteTest(selectedTests.Method.FullyQualifiedName); + } else if (selectedTests.Class != null) { + WriteTest(selectedTests.Class.FullyQualifiedName); + } else if (!String.IsNullOrEmpty(selectedTests.NamespaceFilter)) { + WriteTest(selectedTests.NamespaceFilter); + } else { + WriteProjectTests(selectedTests.Project); + } + + } + + void WriteProjectTests(IProject project) + { + if (project != null) { + WriteProjectFileItems(project.Items); + } + } + + void WritePathsForReferencedProjects(IProject project) + { + if (project != null) { + foreach (ProjectItem item in project.Items) { + ProjectReferenceProjectItem projectRef = item as ProjectReferenceProjectItem; + if (projectRef != null) { + string directory = Path.GetDirectoryName(projectRef.FileName); + WritePathIfNotEmpty(directory); + } + } + } + } + + void WriteProjectFileItems(ReadOnlyCollection items) + { + foreach (ProjectItem item in items) { + FileProjectItem fileItem = item as FileProjectItem; + if (fileItem != null) { + WriteFileNameWithoutExtension(fileItem.FileName); + } + } + } + + void WriteFileNameWithoutExtension(string fileName) + { + string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); + WriteTest(fileNameWithoutExtension); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs index b962b15407..2f53fced95 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/RunPythonCommand.cs @@ -23,7 +23,7 @@ namespace ICSharpCode.PythonBinding IDebugger debugger; AddInOptions options; IWorkbench workbench; - bool debug; + PythonConsoleApplication ipy; public RunPythonCommand() : this(WorkbenchSingleton.Workbench, new AddInOptions(), DebuggerService.CurrentDebugger) @@ -35,40 +35,28 @@ namespace ICSharpCode.PythonBinding this.workbench = workbench; this.debugger = debugger; this.options = options; + ipy = new PythonConsoleApplication(options); } public bool Debug { - get { return debug; } - set { debug = value; } + get { return ipy.Debug; } + set { ipy.Debug = value; } } public override void Run() { - if (debug) { - debugger.Start(CreateProcessStartInfo()); + ProcessStartInfo processStartInfo = GetProcessStartInfo(); + if (Debug) { + debugger.Start(processStartInfo); } else { - debugger.StartWithoutDebugging(CreateProcessStartInfo()); + debugger.StartWithoutDebugging(processStartInfo); } } - ProcessStartInfo CreateProcessStartInfo() - { - ProcessStartInfo info = new ProcessStartInfo(); - info.FileName = options.PythonFileName; - info.Arguments = GetArguments(); - - return info; - } - - string GetArguments() + ProcessStartInfo GetProcessStartInfo() { - // Get the python script filename. - string pythonScriptFileName = "\"" + workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName + "\""; - - if (Debug) { - return "-D " + pythonScriptFileName; - } - return pythonScriptFileName; + ipy.PythonScriptFileName = workbench.ActiveWorkbenchWindow.ActiveViewContent.PrimaryFileName; + return ipy.GetProcessStartInfo(); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/TestRunner/sdtest.py b/src/AddIns/BackendBindings/Python/PythonBinding/Project/TestRunner/sdtest.py new file mode 100644 index 0000000000..3510f6fcfa --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/TestRunner/sdtest.py @@ -0,0 +1,95 @@ + +import sys +import System.IO + +class SharpDevelopTestProgram: + + def __init__(self): + self._sysPaths = [] + self._testNames = [] + + def run(self): + if self._validateCommandLineArgs(): + self._runTests() + return + + print 'Usage: sdunittest.py test-names-file sys-paths-file test-results-file' + print 'Usage: sdunittest.py @response-file' + print '' + print 'Example response file content: ' + print '/p:"sys/path/1"' + print '/p:"sys/path/2"' + print '/r:"path/to/results-file"' + print 'test-name1' + print 'test-name2' + print 'test-name3' + + def _validateCommandLineArgs(self): + if len(sys.argv) == 4: + self._testNamesFile = sys.argv[1] + self._sysPathFile = sys.argv[2] + self._testResultsFile = sys.argv[3] + self._responseFile = '' + return True + if len(sys.argv) == 2: + return self._getResponseFileName(sys.argv[1]) + return False + + def _getResponseFileName(self, fileName): + if len(fileName) > 0: + if fileName[0] == '@': + self._responseFile = fileName[1:] + return True + return False + + def _runTests(self): + if len(self._responseFile) > 0: + self._readResponseFile() + else: + self._readSysPathsFromFile() + self._readTestNames() + + self._addSysPaths() + + import unittest + import sdtestrunner + + suite = unittest.TestLoader().loadTestsFromNames(self._testNames) + sdtestrunner.SharpDevelopTestRunner(resultsFileName=self._testResultsFile, verbosity=2).run(suite) + + def _readResponseFile(self): + for line in self._readLinesFromFile(self._responseFile): + self._readResponseFileArgument(line) + + def _readResponseFileArgument(self, line): + if line.startswith('/r:'): + line = self._removeQuotes(line[3:]) + self._testResultsFile = line + elif line.startswith('/p:'): + line = self._removeQuotes(line[3:]) + self._sysPaths.append(line) + else: + self._testNames.append(line) + + def _removeQuotes(self, line): + return line.strip('\"') + + def _readLinesFromFile(self, fileName): + #f = codecs.open(fileName, 'rb', 'utf-8') + #return f.readall().splitlines() + return System.IO.File.ReadAllLines(fileName) + + def _readTestNames(self): + self._testNames = self._readLinesFromFile(self._testNamesFile) + + def _readSysPathsFromFile(self): + self._sysPaths = self._readLinesFromFile(self._sysPathFile) + + def _addSysPaths(self): + for path in self._sysPaths: + sys.path.append(path) + + +if __name__ == '__main__': + program = SharpDevelopTestProgram() + program.run() diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/TestRunner/sdtestrunner.py b/src/AddIns/BackendBindings/Python/PythonBinding/Project/TestRunner/sdtestrunner.py new file mode 100644 index 0000000000..9fa36d46c3 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/TestRunner/sdtestrunner.py @@ -0,0 +1,106 @@ + +import codecs +import sys +import time +from unittest import TestResult +from unittest import TextTestRunner +from unittest import _TextTestResult +from unittest import _WritelnDecorator + +class _SharpDevelopTestResultWriter: + def __init__(self, resultsFileName): + self.stream = codecs.open(resultsFileName, "w+", "utf-8-sig") + + def _writeln(self, arg): + self.stream.write(arg) + self.stream.write('\r\n') + + def _writeTestName(self, test): + self._writeln("Name: " + test.id()) + + def _writeTestResult(self, result): + self._writeln("Result: " + result) + + def _writeTestSuccess(self): + self._writeTestResult("Success") + + def _writeTestFailure(self, test, err, testResult): + self._writeTestResult("Failure") + + exctype, value, tb = err + if value != None: + message = self._prefixLinesWithSpaceChar(str(value)) + self._writeln("Message: " + message) + + excInfoString = testResult._exc_info_to_string(err, test) + excInfoString = self._prefixLinesWithSpaceChar(excInfoString) + self._writeln("StackTrace: " + excInfoString) + + def _prefixLinesWithSpaceChar(self, text): + lines = [] + originalLines = text.splitlines() + if len(originalLines) == 0: + return text + + lines.append(originalLines[0] + '\r\n') + + for line in originalLines[1:]: + lines.append(' ' + line + '\r\n') + return ''.join(lines).rstrip() + + def addSuccess(self, test): + self._writeTestName(test) + self._writeTestSuccess() + + def addError(self, test, err, testResult): + self._writeTestName(test) + self._writeTestFailure(test, err, testResult) + + def addFailure(self, test, err, testResult): + self._writeTestName(test) + self._writeTestFailure(test, err, testResult) + +class _SharpDevelopNullTestResultWriter: + def __init__(self): + pass + + def addSuccess(self, test): + pass + + def addError(self, test, err, testResult): + pass + + def addFailure(self, test, err, testResult): + pass + + +class _SharpDevelopTestResult(_TextTestResult): + def __init__(self, stream, descriptions, verbosity, resultWriter): + _TextTestResult.__init__(self, stream, descriptions, verbosity) + self.resultWriter = resultWriter + + def addSuccess(self, test): + self.resultWriter.addSuccess(test) + _TextTestResult.addSuccess(self, test) + + def addError(self, test, err): + self.resultWriter.addError(test, err, self) + _TextTestResult.addError(self, test, err) + + def addFailure(self, test, err): + self.resultWriter.addFailure(test, err, self) + _TextTestResult.addFailure(self, test, err) + + +class SharpDevelopTestRunner(TextTestRunner): + def __init__(self, stream=sys.stderr, resultsFileName=None, descriptions=1, verbosity=1): + self.stream = _WritelnDecorator(stream) + self.descriptions = descriptions + self.verbosity = verbosity + if resultsFileName is None: + self.resultWriter = _SharpDevelopNullTestResultWriter() + else: + self.resultWriter = _SharpDevelopTestResultWriter(resultsFileName) + + def _makeResult(self): + return _SharpDevelopTestResult(self.stream, self.descriptions, self.verbosity, self.resultWriter) diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInOptionsTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInOptionsTestFixture.cs deleted file mode 100644 index 7306089ba7..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInOptionsTestFixture.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.IO; -using ICSharpCode.Core; -using ICSharpCode.PythonBinding; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests -{ - /// - /// Tests the AddInOptions class. - /// - [TestFixture] - public class AddInOptionsTestFixture - { - [Test] - public void DefaultPythonConsoleFileName() - { - Properties p = new Properties(); - DerivedAddInOptions options = new DerivedAddInOptions(p); - options.AddInPath = @"C:\Projects\SD\AddIns\Python"; - - string expectedFileName = Path.Combine(options.AddInPath, "ipy.exe"); - Assert.AreEqual(expectedFileName, options.PythonFileName); - Assert.AreEqual("${addinpath:ICSharpCode.PythonBinding}", options.AddInPathRequested); - } - - [Test] - public void SetPythonConsoleFileNameToNull() - { - Properties p = new Properties(); - DerivedAddInOptions options = new DerivedAddInOptions(p); - options.AddInPath = @"C:\Projects\SD\AddIns\Python"; - options.PythonFileName = null; - - string expectedFileName = Path.Combine(options.AddInPath, "ipy.exe"); - Assert.AreEqual(expectedFileName, options.PythonFileName); - } - - [Test] - public void SetPythonConsoleFileNameToEmptyString() - { - Properties p = new Properties(); - DerivedAddInOptions options = new DerivedAddInOptions(p); - options.AddInPath = @"C:\Projects\SD\AddIns\Python"; - options.PythonFileName = String.Empty; - - string expectedFileName = Path.Combine(options.AddInPath, "ipy.exe"); - Assert.AreEqual(expectedFileName, options.PythonFileName); - } - - [Test] - public void SetPythonConsoleFileName() - { - Properties p = new Properties(); - AddInOptions options = new AddInOptions(p); - string fileName = @"C:\IronPython\ipy.exe"; - options.PythonFileName = fileName; - - Assert.AreEqual(fileName, options.PythonFileName); - Assert.AreEqual(fileName, p["PythonFileName"]); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CodeCompletionBindingFromImportCompletionTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/CodeCompletionBindingFromImportCompletionTestFixture.cs deleted file mode 100644 index 8d560b5fb5..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CodeCompletionBindingFromImportCompletionTestFixture.cs +++ /dev/null @@ -1,52 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using ICSharpCode.Core; -using ICSharpCode.PythonBinding; -using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; -using ICSharpCode.SharpDevelop.Dom; -using NUnit.Framework; -using PythonBinding.Tests.Utils; - -namespace PythonBinding.Tests -{ - /// - /// Tests that the From keyword is correctly identified as a - /// importable code completion keyword. - /// - [TestFixture] - public class FromImportCompletionTestFixture - { - DerivedPythonCodeCompletionBinding codeCompletionBinding; - bool handlesImportKeyword; - SharpDevelopTextAreaControl textAreaControl; - - [TestFixtureSetUp] - public void SetUpFixture() - { - if (!PropertyService.Initialized) { - PropertyService.InitializeService(String.Empty, String.Empty, String.Empty); - } - textAreaControl = new SharpDevelopTextAreaControl(); - codeCompletionBinding = new DerivedPythonCodeCompletionBinding(); - handlesImportKeyword = codeCompletionBinding.HandleKeyword(textAreaControl, "from"); - } - - [Test] - public void HandlesImportKeyWord() - { - Assert.IsTrue(handlesImportKeyword); - } - - [Test] - public void ExpressionContextIsImportable() - { - Assert.AreEqual(ExpressionContext.Importable, codeCompletionBinding.ExpressionContext); - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/CodeCompletionBindingImportCompletionTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/CodeCompletionBindingImportCompletionTestFixture.cs index e50567742b..49d26d4e59 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/CodeCompletionBindingImportCompletionTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/CodeCompletionBindingImportCompletionTestFixture.cs @@ -8,12 +8,12 @@ using System; using ICSharpCode.Core; using ICSharpCode.PythonBinding; -using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Editor.AvalonEdit; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Completion { /// /// Tests the code completion after an "import" statement. @@ -48,7 +48,7 @@ namespace PythonBinding.Tests Assert.IsFalse(codeCompletionBinding.HandleKeyword(textEditor, "Unknown")); } - [Test] + [Test] public void HandlesUppercaseImportKeyword() { Assert.IsTrue(codeCompletionBinding.HandleKeyword(textEditor, "IMPORT")); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/NamespaceContentsAddedToCtrlSpaceTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/NamespaceContentsAddedToCtrlSpaceTestFixture.cs index 258b9df69a..fb803ad45f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/NamespaceContentsAddedToCtrlSpaceTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Completion/NamespaceContentsAddedToCtrlSpaceTestFixture.cs @@ -12,6 +12,7 @@ using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { @@ -25,14 +26,14 @@ namespace PythonBinding.Tests.Resolver { List results; PythonResolver resolver; - MockProjectContent mockProjectContent; + PythonBinding.Tests.Utils.MockProjectContent mockProjectContent; MockClass myTestClass; [TestFixtureSetUp] public void SetUpFixture() { resolver = new PythonResolver(); - mockProjectContent = new MockProjectContent(); + mockProjectContent = new PythonBinding.Tests.Utils.MockProjectContent(); mockProjectContent.NamespacesToAdd.Add("Test"); myTestClass = new MockClass(mockProjectContent, "MyTestClass"); List namespaceItems = new List(); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInFileTestFixture.cs similarity index 93% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInFileTestFixture.cs index 6548db301f..34bd86cf24 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/AddInFileTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInFileTestFixture.cs @@ -15,7 +15,7 @@ using ICSharpCode.TextEditor.Document; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Configuration { /// /// Basic PythonBinding.addin file tests. @@ -50,6 +50,10 @@ namespace PythonBinding.Tests Codon convertCSharpProjectCodon; Codon convertVBNetProjectCodon; Codon formattingStrategyCodon; + Runtime sharpdevelopRuntime; + Runtime ironpythonModulesRuntime; + Runtime unitTestingRuntime; + Codon testFrameworkCodon; [TestFixtureSetUp] public void SetupFixture() @@ -83,13 +87,20 @@ namespace PythonBinding.Tests convertCSharpProjectCodon = GetCodon("/SharpDevelop/Pads/ProjectBrowser/ContextMenu/ProjectActions/Convert", "CSharpProjectToPythonProjectConverter"); convertVBNetProjectCodon = GetCodon("/SharpDevelop/Pads/ProjectBrowser/ContextMenu/ProjectActions/Convert", "VBNetProjectToPythonProjectConverter"); formattingStrategyCodon = GetCodon("/AddIns/DefaultTextEditor/Formatter/Python", "PythonFormatter"); - + testFrameworkCodon = GetCodon("/SharpDevelop/UnitTesting/TestFrameworks", "pyunit"); + // Get the PythonBinding runtime. foreach (Runtime runtime in addin.Runtimes) { if (runtime.Assembly == "PythonBinding.dll") { - pythonBindingRuntime = runtime; + pythonBindingRuntime = runtime; } else if (runtime.Assembly == "$ICSharpCode.FormsDesigner/FormsDesigner.dll") { formsDesignerRuntime = runtime; + } else if (runtime.Assembly == "IronPython.Modules.dll") { + ironpythonModulesRuntime = runtime; + } else if (runtime.Assembly == ":ICSharpCode.SharpDevelop") { + sharpdevelopRuntime = runtime; + } else if (runtime.Assembly == "$ICSharpCode.UnitTesting/UnitTesting.dll") { + unitTestingRuntime = runtime; } } @@ -128,11 +139,29 @@ namespace PythonBinding.Tests } [Test] - public void RuntimeExists() + public void PythonBindingRuntimeExists() { Assert.IsNotNull(pythonBindingRuntime); } + [Test] + public void ICSharpCodeSharpDevelopRuntimeExists() + { + Assert.IsNotNull(sharpdevelopRuntime); + } + + [Test] + public void IronPythonModulesRuntimeExists() + { + Assert.IsNotNull(ironpythonModulesRuntime); + } + + [Test] + public void UnitTestingRuntimeExists() + { + Assert.IsNotNull(unitTestingRuntime); + } + [Test] public void FileFilterExists() { @@ -725,22 +754,40 @@ namespace PythonBinding.Tests { Assert.AreEqual(1, pythonWithoutDebuggerRunMenuItemCodon.Conditions.Length); } - + [Test] public void PythonDebugRunConditionIsSameAsPythonRunCondition() { Assert.AreEqual(pythonWithoutDebuggerRunMenuItemCodon.Conditions[0], pythonRunMenuItemCodon.Conditions[0]); } - + [Test] public void PythonFormatterClass() { Assert.AreEqual("ICSharpCode.PythonBinding.PythonFormattingStrategy", formattingStrategyCodon["class"]); } + [Test] + public void TestFrameworkCodonExists() + { + Assert.IsNotNull(testFrameworkCodon); + } + + [Test] + public void TestFrameworkClassIsPythonTestFrameworks() + { + Assert.AreEqual("ICSharpCode.PythonBinding.PythonTestFramework", testFrameworkCodon["class"]); + } + + [Test] + public void TestFrameworkSupportedProjectsIsPythonProject() + { + Assert.AreEqual(".pyproj", testFrameworkCodon["supportedProjects"]); + } + Codon GetCodon(string name, string extensionPath) { return AddInHelper.GetCodon(addin, name, extensionPath); - } + } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInOptionsTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInOptionsTestFixture.cs new file mode 100644 index 0000000000..3ebb9d18e3 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Configuration/AddInOptionsTestFixture.cs @@ -0,0 +1,94 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using ICSharpCode.Core; +using ICSharpCode.PythonBinding; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Configuration +{ + /// + /// Tests the AddInOptions class. + /// + [TestFixture] + public class AddInOptionsTestFixture + { + AddInOptions options; + Properties properties; + AddIn addin; + + [TestFixtureSetUp] + public void SetUpFixture() + { + addin = AddInPathHelper.CreateDummyPythonAddInInsideAddInTree(); + addin.FileName = @"C:\Projects\SD\AddIns\Python\pythonbinding.addin"; + } + + [SetUp] + public void Init() + { + properties = new Properties(); + options = new AddInOptions(properties); + } + + [Test] + public void DefaultPythonConsoleFileNameIsPythonAddInPathCombinedWithIpyExe() + { + string expectedFileName = @"C:\Projects\SD\AddIns\Python\ipy.exe"; + Assert.AreEqual(expectedFileName, options.PythonFileName); + } + + [Test] + public void RequestingPythonFileNameWhenPythonConsoleFileNameSetToNullReturnsDefaultPythonConsoleFileName() + { + options.PythonFileName = null; + string expectedFileName = @"C:\Projects\SD\AddIns\Python\ipy.exe"; + Assert.AreEqual(expectedFileName, options.PythonFileName); + } + + [Test] + public void RequestingPythonFileNameWhenPythonConsoleFileNameToEmptyStringReturnsDefaultPythonConsoleFileName() + { + options.PythonFileName = String.Empty; + string expectedFileName = @"C:\Projects\SD\AddIns\Python\ipy.exe"; + Assert.AreEqual(expectedFileName, options.PythonFileName); + } + + [Test] + public void SetPythonConsoleFileNameUpdatesAddInOptionsPythonFileName() + { + string fileName = @"C:\IronPython\ipy.exe"; + options.PythonFileName = fileName; + Assert.AreEqual(fileName, options.PythonFileName); + } + + [Test] + public void SetPythonConsoleFileNameUpdatesProperties() + { + string fileName = @"C:\IronPython\ipy.exe"; + options.PythonFileName = fileName; + Assert.AreEqual(fileName, properties["PythonFileName"]); + } + + [Test] + public void PythonLibraryPathTakenFromProperties() + { + string expectedPythonLibraryPath = @"c:\python26\lib;c:\python26\lib\lib-tk"; + properties["PythonLibraryPath"] = expectedPythonLibraryPath; + Assert.AreEqual(expectedPythonLibraryPath, options.PythonLibraryPath); + } + + [Test] + public void DefaultPythonLibraryPathIsEmptyString() + { + Assert.AreEqual(String.Empty, options.PythonLibraryPath); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForLoopConversionTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForLoopConversionTestFixture.cs index 32e2f86734..0939669caf 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForLoopConversionTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForLoopConversionTestFixture.cs @@ -51,7 +51,6 @@ namespace PythonBinding.Tests.Converter { NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp); string code = converter.Convert(csharp); - System.Console.WriteLine(code); string expectedCode = "class Foo(object):\r\n" + "\tdef GetCount(self):\r\n" + "\t\tcount = 0\r\n" + @@ -60,7 +59,7 @@ namespace PythonBinding.Tests.Converter "\t\t\tcount += 1\r\n" + "\t\t\ti = i + 1\r\n" + "\t\treturn count"; - + Assert.AreEqual(expectedCode, code); } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs index bf5770363e..66d959d2e8 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ProjectHasStartupObjectTestFixture.cs @@ -17,6 +17,7 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Project; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Converter { @@ -31,7 +32,7 @@ namespace PythonBinding.Tests.Converter MSBuildBasedProject sourceProject; PythonProject targetProject; MockTextEditorProperties mockTextEditorProperties; - MockProjectContent mockProjectContent; + PythonBinding.Tests.Utils.MockProjectContent mockProjectContent; string startupObject = "RootNamespace.Main"; @@ -64,7 +65,7 @@ namespace PythonBinding.Tests.Converter // Set up IProjectContent so the ConvertProjectToPythonProjectCommand can // locate the startup object and determine it's filename. - mockProjectContent = new MockProjectContent(); + mockProjectContent = new PythonBinding.Tests.Utils.MockProjectContent(); MockClass mainClass = new MockClass(mockProjectContent, startupObject); mainClass.CompilationUnit.FileName = @"d:\projects\test\src\Main2.cs"; mockProjectContent.ClassToReturnFromGetClass = mainClass; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratorMergeFindsInitializeComponentsTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratorMergeFindsInitializeComponentsTestFixture.cs index 723eff78d7..8e1e8e9e64 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratorMergeFindsInitializeComponentsTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/GeneratorMergeFindsInitializeComponentsTestFixture.cs @@ -20,6 +20,7 @@ using ICSharpCode.FormsDesigner; using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Designer { @@ -71,7 +72,7 @@ namespace PythonBinding.Tests.Designer [Test] public void GetDomRegion() { - MockMethod method = new MockMethod(); + MockMethod method = new MockMethod(MockClass.CreateMockClassWithoutAnyAttributes()); DomRegion bodyRegion = new DomRegion(0, 4, 1, 4); method.BodyRegion = bodyRegion; DomRegion expectedRegion = new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine + 1, 1); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs index 6e6d37d7f7..bc4b6948c9 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonDesignerLoaderTestFixture.cs @@ -68,9 +68,7 @@ namespace PythonBinding.Tests.Designer serializationManager = new DesignerSerializationManager(mockDesignerLoaderHost); - System.Console.WriteLine("Before BeginLoad"); loader.BeginLoad(mockDesignerLoaderHost); - System.Console.WriteLine("After BeginLoad"); rootComponent = mockDesignerLoaderHost.RootComponent; designedForm = new Form(); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonGeneratorTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonGeneratorTestFixture.cs index 8c82afa474..e414ac077f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonGeneratorTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Designer/PythonGeneratorTestFixture.cs @@ -17,6 +17,7 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Designer { @@ -26,7 +27,7 @@ namespace PythonBinding.Tests.Designer [Test] public void GetMethodReplaceRegion() { - MockMethod method = new MockMethod(); + MockMethod method = new MockMethod(MockClass.CreateMockClassWithoutAnyAttributes()); DomRegion bodyRegion = new DomRegion(0, 4, 1, 4); method.BodyRegion = bodyRegion; DomRegion expectedRegion = new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine + 1, 1); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/AppSettingsPanelTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/AppSettingsPanelTestFixture.cs similarity index 99% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/AppSettingsPanelTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/AppSettingsPanelTestFixture.cs index 2c911e6355..77c59a6125 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/AppSettingsPanelTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/AppSettingsPanelTestFixture.cs @@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Project; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { /// /// Tests the ApplicationSettingsPanel class. diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CompilingOptionsPanelTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/CompilingOptionsPanelTestFixture.cs similarity index 99% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/CompilingOptionsPanelTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/CompilingOptionsPanelTestFixture.cs index 1d10376d14..7e6b51e07f 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CompilingOptionsPanelTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/CompilingOptionsPanelTestFixture.cs @@ -16,7 +16,7 @@ using ICSharpCode.SharpDevelop.Project; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { /// /// Tests the CompilingOptionsPanel. diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/DebugPythonCommandTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/DebugPythonCommandTestFixture.cs similarity index 88% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/DebugPythonCommandTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/DebugPythonCommandTestFixture.cs index ed886eb6cc..eff903c3e9 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/DebugPythonCommandTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/DebugPythonCommandTestFixture.cs @@ -13,7 +13,7 @@ using ICSharpCode.PythonBinding; using PythonBinding.Tests.Utils; using NUnit.Framework; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { [TestFixture] public class DebugPythonCommandTestFixture @@ -26,7 +26,7 @@ namespace PythonBinding.Tests { // Create dummy view content with the Python script. MockViewContent viewContent = new MockViewContent(); - viewContent.PrimaryFileName = new FileName(@"C:\Projects\test.py"); + viewContent.PrimaryFileName = new FileName(@"C:\Projects\test.py"); MockWorkbenchWindow workbenchWindow = new MockWorkbenchWindow(); workbenchWindow.ActiveViewContent = viewContent; MockWorkbench workbench = new MockWorkbench(); @@ -57,7 +57,7 @@ namespace PythonBinding.Tests [Test] public void ProcessInfoArgs() { - Assert.AreEqual("-D \"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments); + Assert.AreEqual("-X:Debug \"C:\\Projects\\test.py\"", debugger.ProcessStartInfo.Arguments); } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/FormsDesignerDisplayBindingTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/FormsDesignerDisplayBindingTestFixture.cs similarity index 95% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/FormsDesignerDisplayBindingTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/FormsDesignerDisplayBindingTestFixture.cs index ae257c9c6a..6580488bc6 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/FormsDesignerDisplayBindingTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/FormsDesignerDisplayBindingTestFixture.cs @@ -8,12 +8,13 @@ using System; using ICSharpCode.FormsDesigner; using ICSharpCode.PythonBinding; +using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Gui; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { /// /// Tests the PythonFormsDesignerDisplayBinding. @@ -23,8 +24,8 @@ namespace PythonBinding.Tests { DerivedPythonFormsDesignerDisplayBinding displayBinding; MockTextEditorViewContent viewContent; - ParseInformation parseInfo; bool canAttachToDesignableClass; + ParseInformation parseInfo; [SetUp] public void SetUp() @@ -32,7 +33,7 @@ namespace PythonBinding.Tests displayBinding = new DerivedPythonFormsDesignerDisplayBinding(); viewContent = new MockTextEditorViewContent(); parseInfo = new ParseInformation(new DefaultCompilationUnit(new DefaultProjectContent())); - viewContent.PrimaryFileName = new ICSharpCode.Core.FileName("test.py"); + viewContent.PrimaryFileName = new FileName("test.py"); viewContent.TextEditor.Document.Text = "text content"; displayBinding.ParseServiceParseInfoToReturn = parseInfo; displayBinding.IsParseInfoDesignable = true; @@ -99,7 +100,7 @@ namespace PythonBinding.Tests [Test] public void NonPythonFileNameCannotBeAttachedTo() { - viewContent.PrimaryFileName = new ICSharpCode.Core.FileName("test.cs"); + viewContent.PrimaryFileName = new FileName("test.cs"); Assert.IsFalse(displayBinding.CanAttachTo(viewContent)); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonIndentationTests.cs similarity index 98% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonIndentationTests.cs index 866a632a5b..9bcfc0f973 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonIndentationTests.cs @@ -13,13 +13,13 @@ using ICSharpCode.TextEditor.Actions; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests.Indentation +namespace PythonBinding.Tests { /// /// Tests that the PythonFormattingStrategy indents the new line added after pressing the ':' character. /// [TestFixture] - public class PythonNewMethodIndentationTestFixture + public class PythonIndentationTestFixture { TextEditorControl textEditor; PythonFormattingStrategy formattingStrategy; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonOptionsPanelTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonOptionsPanelTestFixture.cs similarity index 67% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonOptionsPanelTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonOptionsPanelTestFixture.cs index c02b17827e..e5d645ff59 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonOptionsPanelTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonOptionsPanelTestFixture.cs @@ -5,16 +5,16 @@ // $Revision$ // -using ICSharpCode.SharpDevelop.Gui.OptionPanels; using System; using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.PythonBinding; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Gui.OptionPanels; using NUnit.Framework; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { /// /// Tests the PythonOptionsPanel. @@ -26,6 +26,7 @@ namespace PythonBinding.Tests Properties properties; AddInOptions options; TextBox fileNameTextBox; + TextBox pythonLibraryPathTextBox; [SetUp] public void SetUp() @@ -33,9 +34,11 @@ namespace PythonBinding.Tests properties = new Properties(); options = new AddInOptions(properties); options.PythonFileName = @"C:\Python\ipy.exe"; + options.PythonLibraryPath = @"C:\Python26\lib"; optionsPanel = new PythonOptionsPanel(options); optionsPanel.LoadPanelContents(); fileNameTextBox = (TextBox)optionsPanel.ControlDictionary["pythonFileNameTextBox"]; + pythonLibraryPathTextBox = (TextBox)optionsPanel.ControlDictionary["pythonLibraryPathTextBox"]; } [TearDown] @@ -47,7 +50,13 @@ namespace PythonBinding.Tests [Test] public void PythonFileNameDisplayed() { - Assert.AreEqual(options.PythonFileName, fileNameTextBox.Text); + Assert.AreEqual(@"C:\Python\ipy.exe", fileNameTextBox.Text); + } + + [Test] + public void PythonLibraryPathIsDisplayed() + { + Assert.AreEqual(@"C:\Python26\lib", pythonLibraryPathTextBox.Text); } [Test] @@ -57,12 +66,21 @@ namespace PythonBinding.Tests } [Test] - public void SaveOptions() + public void SavingOptionsUpdatesIronPythonFileName() { string fileName = @"C:\Program Files\IronPython\ipy.exe"; fileNameTextBox.Text = fileName; optionsPanel.StorePanelContents(); Assert.AreEqual(fileName, options.PythonFileName); } + + [Test] + public void SavingOptionsUpdatesIronPythonLibraryPath() + { + string path = @"c:\Program Files\Python\lib"; + pythonLibraryPathTextBox.Text = path; + optionsPanel.StorePanelContents(); + Assert.AreEqual(path, options.PythonLibraryPath); + } } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonSyntaxModeTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonSyntaxModeTestFixture.cs similarity index 99% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonSyntaxModeTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonSyntaxModeTestFixture.cs index 261749e7e6..64209fb9eb 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonSyntaxModeTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/PythonSyntaxModeTestFixture.cs @@ -16,8 +16,9 @@ using ICSharpCode.AvalonEdit.AddIn; using ICSharpCode.Core; using ICSharpCode.TextEditor.Document; using NUnit.Framework; +using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { /// /// Tests the Python.xshd syntax mode information. diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/RunPythonCommandTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/RunPythonCommandTestFixture.cs similarity index 98% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/RunPythonCommandTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/RunPythonCommandTestFixture.cs index 1e5cf87015..97a148f5f5 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/RunPythonCommandTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Gui/RunPythonCommandTestFixture.cs @@ -13,7 +13,7 @@ using ICSharpCode.SharpDevelop.Gui; using NUnit.Framework; using PythonBinding.Tests.Utils; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Gui { /// /// Tests that the RunPythonCommand class runs the Python console diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ClassWithBaseClassTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ClassWithBaseClassTestFixture.cs index df26c3a68d..58d3c03080 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ClassWithBaseClassTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ClassWithBaseClassTestFixture.cs @@ -52,6 +52,5 @@ namespace PythonBinding.Tests.Parsing } Assert.IsNotNull(matchedBaseType); } - } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseClassNestedInsideMethodTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseClassNestedInsideMethodTestFixture.cs new file mode 100644 index 0000000000..5d479b83da --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseClassNestedInsideMethodTestFixture.cs @@ -0,0 +1,59 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.TextEditor.Document; +using NUnit.Framework; +using PythonBinding.Tests; + +namespace PythonBinding.Tests.Parsing +{ + [TestFixture] + public class ParseClassNestedInsideMethodTestFixture + { + ICompilationUnit compilationUnit; + IClass c; + + [SetUp] + public void SetUpFixture() + { + string python = + "class MyClass:\r\n" + + " def firstMethod(self):\r\n" + + " class NestedClass:\r\n" + + " def firstNestedClassMethod(self):\r\n" + + " pass\r\n" + + "\r\n" + + " def secondMethod(self):\r\n" + + " pass\r\n" + + "\r\n"; + + DefaultProjectContent projectContent = new DefaultProjectContent(); + PythonParser parser = new PythonParser(); + compilationUnit = parser.Parse(projectContent, @"C:\test.py", python); + if (compilationUnit.Classes.Count > 0) { + c = compilationUnit.Classes[0]; + } + } + + [Test] + public void CompilationUnitHasOneClass() + { + Assert.AreEqual(1, compilationUnit.Classes.Count); + } + + [Test] + public void MyClassHasTwoMethods() + { + Assert.AreEqual(2, c.Methods.Count); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseTestClassTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseTestClassTestFixture.cs new file mode 100644 index 0000000000..76415f2318 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseTestClassTestFixture.cs @@ -0,0 +1,52 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.Dom; +using NUnit.Framework; + +namespace PythonBinding.Tests.Parsing +{ + [TestFixture] + public class ParseTestClassTestFixture + { + ICompilationUnit compilationUnit; + IClass c; + + [TestFixtureSetUp] + public void SetUpFixture() + { + string python = + "import unittest\r\n" + + "\r\n" + + "class simpleTest(unittest.TestCase):\r\n" + + " def testSuccess(self):\r\n" + + " assert True\r\n" + + "\r\n" + + " def testFailure(self):\r\n" + + " assert False\r\n" + + "\r\n"; + + DefaultProjectContent projectContent = new DefaultProjectContent(); + PythonParser parser = new PythonParser(); + compilationUnit = parser.Parse(projectContent, @"C:\test.py", python); + if (compilationUnit.Classes.Count > 0) { + c = compilationUnit.Classes[0]; + } + } + + [Test] + public void SimpleTestFirstBaseTypeIsUnitTestTestCase() + { + IReturnType baseType = c.BaseTypes[0]; + string actualBaseTypeName = baseType.FullyQualifiedName; + string expectedBaseTypeName = "unittest.TestCase"; + Assert.AreEqual(expectedBaseTypeName, actualBaseTypeName); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseTestClassWithBaseClassTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseTestClassWithBaseClassTestFixture.cs new file mode 100644 index 0000000000..2fe65b4a3b --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Parsing/ParseTestClassWithBaseClassTestFixture.cs @@ -0,0 +1,89 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.Dom; +using NUnit.Framework; + +namespace PythonBinding.Tests.Parsing +{ + [TestFixture] + public class ParseTestClassWithBaseClassTestFixture + { + ICompilationUnit compilationUnit; + IClass c; + DefaultProjectContent projectContent; + + [TestFixtureSetUp] + public void SetUpFixture() + { + string python = + "import unittest\r\n" + + "\r\n" + + "class BaseTest(unittest.TestCase):\r\n" + + " def testSuccess(self):\r\n" + + " assert True\r\n" + + "\r\n" + + "class DerivedTest(BaseTest):\r\n" + + " pass\r\n" + + "\r\n"; + + projectContent = new DefaultProjectContent(); + PythonParser parser = new PythonParser(); + string fileName = @"C:\test.py"; + compilationUnit = parser.Parse(projectContent, fileName, python); + projectContent.UpdateCompilationUnit(null, compilationUnit, fileName); + if (compilationUnit.Classes.Count > 1) { + c = compilationUnit.Classes[1]; + } + } + + [Test] + public void DerivedTestFirstBaseTypeIsBaseTestTestCase() + { + IReturnType baseType = c.BaseTypes[0]; + string actualBaseTypeName = baseType.FullyQualifiedName; + string expectedBaseTypeName = "test.BaseTest"; + Assert.AreEqual(expectedBaseTypeName, actualBaseTypeName); + } + + [Test] + public void DerivedTestBaseClassNameIsBaseTest() + { + IClass baseClass = c.BaseClass; + string actualName = baseClass.FullyQualifiedName; + string expectedName = "test.BaseTest"; + Assert.AreEqual(expectedName, actualName); + } + + [Test] + public void ProjectContentGetClassReturnsBaseTest() + { + IClass c = projectContent.GetClass("test.BaseTest", 0); + Assert.AreEqual("test.BaseTest", c.FullyQualifiedName); + } + + [Test] + public void CompilationUnitUsingScopeNamespaceNameIsNamespaceTakenFromFileName() + { + string expectedNamespace = "test"; + Assert.AreEqual(expectedNamespace, compilationUnit.UsingScope.NamespaceName); + } + + [Test] + public void DerivedTestBaseClassHasTestCaseBaseClass() + { + IReturnType baseType = c.BaseTypes[0]; + IClass baseClass = baseType.GetUnderlyingClass(); + IReturnType baseBaseType = baseClass.BaseTypes[0]; + string actualBaseTypeName = baseBaseType.FullyQualifiedName; + string expectedBaseTypeName = "unittest.TestCase"; + Assert.AreEqual(expectedBaseTypeName, actualBaseTypeName); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj index 69ef73d933..a872c44704 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBinding.Tests.csproj @@ -79,11 +79,7 @@ - - - - @@ -104,6 +100,8 @@ + + @@ -199,7 +197,6 @@ - @@ -342,12 +339,19 @@ - - + + + + + + + + + @@ -364,12 +368,11 @@ - - - - - - + + + + + @@ -416,9 +419,22 @@ - + + + + + + + + + + + + + + @@ -426,7 +442,6 @@ - @@ -437,8 +452,9 @@ + + - @@ -447,12 +463,12 @@ - + @@ -463,6 +479,7 @@ + PythonBinding.addin @@ -472,11 +489,13 @@ + + @@ -504,6 +523,10 @@ {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} ICSharpCode.Core + + {857CA1A3-FC88-4BE0-AB6A-D1EE772AB288} + ICSharpCode.Core.WinForms + {924EE450-603D-49C1-A8E5-4AFAA31CE6F3} ICSharpCode.SharpDevelop.Dom @@ -512,6 +535,14 @@ {8035765F-D51F-4A0C-A746-2FD100E19419} ICSharpCode.SharpDevelop.Widgets + + {44A8DE09-CAB9-49D8-9CFC-5EB0A552F181} + UnitTesting.Tests + + + {1F261725-6318-4434-A1B1-6C70CE4CD324} + UnitTesting + {0162E499-42D0-409B-AA25-EED21F75336B} AvalonEdit.AddIn @@ -529,6 +560,10 @@ + + + + diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguage/CreateNewPythonProjectTestFixture.cs similarity index 100% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/CreateNewPythonProjectTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguage/CreateNewPythonProjectTestFixture.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/ProjectBindingTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguage/ProjectBindingTestFixture.cs similarity index 100% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/ProjectBindingTestFixture.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguage/ProjectBindingTestFixture.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguagePropertiesTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguage/PythonLanguagePropertiesTests.cs similarity index 100% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguagePropertiesTests.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonLanguage/PythonLanguagePropertiesTests.cs diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleFromSystemImportEverythingFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleFromSystemImportEverythingFixture.cs index 09f4654490..a73cc401d6 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleFromSystemImportEverythingFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleFromSystemImportEverythingFixture.cs @@ -13,6 +13,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom.CSharp; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleWriteLineTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleWriteLineTestFixture.cs index 9cea39b099..d02815eb21 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleWriteLineTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveConsoleWriteLineTestFixture.cs @@ -12,6 +12,7 @@ using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveFooTextBoxFromSystemWindowsFormsImportedAsFooTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveFooTextBoxFromSystemWindowsFormsImportedAsFooTestFixture.cs index 1ffbca464d..108ba743e3 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveFooTextBoxFromSystemWindowsFormsImportedAsFooTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveFooTextBoxFromSystemWindowsFormsImportedAsFooTestFixture.cs @@ -13,6 +13,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom.CSharp; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveLocalClassInstanceTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveLocalClassInstanceTestFixture.cs index 0db59b8a0c..9f5c872712 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveLocalClassInstanceTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveLocalClassInstanceTestFixture.cs @@ -12,6 +12,7 @@ using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { @@ -27,7 +28,7 @@ namespace PythonBinding.Tests.Resolver public class ResolveLocalClassInstanceTestFixture { PythonResolver resolver; - MockProjectContent mockProjectContent; + PythonBinding.Tests.Utils.MockProjectContent mockProjectContent; LocalResolveResult resolveResult; MockClass testClass; ICompilationUnit compilationUnit; @@ -37,7 +38,7 @@ namespace PythonBinding.Tests.Resolver { resolver = new PythonResolver(); - mockProjectContent = new MockProjectContent(); + mockProjectContent = new PythonBinding.Tests.Utils.MockProjectContent(); testClass = new MockClass(mockProjectContent, "Test.Test1"); mockProjectContent.ClassesInProjectContent.Add(testClass); mockProjectContent.ClassToReturnFromGetClass = testClass; diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemConsoleTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemConsoleTestFixture.cs index 626bb6455b..0e014b791c 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemConsoleTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemConsoleTestFixture.cs @@ -12,6 +12,7 @@ using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { @@ -23,7 +24,7 @@ namespace PythonBinding.Tests.Resolver public class ResolveSystemConsoleTestFixture { PythonResolver resolver; - MockProjectContent mockProjectContent; + PythonBinding.Tests.Utils.MockProjectContent mockProjectContent; ResolveResult resolveResult; MockClass testClass; ICompilationUnit compilationUnit; @@ -34,7 +35,7 @@ namespace PythonBinding.Tests.Resolver public void SetUpFixture() { resolver = new PythonResolver(); - mockProjectContent = new MockProjectContent(); + mockProjectContent = new PythonBinding.Tests.Utils.MockProjectContent(); systemConsoleClass = new MockClass(mockProjectContent, "System.Console"); mockProjectContent.ClassToReturnFromGetClass = systemConsoleClass; @@ -106,7 +107,7 @@ namespace PythonBinding.Tests.Resolver protected virtual ICompilationUnit CreateCompilationUnit(IProjectContent projectContent) { ICompilationUnit compilationUnit = new DefaultCompilationUnit(projectContent); - testClass = new MockClass(compilationUnit, "Test"); + testClass = new MockClass(projectContent, "Test"); compilationUnit.Classes.Add(testClass); return compilationUnit; } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemNamespaceWithMissingImportTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemNamespaceWithMissingImportTestFixture.cs index bb7a50a2f1..7a30fb97a4 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemNamespaceWithMissingImportTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveSystemNamespaceWithMissingImportTestFixture.cs @@ -11,6 +11,7 @@ using ICSharpCode.PythonBinding; using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportTextBoxTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportTextBoxTestFixture.cs index 2f5d3448ff..6fe5b03465 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportTextBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportTextBoxTestFixture.cs @@ -13,6 +13,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom.CSharp; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportedAsMyTextBoxTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportedAsMyTextBoxTestFixture.cs index 3157cd7283..304ad0fe38 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportedAsMyTextBoxTestFixture.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Resolver/ResolveTextBoxFromSystemWindowsFormsImportedAsMyTextBoxTestFixture.cs @@ -13,6 +13,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom.CSharp; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Resolver { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreatePythonTestRunnerTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreatePythonTestRunnerTestFixture.cs new file mode 100644 index 0000000000..09846b1aa3 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreatePythonTestRunnerTestFixture.cs @@ -0,0 +1,52 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.PythonBinding; +using NUnit.Framework; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class CreatePythonTestRunnerTestFixture + { + PythonTestFramework testFramework; + + [TestFixtureSetUp] + public void SetUpFixture() + { + if (!PropertyService.Initialized) { + PropertyService.InitializeService(String.Empty, String.Empty, String.Empty); + } + } + + [SetUp] + public void Init() + { + testFramework = new PythonTestFramework(); + } + + [Test] + public void PythonTestFrameworkCreateTestRunnerReturnsPythonTestRunner() + { + Assert.IsInstanceOf(typeof(PythonTestRunner), testFramework.CreateTestRunner()); + } + + [Test] + public void PythonTestFrameworkCreateTestDebuggerReturnsPythonTestDebugger() + { + Assert.IsInstanceOf(typeof(PythonTestDebugger), testFramework.CreateTestDebugger()); + } + + [Test] + public void PythonTestFrameworkIsBuildNeededBeforeTestRunReturnsFalse() + { + Assert.IsFalse(testFramework.IsBuildNeededBeforeTestRun); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreateTextWriterFromCreateTextWriterInfoTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreateTextWriterFromCreateTextWriterInfoTestFixture.cs new file mode 100644 index 0000000000..a0f36b8026 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreateTextWriterFromCreateTextWriterInfoTestFixture.cs @@ -0,0 +1,41 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using ICSharpCode.PythonBinding; +using NUnit.Framework; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class CreateTextWriterFromCreateTextWriterInfoTestFixture + { + TextWriter textWriter; + + [TestFixtureSetUp] + public void SetUpFixture() + { + string fileName = Path.GetTempFileName(); + CreateTextWriterInfo info = new CreateTextWriterInfo(fileName, Encoding.UTF8, false); + textWriter = info.CreateTextWriter(); + } + + [TestFixtureTearDown] + public void TearDownFixture() + { + textWriter.Dispose(); + } + + [Test] + public void CreatedTextWriterEncodingIsUtf8() + { + Assert.AreEqual(Encoding.UTF8, textWriter.Encoding); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreateTextWriterInfoEqualsTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreateTextWriterInfoEqualsTestFixture.cs new file mode 100644 index 0000000000..3c8e19c2f1 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/CreateTextWriterInfoEqualsTestFixture.cs @@ -0,0 +1,57 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Text; +using ICSharpCode.PythonBinding; +using NUnit.Framework; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class CreateTextWriterInfoEqualsTestFixture + { + [Test] + public void CreateTextWriterInfosAreEqualWhenFileNameAndEncodingAndAppendAreEqual() + { + CreateTextWriterInfo lhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + CreateTextWriterInfo rhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + Assert.AreEqual(lhs, rhs); + } + + [Test] + public void CreateTextWriterInfosAreNotEqualWhenFileNamesAreDifferent() + { + CreateTextWriterInfo lhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + CreateTextWriterInfo rhs = new CreateTextWriterInfo("different-filename.txt", Encoding.UTF8, true); + Assert.AreNotEqual(lhs, rhs); + } + + [Test] + public void CreateTextWriterInfosAreNotEqualWhenEncodingsAreDifferent() + { + CreateTextWriterInfo lhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + CreateTextWriterInfo rhs = new CreateTextWriterInfo("test.txt", Encoding.ASCII, true); + Assert.AreNotEqual(lhs, rhs); + } + + [Test] + public void CreateTextWriterInfosAreNotEqualWhenAppendIsDifferent() + { + CreateTextWriterInfo lhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + CreateTextWriterInfo rhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, false); + Assert.AreNotEqual(lhs, rhs); + } + + [Test] + public void CreateTextWriterInfoEqualsReturnsFalseWhenNullPassedAsParameter() + { + CreateTextWriterInfo lhs = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + Assert.IsFalse(lhs.Equals(null)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs new file mode 100644 index 0000000000..be81d28ebd --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonConsoleApplicationTestFixture.cs @@ -0,0 +1,95 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using ICSharpCode.Core; +using ICSharpCode.PythonBinding; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonConsoleApplicationTestFixture + { + PythonConsoleApplication app; + AddInOptions options; + + [SetUp] + public void Init() + { + options = new AddInOptions(new Properties()); + options.PythonFileName = @"C:\IronPython\ipy.exe"; + app = new PythonConsoleApplication(options); + } + + [Test] + public void FileNameIsPythonFileNameFromAddInOptions() + { + string expectedFileName = @"C:\IronPython\ipy.exe"; + Assert.AreEqual(expectedFileName, app.FileName); + } + + [Test] + public void GetArgumentsReturnsDebugOptionWhenDebugIsTrue() + { + app.Debug = true; + string expectedCommandLine = "-X:Debug"; + + Assert.AreEqual(expectedCommandLine, app.GetArguments()); + } + + [Test] + public void GetArgumentsReturnsQuotedPythonScriptFileName() + { + app.PythonScriptFileName = @"d:\projects\my ipy\test.py"; + string expectedCommandLine = "\"d:\\projects\\my ipy\\test.py\""; + + Assert.AreEqual(expectedCommandLine, app.GetArguments()); + } + + [Test] + public void GetArgumentsReturnsQuotedPythonScriptFileNameAndItsCommandLineArguments() + { + app.Debug = true; + app.PythonScriptFileName = @"d:\projects\my ipy\test.py"; + app.PythonScriptCommandLineArguments = "@responseFile.txt -def"; + string expectedCommandLine = + "-X:Debug \"d:\\projects\\my ipy\\test.py\" @responseFile.txt -def"; + + Assert.AreEqual(expectedCommandLine, app.GetArguments()); + } + + [Test] + public void GetProcessStartInfoHasFileNameThatEqualsIronPythonConsoleApplicationExeFileName() + { + ProcessStartInfo startInfo = app.GetProcessStartInfo(); + string expectedFileName = @"C:\IronPython\ipy.exe"; + + Assert.AreEqual(expectedFileName, startInfo.FileName); + } + + [Test] + public void GetProcessStartInfoHasDebugFlagSetInArguments() + { + app.Debug = true; + ProcessStartInfo startInfo = app.GetProcessStartInfo(); + string expectedCommandLine = "-X:Debug"; + + Assert.AreEqual(expectedCommandLine, startInfo.Arguments); + } + + [Test] + public void GetProcessStartInfoHasWorkingDirectoryIfSet() + { + app.WorkingDirectory = @"d:\temp"; + ProcessStartInfo startInfo = app.GetProcessStartInfo(); + Assert.AreEqual(@"d:\temp", startInfo.WorkingDirectory); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonStandardLibraryPathTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonStandardLibraryPathTests.cs new file mode 100644 index 0000000000..53835dd60f --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonStandardLibraryPathTests.cs @@ -0,0 +1,82 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.PythonBinding; +using NUnit.Framework; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonStandardLibraryPathTests + { + [Test] + public void PathsPropertyReturnsPython26LibDirectory() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(@"c:\python26\lib"); + string[] expectedPaths = new string[] { @"c:\python26\lib" }; + Assert.AreEqual(expectedPaths, path.Directories); + } + + [Test] + public void HasPathReturnsTrueForNonEmptyPathString() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(@"c:\python26\lib"); + Assert.IsTrue(path.HasPath); + } + + [Test] + public void HasPathReturnsFalseForEmptyPathString() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(String.Empty); + Assert.IsFalse(path.HasPath); + } + + [Test] + public void DirectoryPropertyReturnsPython26LibDirectoryAndPython26LibTkDirectory() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(@"c:\python26\lib;c:\python26\lib\lib-tk"); + string[] expectedPaths = new string[] { @"c:\python26\lib", @"c:\python26\lib\lib-tk" }; + Assert.AreEqual(expectedPaths, path.Directories); + } + + [Test] + public void DirectoryPropertyReturnsPython26LibDirectoryAndPython26LibTkDirectorySetInPathProperty() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(String.Empty); + path.Path = @"c:\python26\lib;c:\python26\lib\lib-tk"; + string[] expectedPaths = new string[] { @"c:\python26\lib", @"c:\python26\lib\lib-tk" }; + Assert.AreEqual(expectedPaths, path.Directories); + } + + [Test] + public void DirectoriesAreClearedWhenPathIsSetToDifferentValue() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(@"c:\temp"); + path.Path = @"c:\python26\lib;c:\python26\lib\lib-tk"; + string[] expectedPaths = new string[] { @"c:\python26\lib", @"c:\python26\lib\lib-tk" }; + Assert.AreEqual(expectedPaths, path.Directories); + } + + [Test] + public void EmptyDirectoryInPathNotAddedToDirectories() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(@"c:\temp;;c:\python\lib"); + string[] expectedPaths = new string[] { @"c:\temp", @"c:\python\lib" }; + Assert.AreEqual(expectedPaths, path.Directories); + } + + [Test] + public void DirectoryWithJustWhitespaceIsNotAddedToPath() + { + PythonStandardLibraryPath path = new PythonStandardLibraryPath(@"c:\temp; ;c:\python\lib"); + string[] expectedPaths = new string[] { @"c:\temp", @"c:\python\lib" }; + Assert.AreEqual(expectedPaths, path.Directories); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs new file mode 100644 index 0000000000..23a00b7809 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs @@ -0,0 +1,156 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using ICSharpCode.Core; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.UnitTesting; +using NUnit.Framework; +using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestDebuggerRunsSelectedTestMethodTestFixture + { + MockDebuggerService debuggerService; + UnitTesting.Tests.Utils.MockDebugger debugger; + MockMessageService messageService; + MockCSharpProject project; + PythonTestDebugger testDebugger; + MockTestResultsMonitor testResultsMonitor; + SelectedTests selectedTests; + MockMethod methodToTest; + AddInOptions options; + MockPythonFileService fileService; + StringBuilder responseFileText; + StringWriter responseFileStringWriter; + PythonStandardLibraryPath standardLibraryPath; + + [SetUp] + public void Init() + { + CreateTestDebugger(); + CreateTestMethod(); + } + + void CreateTestDebugger() + { + debuggerService = new MockDebuggerService(); + debugger = debuggerService.MockDebugger; + messageService = new MockMessageService(); + testResultsMonitor = new MockTestResultsMonitor(); + options = new AddInOptions(new Properties()); + options.PythonFileName = @"c:\ironpython\ipy.exe"; + standardLibraryPath = new PythonStandardLibraryPath(@"c:\python\lib"); + fileService = new MockPythonFileService(); + testDebugger = new PythonTestDebugger(debuggerService, messageService, testResultsMonitor, options, standardLibraryPath, fileService); + } + + void CreateTestMethod() + { + project = new MockCSharpProject(); + MockClass c = new MockClass("MyNamespace.MyTestClass"); + methodToTest = new MockMethod(c, "MyTestMethod"); + } + + void RunTestsOnSelectedTestMethod() + { + fileService.SetTempFileName(@"d:\temp\tmp66.tmp"); + CreateTemporaryResponseFileWriter(); + + selectedTests = new SelectedTests(project, null, null, methodToTest); + testDebugger.Start(selectedTests); + } + + void CreateTemporaryResponseFileWriter() + { + responseFileText = new StringBuilder(); + responseFileStringWriter = new StringWriter(responseFileText); + fileService.SetTextWriter(responseFileStringWriter); + } + + [Test] + public void TestDebuggerProcessFileNameIsIronPythonConsoleExeTakenFromAddInOptions() + { + RunTestsOnSelectedTestMethod(); + + string expectedFileName = @"c:\ironpython\ipy.exe"; + Assert.AreEqual(expectedFileName, debugger.ProcessStartInfo.FileName); + } + + [Test] + public void DisposingTestRunnerDeletesTemporaryResponseFile() + { + fileService.FileNameDeleted = null; + RunTestsOnSelectedTestMethod(); + testDebugger.Dispose(); + + string expectedFileName = @"d:\temp\tmp66.tmp"; + Assert.AreEqual(expectedFileName, fileService.FileNameDeleted); + } + + [Test] + public void DisposingTestRunnerDisposesTestResultsMonitor() + { + RunTestsOnSelectedTestMethod(); + testDebugger.Dispose(); + Assert.IsTrue(testResultsMonitor.IsDisposeMethodCalled); + } + + [Test] + public void CommandLineArgumentHasSharpDevelopTestPythonScriptAndResponseFileName() + { + AddIn addin = AddInPathHelper.CreateDummyPythonAddInInsideAddInTree(); + addin.FileName = @"c:\sharpdevelop\addins\pythonbinding\pythonbinding.addin"; + + RunTestsOnSelectedTestMethod(); + + string expectedCommandLine = + "-X:Debug " + + "\"c:\\sharpdevelop\\addins\\pythonbinding\\TestRunner\\sdtest.py\" " + + "\"@d:\\temp\\tmp66.tmp\""; + + Assert.AreEqual(expectedCommandLine, debugger.ProcessStartInfo.Arguments); + } + + [Test] + public void PythonTestResultReturnedFromTestFinishedEvent() + { + TestResult testResult = null; + testDebugger.TestFinished += delegate(object source, TestFinishedEventArgs e) { + testResult = e.Result; + }; + TestResult testResultToFire = new TestResult("test"); + testResultsMonitor.FireTestFinishedEvent(testResultToFire); + + Assert.IsInstanceOf(typeof(PythonTestResult), testResult); + } + + [Test] + public void ResponseFileTextContainsPythonLibraryPathFromPythonStandardLibraryPathObjectIfNotDefinedInAddInOptions() + { + standardLibraryPath.Path = @"c:\python\lib;c:\python\lib\lib-tk"; + options.PythonLibraryPath = String.Empty; + testResultsMonitor.FileName = @"c:\temp\test-results.txt"; + RunTestsOnSelectedTestMethod(); + + string expectedText = + "/p:\"c:\\python\\lib\"\r\n" + + "/p:\"c:\\python\\lib\\lib-tk\"\r\n" + + "/r:\"c:\\temp\\test-results.txt\"\r\n" + + "MyNamespace.MyTestClass.MyTestMethod\r\n"; + + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestClassTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestClassTests.cs new file mode 100644 index 0000000000..4723afc598 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestClassTests.cs @@ -0,0 +1,75 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.Dom; +using NUnit.Framework; +using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestFrameworkIsTestClassTests + { + PythonTestFramework testFramework; + + [SetUp] + public void Init() + { + testFramework = new PythonTestFramework(); + } + + [Test] + public void CreateClassWithUnitTestTestCaseBaseTypeReturnsClassWithFirstBaseTypeEqualToTestCase() + { + IClass c = MockClass.CreateClassWithBaseType("unittest.TestCase"); + string name = c.BaseTypes[0].FullyQualifiedName; + string expectedName = "unittest.TestCase"; + Assert.AreEqual(expectedName, name); + } + + [Test] + public void IsTestClassReturnsTrueWhenClassFirstBaseTypeIsUnitTestTestCase() + { + MockClass c = MockClass.CreateClassWithBaseType("unittest.TestCase"); + Assert.IsTrue(testFramework.IsTestClass(c)); + } + + [Test] + public void IsTestClassReturnsFalseWhenClassHasNoBaseTypes() + { + MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); + Assert.IsFalse(testFramework.IsTestClass(c)); + } + + [Test] + public void IsTestClassReturnsFalseForNull() + { + Assert.IsFalse(testFramework.IsTestClass(null)); + } + + [Test] + public void IsTestClassReturnsFalseWhenFirstBaseTypeIsSystemWindowsFormsForm() + { + MockClass c = MockClass.CreateClassWithBaseType("System.Windows.Forms.Form"); + Assert.IsFalse(testFramework.IsTestClass(c)); + } + + [Test] + public void IsTestClassReturnsTrueWhenDerivedClassHasBaseClassDerivedFromTestCase() + { + MockClass baseClass = MockClass.CreateClassWithBaseType("unittest.TestCase"); + MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); + DefaultReturnType returnType = new DefaultReturnType(baseClass); + c.BaseTypes.Add(returnType); + + Assert.IsTrue(testFramework.IsTestClass(c)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestMethodTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestMethodTests.cs new file mode 100644 index 0000000000..1ec715060d --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestMethodTests.cs @@ -0,0 +1,49 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using NUnit.Framework; +using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestFrameworkIsTestMethodTests + { + PythonTestFramework testFramework; + + [SetUp] + public void Init() + { + testFramework = new PythonTestFramework(); + } + + [Test] + public void IsTestMethodReturnsTrueForMethodThatStartsWithTest() + { + MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); + MockMethod method = new MockMethod(c, "testRunThis"); + Assert.IsTrue(testFramework.IsTestMethod(method)); + } + + [Test] + public void IsTestMethodReturnsFalseForNull() + { + Assert.IsFalse(testFramework.IsTestMethod(null)); + } + + [Test] + public void IsTestMethodReturnsFalseForMethodThatDoesNotStartWithTest() + { + MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); + MockMethod method = new MockMethod(c, "RunThis"); + Assert.IsFalse(testFramework.IsTestMethod(method)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestProjectTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestProjectTests.cs new file mode 100644 index 0000000000..f6a0a979ae --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestFrameworkIsTestProjectTests.cs @@ -0,0 +1,66 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.Internal.Templates; +using ICSharpCode.SharpDevelop.Project; +using NUnit.Framework; +using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestFrameworkIsTestProjectTests + { + PythonTestFramework testFramework; + + [TestFixtureSetUp] + public void SetUpFixture() + { + MSBuildEngineHelper.InitMSBuildEngine(); + } + + [SetUp] + public void Init() + { + testFramework = new PythonTestFramework(); + } + + [Test] + public void IsTestProjectReturnsFalseForNull() + { + Assert.IsFalse(testFramework.IsTestProject(null)); + } + + [Test] + public void IsTestProjectReturnsTrueForPythonProject() + { + ProjectCreateInformation createInfo = new ProjectCreateInformation(); + createInfo.Solution = new Solution(); + createInfo.OutputProjectFileName = @"C:\projects\test.pyproj"; + PythonProject project = new PythonProject(createInfo); + + Assert.IsTrue(testFramework.IsTestProject(project)); + } + + [Test] + public void IsTestProjectReturnsFalseForNonPythonProject() + { + MockProject project = new MockProject(); + Assert.IsFalse(testFramework.IsTestProject(project)); + } + + [Test] + public void IsTestProjectReturnsFalseForNullPythonProject() + { + PythonProject project = null; + Assert.IsFalse(testFramework.IsTestProject(project)); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestResultFailureTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestResultFailureTestFixture.cs new file mode 100644 index 0000000000..24770b8d89 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestResultFailureTestFixture.cs @@ -0,0 +1,90 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.PythonBinding; +using ICSharpCode.UnitTesting; +using NUnit.Framework; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestResultFailureTestFixture + { + PythonTestResult pythonTestResult; + string stackTraceText; + + [SetUp] + public void Init() + { + TestResult testResult = new TestResult("MyTest"); + testResult.ResultType = TestResultType.Failure; + testResult.Message = "test failed"; + + stackTraceText = + "Traceback (most recent call last):\r\n" + + " File \"d:\\temp\\test\\PyTests\\Tests\\MyClassTest.py\", line 16, in testAssertEquals\r\n" + + " self.assertEqual(10, 15, 'wrong size after resize')\r\n" + + "AssertionError: wrong size after resize"; + + testResult.StackTrace = stackTraceText; + pythonTestResult = new PythonTestResult(testResult); + } + + [Test] + public void TestResultNameIsMyTest() + { + Assert.AreEqual("MyTest", pythonTestResult.Name); + } + + [Test] + public void TestResultTypeIsFailure() + { + Assert.AreEqual(TestResultType.Failure, pythonTestResult.ResultType); + } + + [Test] + public void TestResultMessageIsTestFailed() + { + Assert.AreEqual("test failed", pythonTestResult.Message); + } + + [Test] + public void PythonTestResultHasStackTraceFromOriginalTestResult() + { + Assert.AreEqual(stackTraceText, pythonTestResult.StackTrace); + } + + [Test] + public void StackTraceFilePositionHasExpectedFileName() + { + string expectedFileName = "d:\\temp\\test\\PyTests\\Tests\\MyClassTest.py"; + Assert.AreEqual(expectedFileName, pythonTestResult.StackTraceFilePosition.FileName); + } + + [Test] + public void StackTraceFilePositionLineIs16() + { + Assert.AreEqual(16, pythonTestResult.StackTraceFilePosition.Line); + } + + [Test] + public void StackTraceFilePositionColumnIsOne() + { + Assert.AreEqual(1, pythonTestResult.StackTraceFilePosition.Column); + } + + [Test] + public void ChangingStackTraceToEmptyStringSetsStackTraceFilePositionToEmpty() + { + pythonTestResult.StackTraceFilePosition = new FilePosition("test.cs", 10, 2); + pythonTestResult.StackTrace = String.Empty; + Assert.IsTrue(pythonTestResult.StackTraceFilePosition.IsEmpty); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestResultStackTraceLineNumberOverflowTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestResultStackTraceLineNumberOverflowTestFixture.cs new file mode 100644 index 0000000000..3dcfd3dd04 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestResultStackTraceLineNumberOverflowTestFixture.cs @@ -0,0 +1,44 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.PythonBinding; +using ICSharpCode.UnitTesting; +using NUnit.Framework; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestResultLineNumberOverflowTestFixture + { + PythonTestResult pythonTestResult; + string stackTraceText; + + [SetUp] + public void Init() + { + TestResult testResult = new TestResult("MyTest"); + testResult.ResultType = TestResultType.Failure; + testResult.Message = "test failed"; + + stackTraceText = + "Traceback (most recent call last):\r\n" + + " File \"d:\\temp\\test\\PyTests\\Tests\\MyClassTest.py\", line 4294967296, in testAssertEquals\r\n" + + " self.assertEqual(10, 15, 'wrong size after resize')\r\n" + + "AssertionError: wrong size after resize"; + + testResult.StackTrace = stackTraceText; + pythonTestResult = new PythonTestResult(testResult); + } + + [Test] + public void StackTraceFilePositionIsEmpty() + { + Assert.IsTrue(pythonTestResult.StackTraceFilePosition.IsEmpty); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestRunnerResponseFileTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestRunnerResponseFileTestFixture.cs new file mode 100644 index 0000000000..57b1ff8486 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestRunnerResponseFileTestFixture.cs @@ -0,0 +1,206 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using ICSharpCode.Core.Services; +using ICSharpCode.PythonBinding; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.UnitTesting; +using NUnit.Framework; +using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestRunnerResponseFileTestFixture + { + PythonTestRunnerResponseFile responseFile; + StringBuilder responseFileText; + StringWriter writer; + + [SetUp] + public void Init() + { + responseFileText = new StringBuilder(); + writer = new StringWriter(responseFileText); + responseFile = new PythonTestRunnerResponseFile(writer); + } + + [Test] + public void WriteTestAddsTestNameToResponseFile() + { + responseFile.WriteTest("MyTests"); + + Assert.AreEqual("MyTests\r\n", responseFileText.ToString()); + } + + [Test] + public void WritePathAddsQuotedSysPathCommandLineArgument() + { + responseFile.WritePath(@"c:\mytests"); + + string expectedText = "/p:\"c:\\mytests\"\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void WriteResultsFileNameAddsQuotedResultsFileNameCommandLineArgument() + { + responseFile.WriteResultsFileName(@"c:\temp\tmp66.tmp"); + + string expectedText = "/r:\"c:\\temp\\tmp66.tmp\"\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void DisposeMethodDisposesTextWriterPassedInConstructor() + { + responseFile.Dispose(); + Assert.Throws(delegate { writer.Write("test"); }); + } + + [Test] + public void WriteTestsWritesSelectedTestMethodNameWhenMethodSelected() + { + MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); + method.FullyQualifiedName = "MyNamespace.MyTests.MyTestMethod"; + SelectedTests tests = new SelectedTests(new MockCSharpProject(), null, null, method); + + responseFile.WriteTests(tests); + + string expectedText = "MyNamespace.MyTests.MyTestMethod\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void WriteTestsWritesSelectedTestClassNameWhenOnlyClassSelected() + { + MockClass c = MockClass.CreateMockClassWithoutAnyAttributes(); + c.FullyQualifiedName = "MyNamespace.MyTests"; + SelectedTests tests = new SelectedTests(new MockCSharpProject(), null, c, null); + + responseFile.WriteTests(tests); + + string expectedText = "MyNamespace.MyTests\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void WriteTestsWritesSelectedTestNamespaceWhenOnlyNamespaceSelected() + { + SelectedTests tests = new SelectedTests(new MockCSharpProject(), "MyNamespace", null, null); + responseFile.WriteTests(tests); + + string expectedText = "MyNamespace\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void WriteTestsWritesNamespacesForAllFilesInProjectWhenOnlyProjectSelected() + { + MockCSharpProject project = new MockCSharpProject(); + + FileProjectItem item = new FileProjectItem(project, ItemType.Compile); + item.FileName = @"c:\projects\mytests\nonTestClass.py"; + ProjectService.AddProjectItem(project, item); + + item = new FileProjectItem(project, ItemType.Compile); + item.FileName = @"c:\projects\mytests\TestClass.py"; + ProjectService.AddProjectItem(project, item); + + SelectedTests tests = new SelectedTests(project); + + responseFile.WriteTests(tests); + + string expectedText = + "nonTestClass\r\n" + + "TestClass\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void WriteTestsWritesNothingToResponseFileWhenMethodAndClassAndNamespaceAndProjectIsNull() + { + SelectedTests tests = new SelectedTests(null); + responseFile.WriteTests(tests); + Assert.AreEqual(String.Empty, responseFileText.ToString()); + } + + [Test] + public void WriteTestsDoesNotThrowNullReferenceExceptionWhenNonFileProjectItemInProject() + { + MockCSharpProject project = new MockCSharpProject(); + WebReferenceUrl webRef = new WebReferenceUrl(project); + webRef.Include = "test"; + ProjectService.AddProjectItem(project, webRef); + + FileProjectItem item = new FileProjectItem(project, ItemType.Compile); + item.FileName = @"c:\projects\mytests\myTests.py"; + ProjectService.AddProjectItem(project, item); + + SelectedTests tests = new SelectedTests(project); + responseFile.WriteTests(tests); + + string expectedText = "myTests\r\n"; + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void WriteTestsWritesDirectoriesForReferencedProjectsToSysPathCommandLineArguments() + { + // Have to initialize the workbench since ProjectReferenceProjectItem has a dependency on + // WorkbenchSingleton. + InitializeWorkbench(); + + MockCSharpProject referencedProject = new MockCSharpProject(); + referencedProject.FileName = @"c:\projects\pyproject\pyproject.pyproj"; + + MockCSharpProject unitTestProject = new MockCSharpProject(); + ProjectReferenceProjectItem projectRef = new ProjectReferenceProjectItem(unitTestProject, referencedProject); + projectRef.FileName = @"c:\projects\pyproject\pyproject.pyproj"; + ProjectService.AddProjectItem(unitTestProject, projectRef); + + MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes(); + method.FullyQualifiedName = "MyNamespace.MyTests.MyTestMethod"; + + SelectedTests tests = new SelectedTests(unitTestProject, null, null, method); + responseFile.WriteTests(tests); + + string expectedText = + "/p:\"c:\\projects\\pyproject\"\r\n" + + "MyNamespace.MyTests.MyTestMethod\r\n"; + + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + void InitializeWorkbench() + { + string addInXml = + "\r\n" + + "\r\n" + + " \r\n" + + "\r\n" + + "\r\n " + + ""; + AddIn addin = AddIn.Load(new StringReader(addInXml)); + addin.Enabled = true; + AddInTree.InsertAddIn(addin); + if (!PropertyService.Initialized) { + PropertyService.InitializeService(String.Empty, String.Empty, String.Empty); + } + DummyServiceManager serviceManager = new DummyServiceManager(); + ServiceManager.Instance = serviceManager; + WorkbenchSingleton.InitializeWorkbench(new MockWorkbench(), null); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestRunnerRunsSelectedTestMethodTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestRunnerRunsSelectedTestMethodTestFixture.cs new file mode 100644 index 0000000000..38fce06d8d --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestRunnerRunsSelectedTestMethodTestFixture.cs @@ -0,0 +1,225 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Diagnostics; +using System.IO; +using System.Text; +using ICSharpCode.Core; +using ICSharpCode.PythonBinding; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.UnitTesting; +using NUnit.Framework; +using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; + +namespace PythonBinding.Tests.Testing +{ + [TestFixture] + public class PythonTestRunnerRunsSelectedTestMethodTestFixture + { + MockCSharpProject project; + PythonTestRunner testRunner; + MockProcessRunner processRunner; + MockTestResultsMonitor testResultsMonitor; + SelectedTests selectedTests; + MockMethod methodToTest; + AddInOptions options; + MockPythonFileService fileService; + StringBuilder responseFileText; + StringWriter responseFileStringWriter; + PythonStandardLibraryPath standardLibraryPath; + + [SetUp] + public void Init() + { + CreateTestRunner(); + CreateTestMethod(); + } + + void CreateTestRunner() + { + processRunner = new MockProcessRunner(); + testResultsMonitor = new MockTestResultsMonitor(); + options = new AddInOptions(new Properties()); + options.PythonFileName = @"c:\ironpython\ipy.exe"; + fileService = new MockPythonFileService(); + standardLibraryPath = new PythonStandardLibraryPath(@"c:\python\lib"); + + testRunner = new PythonTestRunner(processRunner, testResultsMonitor, options, standardLibraryPath, fileService); + } + + void CreateTestMethod() + { + project = new MockCSharpProject(); + MockClass c = new MockClass("MyNamespace.MyTestClass"); + methodToTest = new MockMethod(c, "MyTestMethod"); + } + + void RunTestsOnSelectedTestMethod() + { + fileService.SetTempFileName(@"d:\temp\tmp66.tmp"); + CreateTemporaryResponseFileWriter(); + + selectedTests = new SelectedTests(project, null, null, methodToTest); + testRunner.Start(selectedTests); + } + + void CreateTemporaryResponseFileWriter() + { + responseFileText = new StringBuilder(); + responseFileStringWriter = new StringWriter(responseFileText); + fileService.SetTextWriter(responseFileStringWriter); + } + + [Test] + public void TestRunnerProcessFileNameIsIronPythonConsoleExeTakenFromAddInOptions() + { + RunTestsOnSelectedTestMethod(); + + string expectedFileName = @"c:\ironpython\ipy.exe"; + Assert.AreEqual(expectedFileName, processRunner.CommandPassedToStartMethod); + } + + [Test] + public void CommandLineArgumentHasSharpDevelopTestPythonScriptAndResponseFileName() + { + AddIn addin = AddInPathHelper.CreateDummyPythonAddInInsideAddInTree(); + addin.FileName = @"c:\sharpdevelop\addins\pythonbinding\pythonbinding.addin"; + + RunTestsOnSelectedTestMethod(); + + string expectedCommandLine = + "\"c:\\sharpdevelop\\addins\\pythonbinding\\TestRunner\\sdtest.py\" " + + "\"@d:\\temp\\tmp66.tmp\""; + + Assert.AreEqual(expectedCommandLine, processRunner.CommandArgumentsPassedToStartMethod); + } + + [Test] + public void ResponseFileCreatedUsingTempFileName() + { + RunTestsOnSelectedTestMethod(); + + Assert.AreEqual(@"d:\temp\tmp66.tmp", fileService.CreateTextWriterInfoPassedToCreateTextWriter.FileName); + } + + [Test] + public void ResponseFileCreatedWithUtf8Encoding() + { + RunTestsOnSelectedTestMethod(); + + Assert.AreEqual(Encoding.UTF8, fileService.CreateTextWriterInfoPassedToCreateTextWriter.Encoding); + } + + [Test] + public void ResponseFileCreatedWithAppendSetToFalse() + { + RunTestsOnSelectedTestMethod(); + + Assert.IsFalse(fileService.CreateTextWriterInfoPassedToCreateTextWriter.Append); + } + + [Test] + public void DisposingTestRunnerDeletesTemporaryResponseFile() + { + fileService.FileNameDeleted = null; + RunTestsOnSelectedTestMethod(); + testRunner.Dispose(); + + string expectedFileName = @"d:\temp\tmp66.tmp"; + Assert.AreEqual(expectedFileName, fileService.FileNameDeleted); + } + + [Test] + public void DisposingTestRunnerDisposesTestResultsMonitor() + { + RunTestsOnSelectedTestMethod(); + testRunner.Dispose(); + Assert.IsTrue(testResultsMonitor.IsDisposeMethodCalled); + } + + [Test] + public void ResponseFileTextContainsPythonLibraryPathAndTestResultsFileNameAndFullyQualifiedTestMethod() + { + standardLibraryPath.Path = String.Empty; + options.PythonLibraryPath = @"c:\python26\lib"; + testResultsMonitor.FileName = @"c:\temp\test-results.txt"; + RunTestsOnSelectedTestMethod(); + + string expectedText = + "/p:\"c:\\python26\\lib\"\r\n" + + "/r:\"c:\\temp\\test-results.txt\"\r\n" + + "MyNamespace.MyTestClass.MyTestMethod\r\n"; + + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void ResponseFileTextDoesNotContainPythonLibraryPathIfItIsAnEmptyString() + { + options.PythonLibraryPath = String.Empty; + standardLibraryPath.Path = String.Empty; + testResultsMonitor.FileName = @"c:\temp\test-results.txt"; + RunTestsOnSelectedTestMethod(); + + string expectedText = + "/r:\"c:\\temp\\test-results.txt\"\r\n" + + "MyNamespace.MyTestClass.MyTestMethod\r\n"; + + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void ResponseFileTextContainsPythonLibraryPathFromPythonStandardLibraryPathObjectIfNotDefinedInAddInOptions() + { + standardLibraryPath.Path = @"c:\python\lib"; + options.PythonLibraryPath = String.Empty; + testResultsMonitor.FileName = @"c:\temp\test-results.txt"; + RunTestsOnSelectedTestMethod(); + + string expectedText = + "/p:\"c:\\python\\lib\"\r\n" + + "/r:\"c:\\temp\\test-results.txt\"\r\n" + + "MyNamespace.MyTestClass.MyTestMethod\r\n"; + + Assert.AreEqual(expectedText, responseFileText.ToString()); + } + + [Test] + public void ResponseFileTextWriterDisposedAfterTestsRun() + { + RunTestsOnSelectedTestMethod(); + Assert.Throws(delegate { responseFileStringWriter.Write("test"); }); + } + + [Test] + public void ProcessRunnerWorkingDirectoryIsDirectoryContainingProject() + { + RunTestsOnSelectedTestMethod(); + + string expectedDirectory = @"c:\projects\MyTests"; + string actualDirectory = processRunner.WorkingDirectory; + + Assert.AreEqual(expectedDirectory, actualDirectory); + } + + [Test] + public void PythonTestResultReturnedFromTestFinishedEvent() + { + TestResult testResult = null; + testRunner.TestFinished += delegate(object source, TestFinishedEventArgs e) { + testResult = e.Result; + }; + TestResult testResultToFire = new TestResult("test"); + testResultsMonitor.FireTestFinishedEvent(testResultToFire); + + Assert.IsInstanceOf(typeof(PythonTestResult), testResult); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInPathHelper.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInPathHelper.cs new file mode 100644 index 0000000000..3b2722db3c --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/AddInPathHelper.cs @@ -0,0 +1,60 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using ICSharpCode.Core; + +namespace PythonBinding.Tests.Utils +{ + public static class AddInPathHelper + { + public static AddIn CreateDummyPythonAddInInsideAddInTree() + { + RemoveOldAddIn(); + AddIn addin = CreateAddIn(); + AddInTree.InsertAddIn(addin); + return addin; + } + + static void RemoveOldAddIn() + { + AddIn oldAddin = FindOldAddIn(); + if (oldAddin != null) { + AddInTree.RemoveAddIn(oldAddin); + } + } + + static AddIn FindOldAddIn() + { + foreach (AddIn addin in AddInTree.AddIns) { + if (addin.Manifest.PrimaryIdentity == "ICSharpCode.PythonBinding") { + return addin; + } + } + return null; + } + + static AddIn CreateAddIn() + { + string xml = GetAddInXml(); + AddIn addin = AddIn.Load(new StringReader(xml)); + addin.FileName = @"C:\SharpDevelop\AddIns\PythonBinding\PythonBinding.addin"; + return addin; + } + + static string GetAddInXml() + { + return + "\r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + ""; + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedAddInOptions.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedAddInOptions.cs deleted file mode 100644 index 00f3dee1ec..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedAddInOptions.cs +++ /dev/null @@ -1,52 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using ICSharpCode.Core; -using ICSharpCode.PythonBinding; - -namespace PythonBinding.Tests.Utils -{ - /// - /// Overrides the AddInOptions GetAddInPath method to return - /// some dummy data used for testing. - /// - public class DerivedAddInOptions : AddInOptions - { - string addInPath = String.Empty; - string addInPathRequested = String.Empty; - - public DerivedAddInOptions(Properties properties) : base(properties) - { - } - - /// - /// Gets the addin path string passed to the GetAddInPath method. - /// - public string AddInPathRequested { - get { return addInPathRequested; } - } - - /// - /// Gets or sets the addin path that should be returned from the - /// GetAddInPath method. - /// - public string AddInPath { - get { return addInPath; } - set { addInPath = value; } - } - - /// - /// Returns our dummy AddInPath. - /// - protected override string GetAddInPath(string addIn) - { - addInPathRequested = addIn; - return addInPath; - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedPythonDesignerLoader.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedPythonDesignerLoader.cs index 9847bb2e27..66a14d1bbe 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedPythonDesignerLoader.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DerivedPythonDesignerLoader.cs @@ -35,7 +35,6 @@ namespace PythonBinding.Tests.Utils protected override void OnEndLoad(bool successful, ICollection errors) { - System.Console.WriteLine("DesignerLoader.OnEndLoad: successful: " + successful); if (errors != null) { foreach (object o in errors) { Exception ex = o as Exception; @@ -49,22 +48,17 @@ namespace PythonBinding.Tests.Utils protected override void OnBeginLoad() { - System.Console.WriteLine("DesignerLoader.OnBeginLoad"); base.OnBeginLoad(); } protected override void Initialize() { - System.Console.WriteLine("DesignerLoader.Initialize"); base.Initialize(); } protected override void PerformLoad(IDesignerSerializationManager manager) { - System.Console.WriteLine("DesignerLoader.PerformLoad Before"); base.PerformLoad(manager); - System.Console.WriteLine("DesignerLoader.PerformLoad After"); } - } } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DummyServiceManager.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DummyServiceManager.cs new file mode 100644 index 0000000000..a63456cfc9 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DummyServiceManager.cs @@ -0,0 +1,32 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Windows.Forms; +using ICSharpCode.Core.Services; +using ICSharpCode.Core.WinForms; + +namespace PythonBinding.Tests.Utils +{ + public class DummyServiceManager : ServiceManager + { + WinFormsMessageService messageService = new WinFormsMessageService(); + + public DummyServiceManager() + { + } + + public override IMessageService MessageService { + get { return messageService; } + } + + public override object GetService(Type serviceType) + { + return null; + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DummySynchronizeInvoke.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DummySynchronizeInvoke.cs new file mode 100644 index 0000000000..07a4dbf4fc --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/DummySynchronizeInvoke.cs @@ -0,0 +1,38 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; + +namespace PythonBinding.Tests.Utils +{ + public class DummySynchronizeInvoke : ISynchronizeInvoke + { + public DummySynchronizeInvoke() + { + } + + public bool InvokeRequired { + get { return false; } + } + + public IAsyncResult BeginInvoke(Delegate method, object[] args) + { + return null; + } + + public object EndInvoke(IAsyncResult result) + { + return null; + } + + public object Invoke(Delegate method, object[] args) + { + return null; + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockClass.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockClass.cs deleted file mode 100644 index f3dce124e0..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockClass.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.Collections.Generic; -using ICSharpCode.SharpDevelop.Dom; - -namespace PythonBinding.Tests.Utils -{ - /// - /// Mock implementation of the IClass interface - /// - public class MockClass : DefaultClass - { - // derive from real DefaultClass. The resolver is free to access any information from the class, - // and I don't want to have to adjust the mock whenever something in SharpDevelop.Dom changes. - public MockClass(ICompilationUnit cu, string name) - : base(cu, name) - { - } - - public MockClass(IProjectContent pc, string name) - : base(new DefaultCompilationUnit(pc), name) - { - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDesignerLoaderHost.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDesignerLoaderHost.cs index 4c3ccf4f85..d50bc05ed6 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDesignerLoaderHost.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockDesignerLoaderHost.cs @@ -86,7 +86,6 @@ namespace PythonBinding.Tests.Utils public void EndLoad(string baseClassName, bool successful, ICollection errorCollection) { - System.Console.WriteLine("DesignerLoaderHost.EndLoad"); } public void Reload() @@ -133,13 +132,11 @@ namespace PythonBinding.Tests.Utils public Type GetType(string typeName) { - System.Console.WriteLine("DesignerLoaderHost.GetType: " + typeName); return typeResolutionService.GetType(typeName); } public void AddService(Type serviceType, object serviceInstance) { - System.Console.WriteLine("DesignerLoaderHost.AddService: " + serviceType.Name + " IsNull: " + (serviceInstance == null)); serviceContainer.AddService(serviceType, serviceInstance); } @@ -165,7 +162,6 @@ namespace PythonBinding.Tests.Utils public object GetService(Type serviceType) { - System.Console.WriteLine("DesignerLoaderHost.GetService: " + serviceType.Name); return serviceContainer.GetService(serviceType); } @@ -203,7 +199,7 @@ namespace PythonBinding.Tests.Utils TransactionOpened(this, e); } } - + protected virtual void OnTransactionOpening(EventArgs e) { if (TransactionOpening != null) { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs deleted file mode 100644 index 6e4bd60dcd..0000000000 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockMethod.cs +++ /dev/null @@ -1,297 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.Collections.Generic; -using ICSharpCode.SharpDevelop.Dom; - -namespace PythonBinding.Tests.Utils -{ - /// - /// Mock IMethod implementation. - /// - public class MockMethod : IMethod - { - public MockMethod() - { - } - - public DomRegion BodyRegion { get; set; } - - public IList TypeParameters { - get { - throw new NotImplementedException(); - } - } - - public bool IsConstructor { - get { - throw new NotImplementedException(); - } - } - - public bool IsOperator { - get { - throw new NotImplementedException(); - } - } - - public IList HandlesClauses { - get { - throw new NotImplementedException(); - } - } - - public IList Parameters { - get { - throw new NotImplementedException(); - } - } - - public bool IsExtensionMethod { - get { - throw new NotImplementedException(); - } - } - - public string FullyQualifiedName { - get { - throw new NotImplementedException(); - } - } - - public IReturnType DeclaringTypeReference { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } - } - - public IMember GenericMember { - get { - throw new NotImplementedException(); - } - } - - public DomRegion Region { - get { - throw new NotImplementedException(); - } - } - - public string Name { - get { - throw new NotImplementedException(); - } - } - - public string Namespace { - get { - throw new NotImplementedException(); - } - } - - public string DotNetName { - get { - throw new NotImplementedException(); - } - } - - public IReturnType ReturnType { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } - } - - public IList InterfaceImplementations { - get { - throw new NotImplementedException(); - } - } - - public IClass DeclaringType { - get { - throw new NotImplementedException(); - } - } - - public ModifierEnum Modifiers { - get { - throw new NotImplementedException(); - } - } - - public IList Attributes { - get { - throw new NotImplementedException(); - } - } - - public string Documentation { - get { - throw new NotImplementedException(); - } - } - - public bool IsAbstract { - get { - throw new NotImplementedException(); - } - } - - public bool IsSealed { - get { - throw new NotImplementedException(); - } - } - - public bool IsStatic { - get { - throw new NotImplementedException(); - } - } - - public bool IsConst { - get { - throw new NotImplementedException(); - } - } - - public bool IsVirtual { - get { - throw new NotImplementedException(); - } - } - - public bool IsPublic { - get { - throw new NotImplementedException(); - } - } - - public bool IsProtected { - get { - throw new NotImplementedException(); - } - } - - public bool IsPrivate { - get { - throw new NotImplementedException(); - } - } - - public bool IsInternal { - get { - throw new NotImplementedException(); - } - } - - public bool IsReadonly { - get { - throw new NotImplementedException(); - } - } - - public bool IsProtectedAndInternal { - get { - throw new NotImplementedException(); - } - } - - public bool IsProtectedOrInternal { - get { - throw new NotImplementedException(); - } - } - - public bool IsOverride { - get { - throw new NotImplementedException(); - } - } - - public bool IsOverridable { - get { - throw new NotImplementedException(); - } - } - - public bool IsNew { - get { - throw new NotImplementedException(); - } - } - - public bool IsSynthetic { - get { - throw new NotImplementedException(); - } - } - - public object UserData { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } - } - - public bool IsFrozen { - get { - throw new NotImplementedException(); - } - } - - public IMember CreateSpecializedMember() - { - throw new NotImplementedException(); - } - - public bool IsAccessible(IClass callingClass, bool isClassInInheritanceTree) - { - throw new NotImplementedException(); - } - - public void Freeze() - { - throw new NotImplementedException(); - } - - public int CompareTo(object obj) - { - throw new NotImplementedException(); - } - - public object Clone() - { - throw new NotImplementedException(); - } - - public ICompilationUnit CompilationUnit { - get { - throw new NotImplementedException(); - } - } - - public IProjectContent ProjectContent { - get { - throw new NotImplementedException(); - } - } - - public EntityType EntityType { - get { return EntityType.Method; } - } - } -} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonFileService.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonFileService.cs new file mode 100644 index 0000000000..27a1998081 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockPythonFileService.cs @@ -0,0 +1,58 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using ICSharpCode.PythonBinding; + +namespace PythonBinding.Tests.Utils +{ + public class MockPythonFileService : IPythonFileService + { + CreateTextWriterInfo createTextWriterInfoPassedToCreateTextWriter; + string tempFileName; + TextWriter textWriter; + string fileNameDeleted; + + public void SetTempFileName(string fileName) + { + this.tempFileName = fileName; + } + + public string GetTempFileName() + { + return tempFileName; + } + + public void SetTextWriter(TextWriter writer) + { + this.textWriter = writer; + } + + public TextWriter CreateTextWriter(CreateTextWriterInfo textWriterInfo) + { + createTextWriterInfoPassedToCreateTextWriter = textWriterInfo; + return textWriter; + } + + public CreateTextWriterInfo CreateTextWriterInfoPassedToCreateTextWriter { + get { return createTextWriterInfoPassedToCreateTextWriter; } + set { createTextWriterInfoPassedToCreateTextWriter = value; } + } + + public void DeleteFile(string fileName) + { + fileNameDeleted = fileName; + } + + public string FileNameDeleted { + get { return fileNameDeleted; } + set { fileNameDeleted = value; } + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTypeResolutionService.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTypeResolutionService.cs index cf9ffde229..d52e52cf7b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTypeResolutionService.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockTypeResolutionService.cs @@ -43,7 +43,6 @@ namespace PythonBinding.Tests.Utils public Type GetType(string name) { - System.Console.WriteLine("TypeResolutionService.GetType: " + name); lastTypeNameResolved = name; if (name == "Form") { return typeof(Form); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs index 6310d8b40f..a461e47415 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/MockWorkbench.cs @@ -19,6 +19,9 @@ namespace PythonBinding.Tests.Utils /// public class MockWorkbench : IWorkbench { + DummySynchronizeInvoke synchronizeInvoke = new DummySynchronizeInvoke(); + Form form = new Form(); + public event EventHandler ActiveWorkbenchWindowChanged { add {} remove {} } public event EventHandler ActiveViewContentChanged { add {} remove {} } public event EventHandler ActiveContentChanged { add {} remove {} } @@ -26,11 +29,11 @@ namespace PythonBinding.Tests.Utils public event ViewContentEventHandler ViewClosed { add {} remove {} } public IWin32Window MainWin32Window { - get { return null; } + get { return form; } } public System.ComponentModel.ISynchronizeInvoke SynchronizingObject { - get { return null; } + get { return synchronizeInvoke; } } public System.Windows.Window MainWindow { @@ -90,12 +93,8 @@ namespace PythonBinding.Tests.Utils } public IWorkbenchLayout WorkbenchLayout { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } + get { return null; } + set { } } public bool IsActiveWindow { @@ -106,7 +105,6 @@ namespace PythonBinding.Tests.Utils public void Initialize() { - throw new NotImplementedException(); } public void ShowView(IViewContent content) @@ -156,7 +154,6 @@ namespace PythonBinding.Tests.Utils public void SetMemento(Properties memento) { - throw new NotImplementedException(); } public bool FullScreen { diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBindingAddInFile.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonBindingAddInFile.cs similarity index 96% rename from src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBindingAddInFile.cs rename to src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonBindingAddInFile.cs index bedd439175..c41cc5fc74 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonBindingAddInFile.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/PythonBindingAddInFile.cs @@ -10,7 +10,7 @@ using System.IO; using System.Reflection; using System.Xml; -namespace PythonBinding.Tests +namespace PythonBinding.Tests.Utils { /// /// Utility class that reads the PythonBinding.addin file diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/AddInPathHelperTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/AddInPathHelperTestFixture.cs new file mode 100644 index 0000000000..ceeb152e46 --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/AddInPathHelperTestFixture.cs @@ -0,0 +1,50 @@ +// +// +// +// +// $Revision$ +// + +using System; +using ICSharpCode.Core; +using NUnit.Framework; +using PythonBinding.Tests.Utils; + +namespace PythonBinding.Tests.Utils.Tests +{ + [TestFixture] + public class AddInPathHelperTestFixture + { + AddIn pythonAddIn; + + [SetUp] + public void Init() + { + pythonAddIn = AddInPathHelper.CreateDummyPythonAddInInsideAddInTree(); + } + + [Test] + public void AddInFileNameIsCDriveSharpDevelopAddInsPythonBindingPythonBindingAddIn() + { + string expectedFileName = @"C:\SharpDevelop\AddIns\PythonBinding\PythonBinding.addin"; + Assert.AreEqual(expectedFileName, pythonAddIn.FileName); + } + + [Test] + public void StringParserAddInPathIsCDriveSharpDevelopAddInsPythonBindingForPythonBindingAddIn() + { + string directory = StringParser.Parse("${addinpath:ICSharpCode.PythonBinding}"); + string expectedDirectory = @"C:\SharpDevelop\AddIns\PythonBinding"; + Assert.AreEqual(expectedDirectory, directory); + } + + [Test] + public void ChangingAddInFileNameReturnsExpectedFileNameFromStringParserAddInPath() + { + pythonAddIn.FileName = @"c:\def\pythonbinding.addin"; + string expectedDirectory = @"c:\def"; + string actualDirectory = StringParser.Parse("${addinpath:ICSharpCode.PythonBinding}"); + Assert.AreEqual(expectedDirectory, actualDirectory); + } + } +} diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockProjectContentTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockProjectContentTests.cs index f3e04c8f35..bd3b3e4339 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockProjectContentTests.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockProjectContentTests.cs @@ -11,19 +11,20 @@ using ICSharpCode.PythonBinding; using ICSharpCode.SharpDevelop.Dom; using NUnit.Framework; using PythonBinding.Tests.Utils; +using UnitTesting.Tests.Utils; namespace PythonBinding.Tests.Utils.Tests { [TestFixture] public class MockProjectContentTests { - MockProjectContent projectContent; + PythonBinding.Tests.Utils.MockProjectContent projectContent; List items; [SetUp] public void Init() { - projectContent = new MockProjectContent(); + projectContent = new PythonBinding.Tests.Utils.MockProjectContent(); items = new List(); } diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockPythonFileServiceTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockPythonFileServiceTestFixture.cs new file mode 100644 index 0000000000..0b068bd50a --- /dev/null +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Utils/Tests/MockPythonFileServiceTestFixture.cs @@ -0,0 +1,65 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.IO; +using System.Text; +using ICSharpCode.PythonBinding; +using NUnit.Framework; + +namespace PythonBinding.Tests.Utils.Tests +{ + [TestFixture] + public class MockPythonFileServiceTestFixture + { + MockPythonFileService fileService; + + [SetUp] + public void Init() + { + fileService = new MockPythonFileService(); + } + + [Test] + public void GetTempFileNameReturnsReturnsTemporaryFileName() + { + string expectedFileName = @"c:\temp\tmp1.tmp"; + fileService.SetTempFileName(expectedFileName); + string tempFileName = fileService.GetTempFileName(); + Assert.AreEqual(expectedFileName, tempFileName); + } + + [Test] + public void TextWriterReturnedFromCreateTextWriter() + { + using (StringWriter stringWriter = new StringWriter(new StringBuilder())) { + fileService.SetTextWriter(stringWriter); + CreateTextWriterInfo info = new CreateTextWriterInfo(@"test.tmp", Encoding.UTF8, true); + Assert.AreEqual(stringWriter, fileService.CreateTextWriter(info)); + } + } + + [Test] + public void CreateTextWriterInfoIsSavedWhenCreateTextWriterMethodIsCalled() + { + fileService.CreateTextWriterInfoPassedToCreateTextWriter = null; + CreateTextWriterInfo info = new CreateTextWriterInfo("test.txt", Encoding.UTF8, true); + fileService.CreateTextWriter(info); + Assert.AreEqual(info, fileService.CreateTextWriterInfoPassedToCreateTextWriter); + } + + [Test] + public void DeleteFileSavesFileNameDeleted() + { + fileService.FileNameDeleted = null; + string expectedFileName = @"c:\temp\tmp66.tmp"; + fileService.DeleteFile(expectedFileName); + + Assert.AreEqual(expectedFileName, fileService.FileNameDeleted); + } + } +} diff --git a/src/Setup/Files.wxs b/src/Setup/Files.wxs index 8d3bfa351b..e07cf623b6 100644 --- a/src/Setup/Files.wxs +++ b/src/Setup/Files.wxs @@ -10,72 +10,72 @@ + NGens SharpDevelop.exe. Needs the NetFx extension (WixNetFxExtension.dll), + library (netfx.wixlib) and custom actions (netfxca.dll). + + Priority=0 means the image generation occurs during + setup. Other values defer the generation. + + Default Platform value is 32bit which tries to generate images + for 32 bitversions of the .NET framework on the + target machine. This will fail on a machine with + 64 bit version of .NET. Cannot use Platform=all + since this runs NGen for both 32 and 64 bit versions + regardless of whether they exist on the target + machine. + --> + Get several ICE33 warnings using the ProgId element + but these apparently can safely be ignored + according to a post on the wix-users list by + Rob Mencshing. Also using the ProgId element + does not create the ProgId table. The current installer + no longer uses the ProgId but instead uses Registry + keys instead. It still creates the same entries in the + msi. + + http://sourceforge.net/mailarchive/message.php?msg_id=9075241 + + Note that the Target of the form [#FileId] expands out to the + full path of the file. A target of the form [!FileId] + expands to the short name of the file (i.e. it includes ~ + characters). We need the full path otherwise the exe name + will be something like SharpDev~1.exe and the + SharpDevelop.exe.manifest file will not be found when + running the application so it does not use XP visual styles. + Unfortunately using [#FileId] generates lots of ICE69 + warnings for the icon and the SharpDevelop.exe target + if they are in a different component. + Not sure why [!FileId] does not produce an error since + the problem seems to be similar, basically the registry + key generated by the ProgId element belongs to one + component whilst we are referencing another component + containing the SharpDevelop.exe and another + containing the icon. + + http://msdn.microsoft.com/library/en-us/msi/setup/ice69.asp + + The ICE69 errors can be ignored for now since the component + being referenced by the file associations will always be installed + even though it is in a different feature. If the FileTypeRegister + addin is an optional install then the ICE69 errors would need to + be resolved. + + We are not using the ProgId element which sets up the + file association registry keys for us, but are specifying them + directly as registry keys. This allows us to use one of the keys + as a key path instead of having to use the parent component's + directory as the key path. The key path is what is used + by the installer to detect whether the component is installed. + Using the component's parent directory (i.e. the Bin folder) + is not feasible since the file associations may not be installed + if the user does not install them in the feature tree. + --> @@ -947,13 +947,13 @@ + + + + + + + --> @@ -1037,6 +1037,14 @@ + + + + + + + + @@ -1182,35 +1190,35 @@ - + + + --> + @@ -1458,80 +1466,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + --> + The choice here is to either useW the IniFile element to + generate the two website shortcuts or create a + SharpDevelop.url file on disk and use a File element and + link to the file instead. We will use a file otherwise an + upgrade will not remove the existing website shortcut. + --> + ICE18 - Force the empty folder to be created. Even though it + has sub folders the validator flags this as an error. + + http://msdn.microsoft.com/library/en-us/msi/setup/ice18.asp + --> + App Path registry setting lives in HKLM so only add it if the + user has admin rights. + --> Privileged + Dummy components that are empty. These are used so + the feature tree does not show the Network installation + as an option. + --> + Fix ICE18 error. The validator thinks that the install folder + could be empty so we have to use CreateFolder in this component. + + http://msdn.microsoft.com/library/en-us/msi/setup/ice18.asp + --> + Fix ICE18 error. The validator thinks that the install folder + could be empty so we have to use CreateFolder in this component. + + http://msdn.microsoft.com/library/en-us/msi/setup/ice18.asp + --> @@ -1541,9 +1549,9 @@ + Fix ICE 38 by adding a dummy registry key that is the key for this shortcut. + http://msdn.microsoft.com/library/en-us/msi/setup/ice38.asp + --> @@ -1552,9 +1560,9 @@ + Fix ICE 38 by adding a dummy registry key that is the key for this shortcut. + http://msdn.microsoft.com/library/en-us/msi/setup/ice38.asp + --> diff --git a/src/Setup/Setup.wxs b/src/Setup/Setup.wxs index e1091fbe15..964bb2d1e0 100644 --- a/src/Setup/Setup.wxs +++ b/src/Setup/Setup.wxs @@ -376,9 +376,9 @@ - - - + + + @@ -398,6 +398,8 @@ + +