[Jython-checkins] jython: Additional testing of what methods are called when subclassed
jim.baker
jython-checkins at python.org
Fri Apr 17 06:56:33 CEST 2015
https://hg.python.org/jython/rev/1c420dee2a19
changeset: 7673:1c420dee2a19
user: Jim Baker <jim.baker at rackspace.com>
date: Thu Apr 16 22:56:28 2015 -0600
summary:
Additional testing of what methods are called when subclassed
Some simple test combinations of constructors along with static vs non
static factories for verifying the right method in a class is
called. Although written to understand issues around
http://bugs.jython.org/issue2104, these tests do not result any
failures.
files:
Lib/test/test_java_subclasses.py | 101 ++++++++++++-
tests/java/javatests/Inheritance.java | 17 ++
tests/java/javatests/InheritanceA.java | 26 +++
tests/java/javatests/InheritanceB.java | 33 ++++
tests/java/javatests/InheritanceC.java | 33 ++++
5 files changed, 208 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_java_subclasses.py b/Lib/test/test_java_subclasses.py
--- a/Lib/test/test_java_subclasses.py
+++ b/Lib/test/test_java_subclasses.py
@@ -6,7 +6,7 @@
from test import test_support
from java.lang import (Boolean, Class, ClassLoader, Comparable,Integer, Object, Runnable, String,
- Thread, ThreadGroup)
+ Thread, ThreadGroup, UnsupportedOperationException)
from java.util import AbstractList, ArrayList, Date, Hashtable, HashSet, Vector
from java.util.concurrent import Callable, Executors
@@ -15,6 +15,8 @@
from javax.swing.table import AbstractTableModel
from org.python.tests import BeanInterface, Callbacker, Coercions, OwnMethodCaller
+from javatests import InheritanceA, InheritanceB, InheritanceC, InheritanceD
+
class InterfaceTest(unittest.TestCase):
def test_java_calling_python_interface_implementation(self):
@@ -459,6 +461,100 @@
self.assertEqual(my_list.size(), 6)
+class HierarchyTest(unittest.TestCase):
+
+ # Attempt to expand upon the inheritance hierarchy described as
+ # being a bug in http://bugs.jython.org/issue2104, but this test
+ # currently only confirms existing behavior.
+
+ def assertB(self, b2, level, cls):
+ self.assertIsInstance(b2, cls)
+ self.assertEqual(b2.whoAmI(), level)
+ self.assertEqual(b2.staticWhoAmI(), level)
+ self.assertEqual(b2.root(), "A")
+ self.assertEqual(b2.staticRoot(), "A")
+ self.assertEqual(b2.everyOther(), "A")
+ self.assertEqual(b2.notInAbstract(), "B")
+
+ def test_b(self):
+ b = InheritanceB()
+ self.assertB(b.replicateMe(), "B", InheritanceB)
+ self.assertB(b.build(), "B", InheritanceB)
+ with self.assertRaises(UnsupportedOperationException):
+ b.replicateParent()
+ with self.assertRaises(UnsupportedOperationException):
+ b.buildParent()
+
+ def assertC(self, c2, level, cls):
+ self.assertIsInstance(c2, cls)
+ self.assertEqual(c2.whoAmI(), level)
+ self.assertEqual(c2.staticWhoAmI(), level)
+ self.assertEqual(c2.root(), "A")
+ self.assertEqual(c2.staticRoot(), "A")
+ self.assertEqual(c2.everyOther(),
+ "C" if isinstance(c2, InheritanceC) else "A")
+ self.assertEqual(c2.notInAbstract(), "B")
+
+ def test_c(self):
+ c = InheritanceC()
+ self.assertC(c.replicateMe(), "C", InheritanceC)
+ self.assertC(c.replicateParent(), "B", InheritanceB)
+ self.assertC(c.build(), "C", InheritanceC)
+ self.assertC(c.buildParent(), "B", InheritanceB)
+
+ def assertD(self, d2, level, cls):
+ self.assertIsInstance(d2, cls)
+ self.assertEqual(d2.whoAmI(), level)
+ self.assertEqual(d2.staticWhoAmI(), level)
+ self.assertEqual(d2.root(), "A")
+ self.assertEqual(d2.staticRoot(), "A")
+ self.assertEqual(d2.everyOther(), "C")
+ self.assertEqual(d2.notInAbstract(), "B")
+
+ def test_d(self):
+ d = InheritanceD()
+ self.assertD(d.replicateMe(), "D", InheritanceD)
+ self.assertD(d.replicateParent(), "C", InheritanceC)
+ self.assertD(d.build(), "D", InheritanceD)
+ self.assertD(d.buildParent(), "C", InheritanceC)
+
+ def assertE(self, e2, level, cls, tested):
+ self.assertIsInstance(e2, cls)
+ self.assertEqual(e2.whoAmI(), level)
+ self.assertEqual(e2.staticWhoAmI(), level)
+ self.assertEqual(e2.root(), "A")
+ self.assertEqual(e2.staticRoot(), "A")
+ self.assertEqual(e2.everyOther(),
+ "E" if isinstance(e2, tested) else "C")
+ self.assertEqual(e2.notInAbstract(), "B")
+
+ def test_e(self):
+ class E(InheritanceD):
+ def replicateMe(self):
+ return E()
+ def replicateParent(self):
+ return InheritanceD()
+ @staticmethod
+ def build():
+ return E()
+ @staticmethod
+ def buildParent():
+ return InheritanceD()
+ def whoAmI(self):
+ return "E"
+ @staticmethod
+ def staticWhoAmI():
+ return "E"
+ def everyOther(self):
+ return "E"
+
+ e = E()
+ self.assertE(e.replicateMe(), "E", E, E)
+ self.assertE(e.replicateParent(), "D", InheritanceD, E)
+ self.assertE(e.build(), "E", E, E)
+ self.assertE(e.buildParent(), "D", InheritanceD, E)
+
+
def test_main():
test_support.run_unittest(
InterfaceTest,
@@ -469,7 +565,8 @@
ContextClassloaderTest,
MetaClassTest,
AbstractMethodTest,
- SuperIsSuperTest)
+ SuperIsSuperTest,
+ HierarchyTest)
if __name__ == '__main__':
diff --git a/tests/java/javatests/Inheritance.java b/tests/java/javatests/Inheritance.java
new file mode 100644
--- /dev/null
+++ b/tests/java/javatests/Inheritance.java
@@ -0,0 +1,17 @@
+// Inheritance*.java are used to test for http://bugs.jython.org/issue2104
+//
+// However this inheritance hierarchy as constructed is still not
+// sufficient to reproduce the issue raised by Jorgo Bakker and Jaime
+// Saiz, so need to figure out a patch that does reproduce the problem
+// before we can commit even what appears to be a trivial bug fix.
+
+package javatests;
+
+public interface Inheritance {
+ Inheritance replicateMe();
+ Inheritance replicateParent();
+ String whoAmI();
+ String root();
+ String notInAbstract();
+ String everyOther();
+}
diff --git a/tests/java/javatests/InheritanceA.java b/tests/java/javatests/InheritanceA.java
new file mode 100644
--- /dev/null
+++ b/tests/java/javatests/InheritanceA.java
@@ -0,0 +1,26 @@
+package javatests;
+
+public abstract class InheritanceA implements Inheritance {
+
+ public String whoAmI() {
+ return "A";
+ }
+
+ public String root() {
+ return "A";
+ }
+
+ public String everyOther() {
+ return "A";
+ }
+
+ public static String staticWhoAmI() {
+ return "A";
+ }
+
+ public static String staticRoot() {
+ return "A";
+ }
+
+}
+
diff --git a/tests/java/javatests/InheritanceB.java b/tests/java/javatests/InheritanceB.java
new file mode 100644
--- /dev/null
+++ b/tests/java/javatests/InheritanceB.java
@@ -0,0 +1,33 @@
+package javatests;
+
+public class InheritanceB extends InheritanceA {
+
+ public Inheritance replicateMe() {
+ return new InheritanceB();
+ }
+
+ public Inheritance replicateParent() {
+ throw new UnsupportedOperationException("parent is abstract");
+ }
+
+ public static Inheritance build() {
+ return new InheritanceB();
+ }
+
+ public static Inheritance buildParent() {
+ throw new UnsupportedOperationException("parent is abstract");
+ }
+
+ public String whoAmI() {
+ return "B";
+ }
+
+ public String notInAbstract() {
+ return "B";
+ }
+
+ public static String staticWhoAmI() {
+ return "B";
+ }
+
+}
diff --git a/tests/java/javatests/InheritanceC.java b/tests/java/javatests/InheritanceC.java
new file mode 100644
--- /dev/null
+++ b/tests/java/javatests/InheritanceC.java
@@ -0,0 +1,33 @@
+package javatests;
+
+public class InheritanceC extends InheritanceB {
+
+ public Inheritance replicateMe() {
+ return new InheritanceC();
+ }
+
+ public Inheritance replicateParent() {
+ return new InheritanceB();
+ }
+
+ public static Inheritance build() {
+ return new InheritanceC();
+ }
+
+ public static Inheritance buildParent() {
+ return new InheritanceB();
+ }
+
+ public String whoAmI() {
+ return "C";
+ }
+
+ public String everyOther() {
+ return "C";
+ }
+
+ public static String staticWhoAmI() {
+ return "C";
+ }
+
+}
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list