From 62ae5c759ff1867d2a32774f189e0158cd8ec7cc Mon Sep 17 00:00:00 2001 From: Taras Glek Date: Wed, 1 May 2013 14:35:40 -0700 Subject: [PATCH] run tests via our wrapper --- Makefile | 2 +- org/mozilla/jydoop/PythonWrapper.java | 12 ++++++++++-- test.py | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 31e91eb..93f10da 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ TEST_PY=test.py all: driver.jar check: driver.jar - java -cp driver.jar:$(CP) org.python.util.jython $(TEST_PY) + java -cp driver.jar:$(CP) org.mozilla.jydoop.PythonWrapper $(TEST_PY) run: driver.jar java -cp driver.jar:$(CP) org.mozilla.jydoop.$(TASK) diff --git a/org/mozilla/jydoop/PythonWrapper.java b/org/mozilla/jydoop/PythonWrapper.java index 12d4089..52996d9 100644 --- a/org/mozilla/jydoop/PythonWrapper.java +++ b/org/mozilla/jydoop/PythonWrapper.java @@ -9,6 +9,7 @@ import org.python.core.PyType; import java.io.IOException; import java.io.InputStream; import java.io.File; +import java.io.FileInputStream; import java.net.URL; import java.net.JarURLConnection; @@ -48,7 +49,9 @@ public class PythonWrapper { File f; try { - if (url.getProtocol().equals("file")) { + if (url == null) { + f = new File(path); + } else if (url.getProtocol().equals("file")) { f = new File(url.toURI()); } else if (url.getProtocol().equals("jar")) { JarURLConnection j = (JarURLConnection) url.openConnection(); @@ -84,9 +87,14 @@ public class PythonWrapper { // Get the the script path from our loader URL scripturl = this.getClass().getResource("/" + pathname); - InputStream pythonstream = scripturl.openStream(); + InputStream pythonstream = scripturl != null ? scripturl.openStream() : new FileInputStream(pathname); interp.execfile(pythonstream, pathname); } + + public static void main(String args[]) throws IOException { + new PythonWrapper(args[0]); + } + public PyObject getFunction(String name) { return interp.get(name.intern()); } diff --git a/test.py b/test.py index de90c5b..edfd133 100644 --- a/test.py +++ b/test.py @@ -123,4 +123,5 @@ class TestResource(unittest.TestCase): self.assertIsNotNone(jydoop.getResource("scripts/jydoop.py")) if __name__ == '__main__': - unittest.main() + """For some reason sys.exit(0) causes Jython to get angry when run from PythonWrapper""" + unittest.main(exit=False)