@@ -104,4 +104,41 @@ public void testParameters() throws InterruptedException, ExecutionException,
104104 assertEquals (expected , actual );
105105 }
106106
107+ /**
108+ * Tests that variables assigned a primitive long value have the expected
109+ * type.
110+ * <p>
111+ * There is a crazy bug in {@link org.python.jsr223.PyScriptEngine}, which
112+ * results in variables assigned a long primitive to somehow end up as (or
113+ * appearing to end up as) {@link java.math.BigInteger} instances instead. See
114+ * <a href=
115+ * "http://sourceforge.net/p/jython/mailman/jython-users/thread/54370FE9.5010603%40farowl.co.uk/"
116+ * >this thread on the jython-users mailing list</a> for discussion.
117+ * </p>
118+ * <p>
119+ * This test ensures that that specific problem gets flagged if it occurs. As
120+ * long as we keep using our own Jython {@code ScriptEngine} implementation
121+ * (i.e.: {@link org.scijava.plugins.scripting.jython.JythonScriptEngine}),
122+ * the problem does not occur. But if we switch to the stock JSR-223 Jython
123+ * {@code ScriptEngine} (i.e.: {@link org.python.jsr223.PyScriptEngine}), the
124+ * problem manifests. See {@link JythonScriptLanguage#getScriptEngine()}.
125+ * </p>
126+ */
127+ @ Test
128+ public void testLongType () throws InterruptedException , ExecutionException ,
129+ IOException , ScriptException
130+ {
131+ final Context context = new Context (ScriptService .class );
132+ final ScriptService scriptService = context .getService (ScriptService .class );
133+
134+ final String script = "" + //
135+ "# @OUTPUT String varType\n " + //
136+ "a = 10L\n " + //
137+ "varType = type(a)\n " ;
138+ final ScriptModule m = scriptService .run ("longType.py" , script , true ).get ();
139+
140+ final Object actual = m .getOutput ("varType" );
141+ final String expected = "<type 'long'>" ;
142+ assertEquals (expected , actual );
143+ }
107144}
0 commit comments