Ejemplo n.º 1
0
        public void Execute_SwitchesAndReleasesScriptContextIfScriptExecutionThrows()
        {
            Assert.That(ScriptContext.Current, Is.Null);

            const string scriptText = @"
import clr
clr.AddReferenceByPartialName('Remotion.Scripting')
from Remotion.Scripting import *
def Test() :
  raise Exception('IntentionallyRaisedIronPythonException') 
";

            ScriptContext scriptContextForScript = ScriptContextObjectMother.CreateTestScriptContext("Execute_SwitchesAndReleasesScriptContextIfScriptExecutionThrows");
            var           scriptEnvironment      = ScriptEnvironment.Create();
            var           script = new ScriptFunction <Object> (scriptContextForScript, ScriptLanguageType.Python, scriptText, scriptEnvironment, "Test");

            try
            {
                script.Execute();
            }
            catch (Exception e)
            {
                Assert.That(e.Message, Is.EqualTo("IntentionallyRaisedIronPythonException"));
            }

            Assert.That(ScriptContext.Current, Is.Null);
        }
Ejemplo n.º 2
0
        public void Ctor_NumberTemplateArguments_9()
        {
            const string scriptText =
                @"def Test(s1,s2,s3,s4,s5,s6,s7,s8,s9) :
  return 'Test: '+s1+s2+s3+s4+s5+s6+s7+s8+s9";

            var scriptEnvironment = ScriptEnvironment.Create();
            var script            = new ScriptFunction <string, string, string, string, string, string, string, string, string, string> (
                ScriptContextObjectMother.CreateTestScriptContext(), ScriptLanguageType.Python, scriptText, scriptEnvironment, "Test");

            Assert.That(script.Execute("1", "2", "3", "4", "5", "6", "7", "8", "9"), Is.EqualTo("Test: 123456789"));
        }
Ejemplo n.º 3
0
        public void Ctor_NumberTemplateArguments_2()
        {
            const string scriptText =
                @"def Test(s0,s1) :
  return 'Test: ' + s0 + ' ' + s1";

            var scriptEnvironment = ScriptEnvironment.Create();
            var script            = new ScriptFunction <string, string, string> (ScriptContextObjectMother.CreateTestScriptContext(),
                                                                                 ScriptLanguageType.Python, scriptText, scriptEnvironment, "Test");

            Assert.That(script.Execute("really", "works"), Is.EqualTo("Test: really works"));
        }
Ejemplo n.º 4
0
        public void Ctor_NumberTemplateArguments_1()
        {
            const string scriptText =
                @"def Test(s) :
  return 'Test: ' + s";

            //ScriptScope scriptScope = ScriptingHelper.CreateScriptScope (ScriptLanguageType.Python);
            var scriptScope = ScriptEnvironment.Create();
            var script      = new ScriptFunction <string, string> (ScriptContextObjectMother.CreateTestScriptContext(), ScriptLanguageType.Python, scriptText, scriptScope, "Test");

            Assert.That(script.Execute("works"), Is.EqualTo("Test: works"));
        }
        public void NotImportClr()
        {
            var          scriptEnvironment = ScriptEnvironment.Create();
            const string scriptText        = "'ABcd'.Substring(1,2)";
            var          expressionScript  =
                new ExpressionScript <string> (
                    ScriptContextObjectMother.CreateTestScriptContext("NotImportClr"),
                    ScriptLanguageType.Python,
                    scriptText,
                    scriptEnvironment);

            expressionScript.Execute();
        }
        public void ImportIifHelperFunctions_LazyIIf()
        {
            var scriptEnvironment = ScriptEnvironment.Create();

            scriptEnvironment.ImportIifHelperFunctions();
            scriptEnvironment.SetVariable("x", 100000);
            const string scriptText       = "LazyIIf(x > 1000,lambda:'big',lambda:NonExistingSymbol)";
            var          expressionScript =
                new ExpressionScript <string> (ScriptContextObjectMother.CreateTestScriptContext("ImportIifHelperFunctions"), ScriptLanguageType.Python,
                                               scriptText, scriptEnvironment);

            Assert.That(expressionScript.Execute(), Is.EqualTo("big"));
        }
        public void Execute()
        {
            const string scriptText = "'Document Name: ' + rmDoc.Name";

            var scriptEnvironment = ScriptEnvironment.Create();
            var document          = new Document("Test Doc");

            scriptEnvironment.SetVariable("rmDoc", document);

            var script = new ExpressionScript <string> (ScriptContextObjectMother.CreateTestScriptContext(),
                                                        ScriptLanguageType.Python, scriptText, scriptEnvironment);

            Assert.That(script.Execute(), Is.EqualTo("Document Name: Test Doc"));
        }
        public void ImportClr()
        {
            var scriptEnvironment = ScriptEnvironment.Create();

            scriptEnvironment.ImportClr();

            const string scriptText       = "'ABcd'.Substring(1,2)";
            var          expressionScript = new ExpressionScript <string> (
                ScriptContextObjectMother.CreateTestScriptContext("ImportClr"),
                ScriptLanguageType.Python,
                scriptText,
                scriptEnvironment);

            Assert.That(expressionScript.Execute(), Is.EqualTo("Bc"));
        }
        public void Ctor()
        {
            ScriptContext            scriptContext      = ScriptContextObjectMother.CreateTestScriptContext();
            const ScriptLanguageType scriptLanguageType = ScriptLanguageType.Python;

            const string scriptText = "'ExpressionScriptCtorTest'";

            var scriptEnvironment = ScriptEnvironment.Create();
            var script            = new ExpressionScript <string> (scriptContext, scriptLanguageType, scriptText, scriptEnvironment);

            Assert.That(script.ScriptContext, Is.EqualTo(scriptContext));
            Assert.That(script.ScriptLanguageType, Is.EqualTo(scriptLanguageType));
            Assert.That(script.ScriptText, Is.EqualTo(scriptText));
            Assert.That(script.Execute(), Is.EqualTo("ExpressionScriptCtorTest"));
        }
        public void Execute_ImportedTypeIntoScriptScope()
        {
            const string scriptText = "Document('New ' + rmDoc.Name)";

            var scriptEnvironment = ScriptEnvironment.Create();

            scriptEnvironment.Import("Remotion.Scripting.UnitTests", "Remotion.Scripting.UnitTests.TestDomain", "Document");
            var document = new Document("Test Doc");

            scriptEnvironment.SetVariable("rmDoc", document);

            var script = new ExpressionScript <Document> (ScriptContextObjectMother.CreateTestScriptContext(),
                                                          ScriptLanguageType.Python, scriptText, scriptEnvironment);
            var result = script.Execute();

            Assert.That(result.Name, Is.EqualTo("New Test Doc"));
        }
