[Jython-checkins] jython (merge 2.5 -> default): merge w/ 2.5

philip.jenvey jython-checkins at python.org
Fri Dec 16 01:20:30 CET 2011


http://hg.python.org/jython/rev/825546a4600e
changeset:   6290:825546a4600e
parent:      6287:0db163c83774
parent:      6289:68626d94a76d
user:        Philip Jenvey <pjenvey at underboss.org>
date:        Thu Dec 15 16:19:46 2011 -0800
summary:
  merge w/ 2.5

files:
  Lib/test/test_chdir.py          |   7 ++-
  Lib/test/test_long_jy.py        |  34 +++++++++++++++++++++
  NEWS                            |   1 +
  src/org/python/core/PyLong.java |  13 +++++--
  4 files changed, 48 insertions(+), 7 deletions(-)


diff --git a/Lib/test/test_chdir.py b/Lib/test/test_chdir.py
--- a/Lib/test/test_chdir.py
+++ b/Lib/test/test_chdir.py
@@ -582,13 +582,14 @@
     def test_symlink_src_is_relative(self):
         write(self.src, 'foo')
         # Ensure that linking to os.path.basename(self.src) creates a
-        # dead link (since it lives in a different dir)
+        # dead link (as self.src lives in a different dir than
+        # self.link)
         os.symlink(self.relsrc, self.link)
         # If the cwd (self.dir1) was applied to os.link's src arg then
         # the link would not be dead
-        self.assertTrue(self.is_dead_link(self.link))
+        self.assertTrue(self.isdeadlink(self.link))
 
-    def is_dead_link(self, link):
+    def isdeadlink(self, link):
         return os.path.lexists(link) and not os.path.exists(link)
 
 
diff --git a/Lib/test/test_long_jy.py b/Lib/test/test_long_jy.py
new file mode 100644
--- /dev/null
+++ b/Lib/test/test_long_jy.py
@@ -0,0 +1,34 @@
+"""Misc long tests
+
+Made for Jython.
+"""
+from test import test_support
+import unittest
+
+class MyLong(long):
+    pass
+
+
+class LongTestCase(unittest.TestCase):
+
+    def _test_long_repr(self, type2test):
+        val = type2test(42)
+        self.assertEqual(str(val), '42')
+        self.assertEqual(repr(val), '42L')
+
+    def test_long_repr(self):
+        self._test_long_repr(long)
+
+    def test_long_subclass_repr(self):
+        self._test_long_repr(MyLong)
+
+    def test_subclass_bool(self):
+        # http://bugs.jython.org/issue1828
+        self.assertTrue(bool(MyLong(42)))
+
+
+def test_main():
+    test_support.run_unittest(LongTestCase)
+
+if __name__ == '__main__':
+    test_main()
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@
     - [ 1819 ] Incorrect handling of Java object toString methods returning null
     - [ 1824 ] os.link() can silently fail
     - [ 1825 ] EnvironmentError.filename is `str` even if original name is `unicode`
+    - [ 1828 ] Problems inheriting from long
 
 Jython 2.5.2
   same as 2.5.2rc4
diff --git a/src/org/python/core/PyLong.java b/src/org/python/core/PyLong.java
--- a/src/org/python/core/PyLong.java
+++ b/src/org/python/core/PyLong.java
@@ -155,7 +155,7 @@
         return long_toString();
     }
 
-    @ExposedMethod(names = {"__str__", "__repr__"}, doc = BuiltinDocs.long___str___doc)
+    @ExposedMethod(names = "__repr__", doc = BuiltinDocs.long___repr___doc)
     final String long_toString() {
         return getValue().toString() + "L";
     }
@@ -172,12 +172,12 @@
 
     @Override
     public boolean __nonzero__() {
-        return !getValue().equals(BigInteger.ZERO);
+        return long___nonzero__();
     }
 
     @ExposedMethod(doc = BuiltinDocs.long___nonzero___doc)
     public boolean long___nonzero__() {
-        return __nonzero__();
+        return !getValue().equals(BigInteger.ZERO);
     }
 
     public double doubleValue() {
@@ -951,9 +951,14 @@
         }
     }
 
+    @ExposedMethod(doc = BuiltinDocs.long___str___doc)
+    public PyString long___str__() {
+        return Py.newString(getValue().toString());
+    }
+
     @Override
     public PyString __str__() {
-        return Py.newString(getValue().toString());
+        return long___str__();
     }
 
     @Override

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list