Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5861 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
87 changed files with 3402 additions and 900 deletions
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public interface IPythonFileService |
||||
{ |
||||
string GetTempFileName(); |
||||
TextWriter CreateTextWriter(CreateTextWriterInfo createTextWriterInfo); |
||||
void DeleteFile(string fileName); |
||||
} |
||||
} |
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using 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); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Security; |
||||
using Microsoft.Win32; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonStandardLibraryPath |
||||
{ |
||||
List<string> directories = new List<string>(); |
||||
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; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using ICSharpCode.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using 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; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Stack trace:
|
||||
/// Traceback (most recent call last):
|
||||
/// File "d:\temp\test\PyTests\Tests\MyClassTest.py", line 19, in testRaiseException
|
||||
/// raise 'abc'
|
||||
/// </summary>
|
||||
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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using 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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using 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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,122 @@
@@ -0,0 +1,122 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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<ProjectItem> 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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@
@@ -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() |
@ -0,0 +1,106 @@
@@ -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) |
@ -1,71 +0,0 @@
@@ -1,71 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the AddInOptions class.
|
||||
/// </summary>
|
||||
[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"]); |
||||
} |
||||
} |
||||
} |
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.PythonBinding; |
||||
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the From keyword is correctly identified as a
|
||||
/// importable code completion keyword.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Configuration |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the AddInOptions class.
|
||||
/// </summary>
|
||||
[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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.PythonBinding; |
||||
using 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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,156 @@
@@ -0,0 +1,156 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using 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()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,206 @@
@@ -0,0 +1,206 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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<ObjectDisposedException>(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 = |
||||
"<AddIn name=\"Test\" author= \"\" copyright=\"\" description=\"\">\r\n" + |
||||
"<Manifest>\r\n" + |
||||
" <Identity name=\"Test\"/>\r\n" + |
||||
"</Manifest>\r\n" + |
||||
"<Path name=\"/SharpDevelop/Workbench/DisplayBindings\"/>\r\n " + |
||||
"</AddIn>"; |
||||
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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,225 @@
@@ -0,0 +1,225 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using 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<ObjectDisposedException>(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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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 |
||||
"<AddIn name='PythonBinding' author= '' copyright='' description=''>\r\n" + |
||||
" <Manifest>\r\n" + |
||||
" <Identity name='ICSharpCode.PythonBinding'/>\r\n" + |
||||
" </Manifest>\r\n" + |
||||
"</AddIn>"; |
||||
} |
||||
} |
||||
} |
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.PythonBinding; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Overrides the AddInOptions GetAddInPath method to return
|
||||
/// some dummy data used for testing.
|
||||
/// </summary>
|
||||
public class DerivedAddInOptions : AddInOptions |
||||
{ |
||||
string addInPath = String.Empty; |
||||
string addInPathRequested = String.Empty; |
||||
|
||||
public DerivedAddInOptions(Properties properties) : base(properties) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the addin path string passed to the GetAddInPath method.
|
||||
/// </summary>
|
||||
public string AddInPathRequested { |
||||
get { return addInPathRequested; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the addin path that should be returned from the
|
||||
/// GetAddInPath method.
|
||||
/// </summary>
|
||||
public string AddInPath { |
||||
get { return addInPath; } |
||||
set { addInPath = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns our dummy AddInPath.
|
||||
/// </summary>
|
||||
protected override string GetAddInPath(string addIn) |
||||
{ |
||||
addInPathRequested = addIn; |
||||
return addInPath; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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; |
||||
} |
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Mock implementation of the IClass interface
|
||||
/// </summary>
|
||||
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) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -1,297 +0,0 @@
@@ -1,297 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace PythonBinding.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Mock IMethod implementation.
|
||||
/// </summary>
|
||||
public class MockMethod : IMethod |
||||
{ |
||||
public MockMethod() |
||||
{ |
||||
} |
||||
|
||||
public DomRegion BodyRegion { get; set; } |
||||
|
||||
public IList<ITypeParameter> TypeParameters { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsConstructor { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public bool IsOperator { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<string> HandlesClauses { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<IParameter> 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<ExplicitInterfaceImplementation> InterfaceImplementations { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IClass DeclaringType { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public ModifierEnum Modifiers { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public IList<IAttribute> 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; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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; } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using 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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue