Jim Baker avatar Jim Baker committed 7d5369f

Proxy deserialization test

Comments (0)

Files changed (1)

Lib/test/test_java_integration.py

 import copy
+import glob
 import operator
 import os
 import os.path
         return self.output.classQueue.popleft()
 
 
-def find_jython_jar():
-    jython_jar_path = os.path.normpath(os.path.join(sys.executable, "..", "..", "jython.jar"))
-    jython_jar_dev_path = os.path.normpath(os.path.join(sys.executable, "..", "..", "jython-dev.jar"))
-    if os.path.exists(jython_jar_path):
-        return jython_jar_path
-    elif os.path.exists(jython_jar_dev_path):
-        return jython_jar_dev_path
+def find_jython_jars():
+    # Uses the same classpath resolution as bin/jython
+    jython_jar_path = os.path.normpath(os.path.join(sys.executable, "../../jython.jar"))
+    jython_jar_dev_path = os.path.normpath(os.path.join(sys.executable, "../../jython-dev.jar"))
+    if os.path.exists(jython_jar_dev_path):
+        jars = [jython_jar_dev_path]
+        jars.extend(glob.glob(os.path.normpath(os.path.join(jython_jar_dev_path, "../javalib/*.jar"))))
+    elif os.path.exists(jython_jar_path):
+        jars = [jython_jar_path]
     else:
         raise Exception("Cannot find jython jar")
+    return jars
 
 
 class SerializationTest(unittest.TestCase):
         self.assertEqual(names, roundtrip_serialization(names))
 
     def test_proxy_serialization(self):
-        # Verifies that proxies are properly serializable, including being able to "findpython" to get a PySystemState
+        """Proxies can be deserializable in a fresh JVM, including being able to "findPython" to get a PySystemState"""
         tempdir = tempfile.mkdtemp()
         old_proxy_debug_dir = org.python.core.Options.proxyDebugDirectory
         try:
             proxies_jar_path = os.path.join(tempdir, "proxies.jar")
             subprocess.check_call(["jar", "cf", proxies_jar_path, "-C", tempdir, "org/"])
 
-            # Serialize Cat
+            # Serialize our cat
             output = ByteArrayOutputStream()
             serializer = CloneOutput(output)
             serializer.writeObject(cat)
             # ProxyDeserialization, verify we get "meow" printed to
             # stdout, which in turn ensures that PySystemState (and
             # Jython runtime) is initialized for the proxy
-            classpath = ":".join([find_jython_jar(), proxies_jar_path])
-            cmd = [os.path.join(System.getProperty("java.home"), "bin", "java"),
+            jars = find_jython_jars()
+            jars.append(proxies_jar_path)
+            classpath = ":".join(jars)
+            cmd = [os.path.join(System.getProperty("java.home"), "bin/java"),
                    "-classpath", classpath, "ProxyDeserialization", cat_path]
             self.assertEqual(subprocess.check_output(cmd), "meow\n")
         finally:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.