1 package jep.test; 2 3 import jep.Interpreter; 4 import jep.JepException; 5 import jep.SharedInterpreter; 6 7 /** 8 * Tests ability to execute multiple lines of python using exec() 9 * 10 * Created: August 2019 11 * 12 * @author Ben Steffensmeier 13 */ 14 public class TestExec { 15 main(String[] args)16 public static void main(String[] args) throws JepException { 17 StringBuilder script = new StringBuilder(); 18 script.append("a = 'Passed'\n"); 19 script.append("b = 'Failed'\n"); 20 script.append("result = max(a,b)"); 21 try (Interpreter interp = new SharedInterpreter()) { 22 interp.exec(script.toString()); 23 String result = interp.getValue("result", String.class); 24 if (!"Passed".equals(result)) { 25 throw new IllegalStateException( 26 "multi-line exec returned " + result); 27 } 28 } 29 } 30 31 } 32