[Pydev-cvs] org.python.pydev.debug/tests/org/python/pydev/debug/codecoverage XmlRpcTest.java, 1.1,
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-03-30 21:45:15
|
Update of /cvsroot/pydev/org.python.pydev.debug/tests/org/python/pydev/debug/codecoverage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28985/tests/org/python/pydev/debug/codecoverage Modified Files: XmlRpcTest.java Log Message: - up/down should select content in history based on what's already in the console - stdout/stderr gotten from the server without using sockets - sys.exit may halt shell - shell still seems open after 'killing' eclipse. Index: XmlRpcTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/tests/org/python/pydev/debug/codecoverage/XmlRpcTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XmlRpcTest.java 18 Mar 2008 02:55:03 -0000 1.1 --- XmlRpcTest.java 30 Mar 2008 21:45:18 -0000 1.2 *************** *** 4,19 **** import java.io.IOException; import java.net.MalformedURLException; - import java.net.URL; import junit.framework.TestCase; import org.apache.xmlrpc.XmlRpcException; ! import org.apache.xmlrpc.client.XmlRpcClient; ! import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; import org.python.pydev.core.REF; import org.python.pydev.core.TestDependent; import org.python.pydev.core.docutils.StringUtils; import org.python.pydev.plugin.SocketUtil; import org.python.pydev.runners.SimplePythonRunner; public class XmlRpcTest extends TestCase{ --- 4,25 ---- import java.io.IOException; import java.net.MalformedURLException; import junit.framework.TestCase; import org.apache.xmlrpc.XmlRpcException; ! import org.apache.xmlrpc.XmlRpcHandler; ! import org.apache.xmlrpc.XmlRpcRequest; ! import org.apache.xmlrpc.server.XmlRpcHandlerMapping; ! import org.apache.xmlrpc.server.XmlRpcNoSuchHandlerException; ! import org.apache.xmlrpc.server.XmlRpcServer; ! import org.apache.xmlrpc.webserver.WebServer; import org.python.pydev.core.REF; import org.python.pydev.core.TestDependent; import org.python.pydev.core.docutils.StringUtils; + import org.python.pydev.debug.newconsole.IPydevXmlRpcClient; + import org.python.pydev.debug.newconsole.PydevXmlRpcClient; import org.python.pydev.plugin.SocketUtil; import org.python.pydev.runners.SimplePythonRunner; + import org.python.pydev.runners.ThreadStreamReader; public class XmlRpcTest extends TestCase{ *************** *** 39,56 **** "false", "false", "start get completions", "foo", "3|4", "end get completions", "start raw_input", "false", - "true", "finish raw_input", "'foo'", "false", "false", }; private int next = -1; public static void main(String[] args) throws MalformedURLException, XmlRpcException { --- 45,75 ---- "false", "false", + + "false", + "false", "start get completions", + "Foo", + "1", "foo", "3|4", "end get completions", "start raw_input", + "'input_request'", + "false", "false", "finish raw_input", "'foo'", "false", "false", + "Console already exited with value: 0 while waiting for an answer.|exceptions.SystemExit:0", }; private int next = -1; + + private ThreadStreamReader err; + + private ThreadStreamReader out; + + private WebServer webServer; public static void main(String[] args) throws MalformedURLException, XmlRpcException { *************** *** 58,62 **** } ! private Process startServer(int port, boolean python) throws IOException { File f = new File(TestDependent.TEST_PYDEV_PLUGIN_LOC+"pysrc/pydevconsole.py"); --- 77,88 ---- } ! @Override ! protected void tearDown() throws Exception { ! if(this.webServer != null){ ! this.webServer.shutdown(); ! } ! } ! ! private Process startServer(int client_port, int port, boolean python) throws IOException { File f = new File(TestDependent.TEST_PYDEV_PLUGIN_LOC+"pysrc/pydevconsole.py"); *************** *** 64,77 **** if(python){ cmdLine = SimplePythonRunner.getCommandLineAsString( ! new String[]{TestDependent.PYTHON_EXE, "-u", REF.getFileAbsolutePath(f), ""+port}); }else{ cmdLine = SimplePythonRunner.getCommandLineAsString( new String[]{TestDependent.JAVA_LOCATION, "-classpath", TestDependent.JYTHON_JAR_LOCATION, "org.python.util.jython", ! REF.getFileAbsolutePath(f), ""+port}); } Process process = Runtime.getRuntime().exec(cmdLine); ! process.getErrorStream().close(); return process; } --- 90,121 ---- if(python){ cmdLine = SimplePythonRunner.getCommandLineAsString( ! new String[]{TestDependent.PYTHON_EXE, "-u", REF.getFileAbsolutePath(f), ""+port, ""+client_port}); }else{ cmdLine = SimplePythonRunner.getCommandLineAsString( new String[]{TestDependent.JAVA_LOCATION, "-classpath", TestDependent.JYTHON_JAR_LOCATION, "org.python.util.jython", ! REF.getFileAbsolutePath(f), ""+port, ""+client_port}); } Process process = Runtime.getRuntime().exec(cmdLine); ! err = new ThreadStreamReader(process.getErrorStream()); ! out = new ThreadStreamReader(process.getInputStream()); ! err.start(); ! out.start(); ! ! ! this.webServer = new WebServer(client_port); ! XmlRpcServer serverToHandleRawInput = this.webServer.getXmlRpcServer(); ! serverToHandleRawInput.setHandlerMapping(new XmlRpcHandlerMapping(){ ! ! public XmlRpcHandler getHandler(String handlerName) throws XmlRpcNoSuchHandlerException, XmlRpcException { ! return new XmlRpcHandler(){ ! ! public Object execute(XmlRpcRequest request) throws XmlRpcException { ! return "input_request"; ! }}; ! }}); ! ! this.webServer.start(); return process; } *************** *** 87,100 **** public void checkServer(boolean python) throws XmlRpcException, IOException, InterruptedException { int port = SocketUtil.findUnusedLocalPort(); ! Process process = startServer(port, python); //give some time for the process to start if(!python){ synchronized (this) { ! this.wait(2000); } }else{ synchronized (this) { ! this.wait(1000); } } --- 131,149 ---- public void checkServer(boolean python) throws XmlRpcException, IOException, InterruptedException { int port = SocketUtil.findUnusedLocalPort(); ! int client_port = SocketUtil.findUnusedLocalPort(); ! Process process = startServer(client_port, port, python); ! ! ! // int port = 8000; ! // Process process = null; //give some time for the process to start if(!python){ synchronized (this) { ! this.wait(1500); } }else{ synchronized (this) { ! this.wait(500); } } *************** *** 102,133 **** try { ! XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); ! config.setServerURL(new URL("http://127.0.0.1:"+port)); ! XmlRpcClient client = new XmlRpcClient(); ! client.setConfig(config); ! print(client.execute("addExec", new Object[]{"abc = 10"})); ! print(client.execute("addExec", new Object[]{"abc"})); ! print(client.execute("addExec", new Object[]{"import sys"})); ! print(client.execute("addExec", new Object[]{"class Foo:"})); ! print(client.execute("addExec", new Object[]{" print 20"})); ! print(client.execute("addExec", new Object[]{" print >> sys.stderr, 30"})); ! print(client.execute("addExec", new Object[]{""})); ! print(client.execute("addExec", new Object[]{"foo=Foo()"})); ! // print(client.execute("addExec", new Object[]{"foo.__doc__=None"})); ! print("start get completions"); ! print(client.execute("getCompletions", new Object[]{"fo"})); ! print("end get completions"); ! print("start raw_input"); ! print(client.execute("addExec", new Object[]{"raw_input()"})); ! print("finish raw_input"); ! print(client.execute("addExec", new Object[]{"foo"})); } finally { ! process.destroy(); } assertEquals(next, EXPECTED.length-1); } private void print(Object execute) { if(execute instanceof Object[]){ --- 151,205 ---- try { ! ThreadStreamReader stdErr = new ThreadStreamReader(process.getErrorStream()); ! stdErr.start(); ! IPydevXmlRpcClient client = new PydevXmlRpcClient(process, stdErr); ! client.setPort(port); ! printArr(client.execute("addExec", new Object[]{"abc = 10"})); ! printArr(client.execute("addExec", new Object[]{"abc"})); ! printArr(client.execute("addExec", new Object[]{"import sys"})); ! printArr(client.execute("addExec", new Object[]{"class Foo:"})); ! printArr(client.execute("addExec", new Object[]{" print 20"})); ! printArr(client.execute("addExec", new Object[]{" print >> sys.stderr, 30"})); ! printArr(client.execute("addExec", new Object[]{""})); ! printArr(client.execute("addExec", new Object[]{"foo=Foo()"})); ! printArr(client.execute("addExec", new Object[]{"foo.__doc__=None"})); ! printArr("start get completions"); ! Object[] completions = (Object[]) client.execute("getCompletions", new Object[]{"fo"}); ! //the completions may come in any order ! if(!((Object[])completions[0])[0].toString().equals("Foo")){ ! Object object = completions[1]; ! completions[1] = completions[0]; ! completions[0] = object; ! } ! printArr(completions); ! printArr("end get completions"); ! printArr("start raw_input"); ! printArr(client.execute("addExec", new Object[]{"raw_input()"})); ! printArr("finish raw_input"); ! printArr(client.execute("addExec", new Object[]{"'foo'"})); ! // System.out.println("Ask exit"); ! printArr(client.execute("addExec", new Object[]{"sys.exit(0)"})); ! // System.out.println("End Ask exit"); } finally { ! if(process != null){ ! process.destroy(); ! } } assertEquals(next, EXPECTED.length-1); } + private void printArr(Object ... execute) { + if(this.out != null){ + print(this.out.getAndClearContents()); + print(this.err.getAndClearContents()); + } + + for(Object o:execute){ + print(o); + } + } + private void print(Object execute) { if(execute instanceof Object[]){ *************** *** 154,160 **** } } String errorMessage = StringUtils.format("Expected: >>%s<< and not: >>%s<< (position:%s)", expected, found, next); ! assertEquals(errorMessage, found, expected); } } --- 226,238 ---- } } + if(expected.equals("Console already exited with value: 0 while waiting for an answer.|exceptions.SystemExit:0")){ + if(found.equals("Console already exited with value: 0 while waiting for an answer.") || + found.equals("exceptions.SystemExit:0")){ + return; + } + } String errorMessage = StringUtils.format("Expected: >>%s<< and not: >>%s<< (position:%s)", expected, found, next); ! assertEquals(errorMessage, expected, found); } } |