~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Python/PythonBinding/Test/Testing/PythonTestDebuggerRunsSelectedTestMethodTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Diagnostics;
 
6
using System.IO;
 
7
using System.Text;
 
8
 
 
9
using ICSharpCode.Core;
 
10
using ICSharpCode.PythonBinding;
 
11
using ICSharpCode.Scripting.Tests.Utils;
 
12
using ICSharpCode.SharpDevelop.Dom;
 
13
using ICSharpCode.UnitTesting;
 
14
using NUnit.Framework;
 
15
using PythonBinding.Tests.Utils;
 
16
using UnitTesting.Tests.Utils;
 
17
 
 
18
namespace PythonBinding.Tests.Testing
 
19
{
 
20
        [TestFixture]
 
21
        public class PythonTestDebuggerRunsSelectedTestMethodTestFixture
 
22
        {
 
23
                MockDebuggerService debuggerService;
 
24
                UnitTesting.Tests.Utils.MockDebugger debugger;
 
25
                MockMessageService messageService;
 
26
                MockCSharpProject project;
 
27
                PythonTestDebugger testDebugger;
 
28
                MockTestResultsMonitor testResultsMonitor;
 
29
                SelectedTests selectedTests;
 
30
                MockMethod methodToTest;
 
31
                PythonAddInOptions options;
 
32
                MockScriptingFileService fileService;
 
33
                StringBuilder responseFileText;
 
34
                StringWriter responseFileStringWriter;
 
35
                PythonStandardLibraryPath standardLibraryPath;
 
36
                
 
37
                [SetUp]
 
38
                public void Init()
 
39
                {
 
40
                        CreateTestDebugger();
 
41
                        CreateTestMethod();
 
42
                }
 
43
                
 
44
                void CreateTestDebugger()
 
45
                {
 
46
                        debuggerService = new MockDebuggerService();
 
47
                        debugger = debuggerService.MockDebugger;
 
48
                        messageService = new MockMessageService();
 
49
                        testResultsMonitor = new MockTestResultsMonitor();
 
50
                        options = new PythonAddInOptions(new Properties());
 
51
                        options.PythonFileName = @"c:\ironpython\ipy.exe";
 
52
                        standardLibraryPath = new PythonStandardLibraryPath(@"c:\python\lib");
 
53
                        fileService = new MockScriptingFileService();
 
54
                        testDebugger = new PythonTestDebugger(debuggerService, messageService, testResultsMonitor, options, standardLibraryPath, fileService);
 
55
                }
 
56
                
 
57
                void CreateTestMethod()
 
58
                {
 
59
                        project = new MockCSharpProject();
 
60
                        MockClass c = new MockClass("MyNamespace.MyTestClass");
 
61
                        methodToTest = new MockMethod(c, "MyTestMethod");
 
62
                }
 
63
                
 
64
                void RunTestsOnSelectedTestMethod()
 
65
                {
 
66
                        fileService.SetTempFileName(@"d:\temp\tmp66.tmp");
 
67
                        CreateTemporaryResponseFileWriter();
 
68
                        
 
69
                        selectedTests = new SelectedTests(project, null, null, methodToTest);
 
70
                        testDebugger.Start(selectedTests);
 
71
                }
 
72
                
 
73
                void CreateTemporaryResponseFileWriter()
 
74
                {
 
75
                        responseFileText = new StringBuilder();
 
76
                        responseFileStringWriter = new StringWriter(responseFileText);
 
77
                        fileService.SetTextWriter(responseFileStringWriter);
 
78
                }
 
79
                
 
80
                [Test]
 
81
                public void TestDebuggerProcessFileNameIsIronPythonConsoleExeTakenFromAddInOptions()
 
82
                {
 
83
                        RunTestsOnSelectedTestMethod();
 
84
                        
 
85
                        string expectedFileName = @"c:\ironpython\ipy.exe";
 
86
                        Assert.AreEqual(expectedFileName, debugger.ProcessStartInfo.FileName);
 
87
                }
 
88
                
 
89
                [Test]
 
90
                public void DisposingTestRunnerDeletesTemporaryResponseFile()
 
91
                {
 
92
                        fileService.FileNameDeleted = null;
 
93
                        RunTestsOnSelectedTestMethod();
 
94
                        testDebugger.Dispose();
 
95
                        
 
96
                        string expectedFileName = @"d:\temp\tmp66.tmp";
 
97
                        Assert.AreEqual(expectedFileName, fileService.FileNameDeleted);
 
98
                }
 
99
                
 
100
                [Test]
 
101
                public void DisposingTestRunnerDisposesTestResultsMonitor()
 
102
                {
 
103
                        RunTestsOnSelectedTestMethod();
 
104
                        testDebugger.Dispose();
 
105
                        Assert.IsTrue(testResultsMonitor.IsDisposeMethodCalled);
 
106
                }
 
107
                
 
108
                [Test]
 
109
                public void CommandLineArgumentHasSharpDevelopTestPythonScriptAndResponseFileName()
 
110
                {
 
111
                        AddInPathHelper helper = new AddInPathHelper("PythonBinding");
 
112
                        AddIn addin = helper.CreateDummyAddInInsideAddInTree();
 
113
                        addin.FileName = @"c:\sharpdevelop\addins\pythonbinding\pythonbinding.addin";
 
114
                        
 
115
                        RunTestsOnSelectedTestMethod();
 
116
                        
 
117
                        string expectedCommandLine =
 
118
                                "-X:Debug " +
 
119
                                "\"c:\\sharpdevelop\\addins\\pythonbinding\\TestRunner\\sdtest.py\" " +
 
120
                                "\"@d:\\temp\\tmp66.tmp\"";
 
121
                        
 
122
                        Assert.AreEqual(expectedCommandLine, debugger.ProcessStartInfo.Arguments);
 
123
                }
 
124
                
 
125
                [Test]
 
126
                public void PythonTestResultReturnedFromTestFinishedEvent()
 
127
                {
 
128
                        TestResult testResult = null;
 
129
                        testDebugger.TestFinished += delegate(object source, TestFinishedEventArgs e) { 
 
130
                                testResult = e.Result;
 
131
                        };
 
132
                        TestResult testResultToFire = new TestResult("test");
 
133
                        testResultsMonitor.FireTestFinishedEvent(testResultToFire);
 
134
                        
 
135
                        Assert.IsInstanceOf(typeof(PythonTestResult), testResult);
 
136
                }
 
137
                
 
138
                [Test]
 
139
                public void ResponseFileTextContainsPythonLibraryPathFromPythonStandardLibraryPathObjectIfNotDefinedInAddInOptions()
 
140
                {
 
141
                        standardLibraryPath.Path = @"c:\python\lib;c:\python\lib\lib-tk";
 
142
                        options.PythonLibraryPath = String.Empty;
 
143
                        testResultsMonitor.FileName = @"c:\temp\test-results.txt";
 
144
                        RunTestsOnSelectedTestMethod();
 
145
                        
 
146
                        string expectedText =
 
147
                                "/p:\"c:\\python\\lib\"\r\n" +
 
148
                                "/p:\"c:\\python\\lib\\lib-tk\"\r\n" +
 
149
                                "/r:\"c:\\temp\\test-results.txt\"\r\n" +
 
150
                                "MyNamespace.MyTestClass.MyTestMethod\r\n";
 
151
                        
 
152
                        Assert.AreEqual(expectedText, responseFileText.ToString());
 
153
                }
 
154
        }
 
155
}