Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix and regression test bug when loading data resources in initialize…

…r of acrive mode sketch
  • Loading branch information...
commit 8e5f96bcb2a11b456f8928a01d8af0db75b38414 1 parent 8e21aa9
@jdf authored
View
2  .classpath
@@ -5,7 +5,7 @@
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/jython/jython.jar"/>
- <classpathentry kind="lib" path="lib/processing/core.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
2  examples.py/Library/PDF Export/OneFrame/OneFrame.py
@@ -6,7 +6,7 @@
* on the display window and is saved to the file.
"""
-from processing.pdf import *
+#from processing.pdf import *
size(600, 600)
View
16 src/jycessing/PAppletJythonDriver.java
@@ -15,6 +15,7 @@
*/
package jycessing;
+import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.regex.Pattern;
@@ -61,9 +62,9 @@
// These are all of the methods that PApplet might call in your sketch. If
// you have implemented a method, we save it and call it.
- private final PyObject setupMeth, drawMeth, mousePressedMeth, mouseClickedMeth,
- mouseReleasedMeth, mouseDraggedMeth, keyPressedMeth, keyReleasedMeth,
- keyTypedMeth, stopMeth;
+ private final PyObject setupMeth, drawMeth, mousePressedMeth,
+ mouseClickedMeth, mouseReleasedMeth, mouseDraggedMeth,
+ keyPressedMeth, keyReleasedMeth, keyTypedMeth, stopMeth;
// Adapted from Jython's PythonInterpreter.java exec(String s) to preserve
// the source file name, so that errors have the file name instead of
@@ -75,10 +76,11 @@ private void interpretSketch() {
Py.flushLine();
}
- public PAppletJythonDriver(final InteractiveConsole interp, final String sketchPath,
- final String programText) {
+ public PAppletJythonDriver(final InteractiveConsole interp,
+ final String sketchPath, final String programText) {
this.programText = programText;
this.pySketchPath = sketchPath;
+ this.sketchPath = new File(sketchPath).getParent();
this.isStaticMode = !ACTIVE_METHOD_DEF.matcher(programText).find();
this.builtins = (PyStringMap) interp.getSystemState().getBuiltins();
this.interp = interp;
@@ -130,8 +132,8 @@ public static void initializeStatics(final PyStringMap builtins) {
* sketch's world, particularly width and height.
*/
@Override
- public void size(final int iwidth, final int iheight, final String irenderer,
- final String ipath) {
+ public void size(final int iwidth, final int iheight,
+ final String irenderer, final String ipath) {
super.size(iwidth, iheight, irenderer, ipath);
setFields();
}
View
17 src/jycessing/Runner.java
@@ -73,7 +73,8 @@ private static void addJar(final URL url) throws Exception {
return;
}
}
- final Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+ final Method method = URLClassLoader.class.getDeclaredMethod("addURL",
+ URL.class);
method.setAccessible(true);
method.invoke(classLoader, new Object[] { url });
if (VERBOSE) {
@@ -143,15 +144,20 @@ public boolean accept(final File f) {
public static void main(final String[] args) throws Exception {
if (args.length < 1) {
- System.err.println("I need the path of your Python script as an argument.");
+ System.err
+ .println("I need the path of your Python script as an argument.");
}
// -Dverbose=true for some logging
VERBOSE = Boolean.getBoolean("verbose");
final Properties buildnum = new Properties();
- buildnum.load(Runner.class.getResourceAsStream("buildnumber.properties"));
- System.err.println("processing.py build " + buildnum.getProperty("buildnumber"));
+ buildnum.load(Runner.class
+ .getResourceAsStream("buildnumber.properties"));
+ if (VERBOSE) {
+ System.err.println("processing.py build "
+ + buildnum.getProperty("buildnumber"));
+ }
// The last argument is the path to the Python sketch
final String sketchPath = args[args.length - 1];
@@ -178,7 +184,8 @@ public static void runSketch(final String[] args, final String sketchPath,
interp.setOut(System.out);
// Where is the sketch located?
- final String sketchDir = new File(sketchPath).getCanonicalFile().getParent();
+ final String sketchDir = new File(sketchPath).getCanonicalFile()
+ .getParent();
// Tell PApplet to make its home there, so that it can find the data
// folder
View
BIN  test_resources/data/Cabal1-48.vlw
Binary file not shown
View
14 test_resources/test_load_in_initializer.py
@@ -0,0 +1,14 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+__author__="max.franks"
+
+font = loadFont("Cabal1-48.vlw")
+
+def setup():
+ size(800, 800, P3D)
+ noLoop();
+
+def draw():
+ background(0)
+ print "OK"
View
12 tests/test/jycessing/JycessingTests.java
@@ -17,9 +17,10 @@ private static String run(final String testResource) throws Exception {
final PrintStream saved = System.out;
try {
System.setOut(new PrintStream(baos, true));
- Runner.main(new String[] { "test_resources/test_" + testResource + ".py" });
- return new String(baos.toByteArray()).replaceAll("\r\n", "\n").replaceAll(
- "\r", "\n");
+ Runner.main(new String[] { "test_resources/test_" + testResource
+ + ".py" });
+ return new String(baos.toByteArray()).replaceAll("\r\n", "\n")
+ .replaceAll("\r", "\n");
} finally {
System.setOut(saved);
}
@@ -55,6 +56,11 @@ public void urllib() throws Exception {
assertEquals("OK\n", run("urllib"));
}
+ @Test
+ public void load_in_initializer() throws Exception {
+ assertEquals("OK\n", run("load_in_initializer"));
+ }
+
public static void main(final String[] args) {
JUnitCore.runClasses(JycessingTests.class);
}
Please sign in to comment.
Something went wrong with that request. Please try again.