[IronPython] Error only from Test Case
Dino Viehland
dinov at microsoft.com
Thu Oct 23 23:00:20 CEST 2008
Ok, I've opened a work item on CodePlex to track it (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=19128). I should have done that last time :) We'll need to investigate this and see what's going on but I think it'll have to wait until after 2.0 at this point.
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Matt Beckius
Sent: Thursday, October 23, 2008 1:47 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Error only from Test Case
We're NUnit and TypeMock.
On Thu, Oct 23, 2008 at 4:38 PM, Dino Viehland <dinov at microsoft.com<mailto:dinov at microsoft.com>> wrote:
Are you using NUnit or NDepend? There's an issue (that we believe is related to how the assemblies are being loaded) which we haven't tracked down just yet: http://www.mail-archive.com/users@lists.ironpython.com/msg07328.html
Running the same code outside of NUnit or NDepend should work.
From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com>] On Behalf Of Matt Beckius
Sent: Thursday, October 23, 2008 1:30 PM
To: users at lists.ironpython.com<mailto:users at lists.ironpython.com>
Subject: [IronPython] Error only from Test Case
The test below fails (see stacktrace). If I take the exact same code and execute from a running program,it works just fine.
Any suggestions,
TIA
Matt B.
[Test]
public void Statements()
{
var e = new IPEngine();
e.Scope.SetVariable("x","testing");
var script = "import System\nfrom System import *\nx = 'kosher'\nprint 'test'";
e.Execute(script);
Assert.AreEqual("kosher",e.Scope.GetVariable<string>("x"));
}
failed: System.InvalidProgramException : Common Language Runtime detected an invalid program.
at Microsoft.Scripting.Actions.MatchCaller.Call6[T0,T1,T2,T3,T4,T5,TRet](Func`8 target, CallSite site, Object[] args)
at Microsoft.Scripting.Actions.CallSite`1.UpdateAndExecute(Object[] args)
at Microsoft.Scripting.Actions.UpdateDelegates.Update6[T,T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at IronPython.Runtime.Importer.Import(CodeContext context, String fullName, PythonTuple from, Int32 level)
at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
at <module>$1##1(Closure , Scope , LanguageContext )
at Microsoft.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression code, Scope scope)
at Microsoft.Scripting.ScriptCode.Run(Scope scope)
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
public class IPEngine
{
#region Member Vars
private readonly ScriptEngine engine;
private readonly ScriptScope scope;
private MemoryStream ms;
#endregion Member Vars
public IPEngine()
{
engine = Python.CreateEngine();
engine.ImportModule("clr");
engine.Runtime.LoadAssembly(typeof(System.String).Assembly);
scope = Engine.CreateScope();
}
public ScriptEngine Engine
{
get { return engine; }
}
public ScriptScope Scope
{
get { return scope; }
}
public void SetupOutput()
{
ms = new MemoryStream();
engine.Runtime.IO.SetOutput(ms, Encoding.UTF8);
//engine.Runtime.IO.SetErrorOutput(ms, Encoding.UTF8);
}
/// <summary>
/// Evaluates a single expressoin
/// </summary>
/// <typeparam name="T">Return Type</typeparam>
/// <param name="expression">Expressions to Eval</param>
/// <returns>T</returns>
public T Eval<T>(string expression)
{
SetupOutput();
var source = Engine.CreateScriptSourceFromString(expression, SourceCodeKind.Expression);
return source.Execute<T>(Scope);
}
public void Execute(string statements)
{
SetupOutput();
var source = engine.CreateScriptSourceFromString(statements, SourceCodeKind.Statements);
source.Execute(scope);
}
public string Output
{
get
{
using (var sr = new StreamReader(ms))
{
ms.Position = 0;
return sr.ReadToEnd();
}
}
}
}
_______________________________________________
Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081023/ec07f34f/attachment.html>
More information about the Ironpython-users
mailing list