Ejemplo n.º 11
0
        public void ScriptExecute_ImportMultipleIntoScriptScope()
        {
            const string scriptText = @"
import clr
clr.AddReferenceByPartialName('Remotion.Scripting.UnitTests')
from Remotion.Scripting.UnitTests import *
def Test() :
  return TestDomain.Document('Knows Document')
";

            ScriptContext scriptContextForScript = ScriptContextObjectMother.CreateTestScriptContext("Execute_ImportIntoScriptScope");
            var           scriptEnvironment      = ScriptEnvironment.Create();
            var           script         = new ScriptFunction <Document> (scriptContextForScript, ScriptLanguageType.Python, scriptText, scriptEnvironment, "Test");
            Document      resultDocument = script.Execute();

            Assert.That(resultDocument.Name, Is.EqualTo("Knows Document"));
        }
        public void Execute_SwitchesAndReleasesScriptContext()
        {
            Assert.That(ScriptContext.Current, Is.Null);

            const string scriptText =
                "ScriptContext.Current";

            ScriptContext scriptContextForScript = ScriptContextObjectMother.CreateTestScriptContext("Execute_SwitchesScriptContext_Script");
            var           scriptEnvironment      = ScriptEnvironment.Create();

            scriptEnvironment.Import("Remotion.Scripting", "Remotion.Scripting", "ScriptContext");
            var script = new ExpressionScript <ScriptContext> (scriptContextForScript, ScriptLanguageType.Python,
                                                               scriptText, scriptEnvironment);

            Assert.That(script.Execute(), Is.SameAs(scriptContextForScript));

            Assert.That(ScriptContext.Current, Is.Null);
        }
Ejemplo n.º 13
0
        public void Ctor()
        {
            ScriptContext            scriptContext      = ScriptContextObjectMother.CreateTestScriptContext();
            const ScriptLanguageType scriptLanguageType = ScriptLanguageType.Python;
            const string             scriptFunctionName = "Test";

            const string scriptText =
                @"def Test() :
  return 'CtorTest'";

            var scriptEnvironment = ScriptEnvironment.Create();

            var script = new ScriptFunction <string> (scriptContext, scriptLanguageType, scriptText, scriptEnvironment, scriptFunctionName);

            Assert.That(script.ScriptContext, Is.EqualTo(scriptContext));
            Assert.That(script.ScriptLanguageType, Is.EqualTo(scriptLanguageType));
            Assert.That(script.ScriptText, Is.EqualTo(scriptText));
            Assert.That(script.Execute(), Is.EqualTo("CtorTest"));
        }
Ejemplo n.º 14
0
        public void Execute_SwitchesAndReleasesScriptContext()
        {
            Assert.That(ScriptContext.Current, Is.Null);

            const string scriptText = @"
import clr
clr.AddReferenceByPartialName('Remotion.Scripting')
from Remotion.Scripting import *
def Test() :
  return ScriptContext.Current
";

            ScriptContext scriptContextForScript = ScriptContextObjectMother.CreateTestScriptContext("Execute_SwitchesScriptContext_Script");
            var           scriptEnvironment      = ScriptEnvironment.Create();
            var           script = new ScriptFunction <ScriptContext> (scriptContextForScript, ScriptLanguageType.Python, scriptText, scriptEnvironment, "Test");

            Assert.That(script.Execute(), Is.SameAs(scriptContextForScript));

            Assert.That(ScriptContext.Current, Is.Null);
        }
        public void Execute_SwitchesAndReleasesScriptContextIfScriptExecutionThrows()
        {
            Assert.That(ScriptContext.Current, Is.Null);

            const string scriptText =
                "RaiseCommandNotSupportedInIronPythonExpressioSoUsingUnkownSymbol";

            ScriptContext scriptContextForScript = ScriptContextObjectMother.CreateTestScriptContext("Execute_SwitchesAndReleasesScriptContextIfScriptExecutionThrows");
            var           scriptEnvironment      = ScriptEnvironment.Create();
            var           script = new ExpressionScript <ScriptContext> (scriptContextForScript, ScriptLanguageType.Python,
                                                                         scriptText, scriptEnvironment);

            try
            {
                script.Execute();
            }
            catch (Exception e)
            {
                Assert.That(e.Message, Is.EqualTo("name 'RaiseCommandNotSupportedInIronPythonExpressioSoUsingUnkownSymbol' is not defined"));
            }

            Assert.That(ScriptContext.Current, Is.Null);
        }