Index: src/org/python/core/PyFloat.java =================================================================== --- src/org/python/core/PyFloat.java (revision 7097) +++ src/org/python/core/PyFloat.java (working copy) @@ -82,7 +82,7 @@ * Determine if this float is not infinity, nor NaN. */ public boolean isFinite() { - return !Double.isInfinite(value) && !Double.isNaN(value); + return !Double.isInfinite(getValue()) && !Double.isNaN(getValue()); } @Override Index: src/org/python/core/PyLong.java =================================================================== --- src/org/python/core/PyLong.java (revision 7097) +++ src/org/python/core/PyLong.java (working copy) @@ -151,7 +151,7 @@ @Override public boolean __nonzero__() { - return !value.equals(BigInteger.valueOf(0)); + return !getValue().equals(BigInteger.ZERO); } @ExposedMethod(doc = BuiltinDocs.long___nonzero___doc) Index: tests/java/org/python/core/WrappedBooleanTest.java =================================================================== --- tests/java/org/python/core/WrappedBooleanTest.java (revision 0) +++ tests/java/org/python/core/WrappedBooleanTest.java (revision 0) @@ -0,0 +1,59 @@ +package org.python.core; + +import junit.framework.TestCase; + +import org.python.util.PythonInterpreter; + +public class WrappedBooleanTest extends TestCase { + + // Simulate the use case where you want to expose some (possibly mutable) + // java boolean field to an interpreter without having to set the value to a + // new PyBoolean each time it changes. + @SuppressWarnings("serial") + static class WrappedBoolean extends PyBoolean { + public WrappedBoolean() { + super(true); + } + + private boolean mutableValue; + + @Override + public boolean getBooleanValue() { + return mutableValue; + } + + public void setMutableValue(final boolean newValue) { + mutableValue = newValue; + } + } + + private PythonInterpreter interp; + private WrappedBoolean a, b; + + @Override + protected void setUp() throws Exception { + interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); + a = new WrappedBoolean(); + b = new WrappedBoolean(); + a.setMutableValue(true); + b.setMutableValue(false); + interp.set("a", a); + interp.set("b", b); + } + + public void testAnd() { + interp.exec("c = a and b"); + assertEquals(new PyBoolean(false), interp.get("c")); + b.setMutableValue(true); + interp.exec("c = a and b"); + assertEquals(new PyBoolean(true), interp.get("c")); + } + + public void testOr() { + interp.exec("c = a or b"); + assertEquals(new PyBoolean(true), interp.get("c")); + a.setMutableValue(false); + interp.exec("c = a or b"); + assertEquals(new PyBoolean(false), interp.get("c")); + } +} Index: tests/java/org/python/core/WrappedFloatTest.java =================================================================== --- tests/java/org/python/core/WrappedFloatTest.java (revision 0) +++ tests/java/org/python/core/WrappedFloatTest.java (revision 0) @@ -0,0 +1,61 @@ +package org.python.core; + +import junit.framework.TestCase; + +import org.python.util.PythonInterpreter; + +public class WrappedFloatTest extends TestCase { + + // Simulate the use case where you want to expose some (possibly mutable) + // java float field to an interpreter without having to set the value to a new + // PyFloat each time it changes. + @SuppressWarnings("serial") + static class WrappedFloat extends PyFloat { + public WrappedFloat() { + super(0); + } + + private double mutableValue; + + @Override + public double getValue() { + return mutableValue; + } + + public void setMutableValue(final double newValue) { + mutableValue = newValue; + } + } + + private PythonInterpreter interp; + private WrappedFloat a, b; + + @Override + protected void setUp() throws Exception { + interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); + a = new WrappedFloat(); + b = new WrappedFloat(); + a.setMutableValue(13.0); + b.setMutableValue(17.0); + interp.set("a", a); + interp.set("b", b); + } + + public void testAdd() { + interp.exec("c = a + b"); + assertEquals(new PyFloat(30), interp.get("c")); + b.setMutableValue(18.0); + interp.exec("c = a + b"); + assertEquals(new PyFloat(31), interp.get("c")); + } + + public void testDiv() { + interp.exec("c = a / b"); + assertEquals(new PyFloat(13 / 17.), interp.get("c")); + } + + public void testMod() { + interp.exec("c = b % a"); + assertEquals(new PyFloat(4), interp.get("c")); + } +} Index: tests/java/org/python/core/WrappedIntegerTest.java =================================================================== --- tests/java/org/python/core/WrappedIntegerTest.java (revision 0) +++ tests/java/org/python/core/WrappedIntegerTest.java (revision 0) @@ -0,0 +1,61 @@ +package org.python.core; + +import junit.framework.TestCase; + +import org.python.util.PythonInterpreter; + +public class WrappedIntegerTest extends TestCase { + + // Simulate the use case where you want to expose some (possibly mutable) + // java int field to an interpreter without having to set the value to a new + // PyInteger each time it changes. + @SuppressWarnings("serial") + static class WrappedInteger extends PyInteger { + public WrappedInteger() { + super(0); + } + + private int mutableValue; + + @Override + public int getValue() { + return mutableValue; + } + + public void setMutableValue(final int newValue) { + mutableValue = newValue; + } + } + + private PythonInterpreter interp; + private WrappedInteger a, b; + + @Override + protected void setUp() throws Exception { + interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); + a = new WrappedInteger(); + b = new WrappedInteger(); + a.setMutableValue(13); + b.setMutableValue(17); + interp.set("a", a); + interp.set("b", b); + } + + public void testAdd() { + interp.exec("c = a + b"); + assertEquals(new PyInteger(30), interp.get("c")); + b.setMutableValue(18); + interp.exec("c = a + b"); + assertEquals(new PyInteger(31), interp.get("c")); + } + + public void testDiv() { + interp.exec("c = a / float(b)"); + assertEquals(new PyFloat(13 / 17.), interp.get("c")); + } + + public void testMod() { + interp.exec("c = b % a"); + assertEquals(new PyInteger(4), interp.get("c")); + } +} Index: tests/java/org/python/core/WrappedLongTest.java =================================================================== --- tests/java/org/python/core/WrappedLongTest.java (revision 0) +++ tests/java/org/python/core/WrappedLongTest.java (revision 0) @@ -0,0 +1,58 @@ +package org.python.core; + +import java.math.BigInteger; + +import junit.framework.TestCase; + +import org.python.util.PythonInterpreter; + +public class WrappedLongTest extends TestCase { + + // Simulate the use case where you want to expose some (possibly mutable) + // java long field to an interpreter without having to set the value to a + // new PyLong each time it changes. + @SuppressWarnings("serial") + static class WrappedLong extends PyLong { + public WrappedLong() { + super(0); + } + + private long mutableValue; + + @Override + public BigInteger getValue() { + return BigInteger.valueOf(mutableValue); + } + + public void setMutableValue(final long newValue) { + mutableValue = newValue; + } + } + + private PythonInterpreter interp; + private WrappedLong a, b; + + @Override + protected void setUp() throws Exception { + interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); + a = new WrappedLong(); + b = new WrappedLong(); + a.setMutableValue(13000000000L); + b.setMutableValue(17000000000L); + interp.set("a", a); + interp.set("b", b); + } + + public void testAdd() { + interp.exec("c = a + b"); + assertEquals(new PyLong(30000000000L), interp.get("c")); + b.setMutableValue(18000000000L); + interp.exec("c = a + b"); + assertEquals(new PyLong(31000000000L), interp.get("c")); + } + + public void testMod() { + interp.exec("c = b % a"); + assertEquals(new PyLong(4000000000L), interp.get("c")); + } +}