public void UnallowedCodeTest1()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var studentCode = @"import os";
     var output = util.Execute(studentCode);
     Assert.AreEqual(output, "Code not permitted: os");
 }
 public void FutureTest()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var output = util.Execute(@"x = 3/2
     print(x)");
     Assert.AreEqual(output, "1.5\r\n");
 }
        public void ReturnTest()
        {
            PyInterpretUtility util = new PyInterpretUtility();
            var output = util.Execute(@"def myFunction(number):
            print(number)

            def professorFunction(num):
            myFunction(num)

            professorFunction(3)    "
            );
            Assert.AreEqual(output, "3\r\n");
        }
        public void EncapsulatedTest()
        {
            PyInterpretUtility util = new PyInterpretUtility();
            var output = util.Execute(@"def encap():
            def myFunction(number):
            print(number)

            def professorFunction():
            myFunction(3)

            professorFunction()

            encap()"
            );
            Assert.AreEqual(output, "3\r\n");
        }
Example #5
0
 public string ExecutePythonCode(string code)
 {
     var py = new Modules.PyInterpret.PyInterpretUtility();
     return py.Execute(code);
 }
 public void PrintTest()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var output = util.Execute("print(\"TESTVALUE\")");
     Assert.AreEqual(output, "TESTVALUE\r\n");
 }
 public void UnallowedCodeTest5()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var studentCode = @"eval(etc)";
     var output = util.Execute(studentCode);
     Assert.AreEqual(output, "Code not permitted: eval");
 }